feat(modules/dgn-monitoring): Replace dgn-node-monitoring

This commit is contained in:
Tom Hubrecht 2025-02-09 00:28:00 +01:00
parent 95df4a5ed6
commit 3678c24ed4
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
6 changed files with 148 additions and 119 deletions

View file

@ -17,9 +17,9 @@ let
lib.mapAttrsToList (
node:
{ config, ... }:
lib.optional config.dgn-node-monitoring.enable {
lib.optional config.dgn-monitoring.exporters.enable {
targets = map (p: "${node}.dgnum:${builtins.toString p}") (
builtins.attrValues config.dgn-node-monitoring.ports
builtins.attrValues config.dgn-monitoring.exporters.ports
);
labels = {
host = node;

View file

@ -21,7 +21,7 @@ lib.extra.mkConfig {
dgn-access-control.users.root = [ "thubrecht" ];
# Disable monitoring
dgn-node-monitoring.enable = false;
dgn-monitoring.enable = false;
# Enable Postgres databases
services.postgresql = {

View file

@ -26,7 +26,6 @@
"dgn-monitoring"
"dgn-netbox-agent"
"dgn-network"
"dgn-node-monitoring"
"dgn-notify"
"dgn-records"
"dgn-redirections"

View file

@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{
config,
lib,
@ -8,60 +12,70 @@
}:
let
inherit (lib) filterAttrs mapAttrsToList optional;
inherit (lib)
filterAttrs
mapAttrsToList
mkEnableOption
mkIf
;
cfg = config.dgn-monitoring;
in
{
services.vmagent = {
enable = true;
imports = [ ./exporters.nix ];
flags = {
"remoteWrite.url" = "http://${meta.network.storage01.netbirdIp}:8428/api/v1/write";
"remoteWrite.label" = "node=${name}";
options.dgn-monitoring = {
enable = mkEnableOption "the DGNum monitoring system" // {
default = true;
};
};
config = mkIf cfg.enable {
services.vmagent = {
enable = true;
flags = {
"remoteWrite.url" = "http://${meta.network.storage01.netbirdIp}:8428/api/v1/write";
"remoteWrite.label" = "node=${name}";
};
prometheusConfig = {
scrape_configs =
mapAttrsToList
(job_name: cfg: {
inherit job_name;
static_configs = [ { targets = [ "127.0.0.1:${builtins.toString cfg.port}" ]; } ];
})
(
filterAttrs (
name: cfg:
!(builtins.elem name [
"assertions"
"warnings"
"blackbox"
"unifi-poller"
"domain"
"minio"
"idrac"
"pve"
"tor"
])
&& cfg.enable
) config.services.prometheus.exporters
);
global = {
scrape_interval = "15s";
external_labels.hostname = "${name}.${nodeMeta.site}.infra.dgnum.eu";
};
};
};
prometheusConfig = {
scrape_configs =
mapAttrsToList
(job_name: cfg: {
inherit job_name;
static_configs = [ { targets = [ "127.0.0.1:${builtins.toString cfg.port}" ]; } ];
})
(
filterAttrs (
name: cfg:
!(builtins.elem name [
"assertions"
"warnings"
"blackbox"
"unifi-poller"
"domain"
"minio"
"idrac"
"pve"
"tor"
])
&& cfg.enable
) config.services.prometheus.exporters
);
global = {
scrape_interval = "15s";
external_labels.hostname = "${name}.${nodeMeta.site}.infra.dgnum.eu";
services.journald.upload = {
enable = true;
settings = {
Upload.URL = "http://${meta.network.storage01.netbirdIp}:9428/insert/journald";
};
};
};
# services.prometheus.exporters = {
# node = {
# enable = true;
# enabledCollectors = [ "systemd" ] ++ (optional config.boot.zfs.enabled "zfs");
# };
# };
services.journald.upload = {
enable = true;
settings = {
Upload.URL = "http://${meta.network.storage01.netbirdIp}:9428/insert/journald";
};
};
}

View file

@ -0,0 +1,84 @@
# 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)
optional
mapAttrs
mapAttrs'
mkDefault
mkIf
mkOption
nameValuePair
recursiveUpdate
;
inherit (lib.types) attrsOf bool port;
cfg = config.dgn-monitoring.exporters;
in
{
options.dgn-monitoring.exporters = {
enable = mkOption {
type = bool;
default = config.dgn-monitoring.enable;
description = ''
Whether to enable standard exporters for the dgnum monitoring system.
'';
};
ports = mkOption {
type = attrsOf port;
description = ''
Ports to listen on for each exporter.
'';
};
};
imports = [ "${sources.cgroup-exporter}/nix/module.nix" ];
config = mkIf cfg.enable {
dgn-monitoring.exporters.ports = mapAttrs (_: mkDefault) {
node = 9002;
cgroup = 9003;
};
services.prometheus = {
exporters =
recursiveUpdate
{
node = {
enable = true;
enabledCollectors = [
"processes"
"systemd"
] ++ (optional config.boot.zfs.enabled "zfs");
};
cgroup = {
enable = true;
package = pkgs.callPackage "${sources.cgroup-exporter}/nix/package.nix" { };
};
}
(
mapAttrs (_: port: {
inherit port;
# NOTE: We always listen on localhost, as the agent runs on the same machine
listenAddress = "127.0.0.1";
}) cfg.ports
);
};
dgn-web.internalPorts = mapAttrs' (name: nameValuePair "${name}-exporter") cfg.ports;
};
}

View file

@ -1,68 +0,0 @@
# 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 = ''
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;
};
}