refactor monitoring module to allow kicking out inactive systems

This commit is contained in:
oxapentane - 2023-05-05 20:34:57 +02:00
parent 84582cdb63
commit f29b63f709
Signed by: oxapentane
GPG Key ID: 91FA5E5BF9AA901C
3 changed files with 46 additions and 15 deletions

View File

@ -7,6 +7,6 @@
./json.nix
./net.nix
./wg.nix
./node-exporter.nix
./monitoring.nix
];
}

View File

@ -0,0 +1,45 @@
{ lib, config, ... }:
let
cfg = config.deployment-TLMS.monitoring;
in
{
options.deployment-TLMS.monitoring = with lib; {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable TLMS default prometheus exporter and log collection
'';
};
monitoring.node-exporter = with lib; {
port = mkOption {
type = types.port;
default = 8119;
description = ''
Default port for prometheus node exporter to listen to
'';
};
};
};
config =
let
wg-addr-pred = !isNull config.deployment-TLMS.net.wg.addr4;
check-wg = enabled:
lib.assertMsg (enabled && wg-addr-pred)
''For monitoring to be working the system must be in wireguard. See config.deplayment-TLMS.net.wg'';
in
lib.mkIf (check-wg cfg.enable) {
# prometheus node exporter
services.prometheus.exporters = {
node = {
enable = true;
port = 8119;
listenAddress = config.deployment-TLMS.net.wg.addr4;
enabledCollectors = [
"systemd"
];
};
};
};
}

View File

@ -1,14 +0,0 @@
{ config, ... }:
{
# metrics exporter
services.prometheus.exporters = {
node = {
enable = true;
port = 8119;
listenAddress = config.deployment-TLMS.net.wg.addr4;
enabledCollectors = [
"systemd"
];
};
};
}