infrastructure/modules/nixos/dgn-node-monitoring.nix

69 lines
1.4 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2024 Maurice Debray <maurice.debray@dgnum.eu>
# SPDX-FileCopyrightText: 2024 Ryan Lahfa <ryan.lahfa@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{
pkgs,
sources,
config,
lib,
...
}:
let
inherit (lib)
mkEnableOption
mkIf
mkOption
types
;
cfg = config.dgn-node-monitoring;
in
{
options.dgn-node-monitoring = {
enable = mkEnableOption "DGNum nodes monitoring (needs a valid netbird tunnel)" // {
default = true;
};
ports = mkOption {
type = types.attrsOf types.port;
default = {
node = 9002;
cgroup = 9003;
};
description = lib.mdDoc ''
Ports to listen on for each exporter.
'';
};
};
imports = [
"${sources.cgroup-exporter}/nix/module.nix"
];
config = mkIf cfg.enable {
services.prometheus = {
exporters = {
node = {
enable = true;
enabledCollectors = [
"processes"
"systemd"
];
port = cfg.ports.node;
listenAddress = "0.0.0.0";
};
cgroup = {
enable = true;
package = pkgs.callPackage "${sources.cgroup-exporter}/nix/package.nix" { };
listenAddress = "0.0.0.0";
port = cfg.ports.cgroup;
};
};
};
networking.firewall.interfaces.wt0.allowedTCPPorts = builtins.attrValues cfg.ports;
};
}