feat: add grafana + prometheus

This commit is contained in:
nydragon 2025-03-01 13:17:14 +01:00
parent 2739488139
commit ae437ea4df
Signed by: nydragon
SSH key fingerprint: SHA256:WcjW5NJPQ8Dx4uQDmoIlVPLWE27Od3fxoe0IUvuoPHE
4 changed files with 84 additions and 0 deletions

View file

@ -65,6 +65,21 @@
};
};
services.prometheus.exporters.node = {
enable = true;
port = 9000;
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/exporters.nix
enabledCollectors = [ "systemd" ];
# /nix/store/zgsw0yx18v10xa58psanfabmg95nl2bb-node_exporter-1.8.1/bin/node_exporter --help
extraFlags = [
"--collector.ethtool"
"--collector.softirqs"
"--collector.tcpstat"
"--collector.wifi"
];
};
networking.firewall.allowedTCPPorts = [ 9000 ];
boot.initrd.systemd.tpm2.enable = false;
system.stateVersion = "24.11";

View file

@ -39,6 +39,13 @@ in
[ "tag:backup:${toString options.modules.server.rsync-daemon.port.default}" ]
)
(mkAcl
[
"${shanMeta.tailscale.ip}"
]
[ "tag:server:9000" ]
)
(mkAcl
[
"tag:guest"

View file

@ -10,6 +10,7 @@
./disk-config.nix
./adguard.nix
./calibre-web.nix
./prometheus.nix
];
swapDevices = [
@ -192,6 +193,8 @@
"fritz.ccnlc.eu" = mkVH "http://192.168.178.1" 80;
"truenas.ccnlc.eu" = mkVH "https://192.168.178.21" 443;
"calibre.ccnlc.eu" = mkVHLocal config.services.calibre-web.listen.port;
"prometheus.ccnlc.eu" = mkVHLocal config.services.prometheus.port;
"grafana.ccnlc.eu" = mkVHLocal config.services.grafana.settings.server.http_port;
${config.services.freshrss.virtualHost} = {
forceSSL = true;
useACMEHost = "ccnlc.eu";

59
hosts/shan/prometheus.nix Normal file
View file

@ -0,0 +1,59 @@
{ config, ... }:
{
services.prometheus = {
enable = true;
webExternalUrl = "https://prometheus.ccnlc.eu";
scrapeConfigs = [
{
job_name = "node";
static_configs = [
{
targets = [
"nihilus:9000"
"shan:9000"
];
}
];
}
];
};
services.prometheus.exporters.node = {
enable = true;
port = 9000;
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/exporters.nix
enabledCollectors = [ "systemd" ];
# /nix/store/zgsw0yx18v10xa58psanfabmg95nl2bb-node_exporter-1.8.1/bin/node_exporter --help
extraFlags = [
"--collector.ethtool"
"--collector.softirqs"
"--collector.tcpstat"
"--collector.wifi"
];
};
services.grafana = {
enable = true;
provision = {
enable = true;
datasources.settings.datasources = [
{
name = "Prometheus";
type = "prometheus";
url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}";
}
];
};
settings = {
users = {
allow_sign_up = true;
};
server = {
protocol = "http";
http_addr = "127.0.0.1";
domain = "grafana.ccnlc.eu";
http_port = 9032;
};
};
};
}