forked from DGNum/infrastructure
feat(monitoring): Enable node exporter on almost all nodes
This commit is contained in:
parent
8e79b19101
commit
c6fe6b5891
5 changed files with 69 additions and 1 deletions
|
@ -1,8 +1,26 @@
|
|||
{ config, ... }:
|
||||
{
|
||||
config,
|
||||
nodes,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
host = "prometheus.dgnum.eu";
|
||||
port = 9091;
|
||||
|
||||
nodeExporterConfigs = lib.flatten (
|
||||
lib.mapAttrsToList (
|
||||
node:
|
||||
{ config, ... }:
|
||||
lib.optional config.dgn-node-monitoring.enable {
|
||||
targets = [ "${node}.dgnum:${builtins.toString config.dgn-node-monitoring.port}" ];
|
||||
labels = {
|
||||
host = node;
|
||||
};
|
||||
}
|
||||
) nodes
|
||||
);
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -33,6 +51,10 @@ in
|
|||
job_name = "prometheus";
|
||||
static_configs = [ { targets = [ "localhost:9090" ]; } ];
|
||||
}
|
||||
{
|
||||
job_name = "node_exporter";
|
||||
static_configs = nodeExporterConfigs;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ lib.extra.mkConfig {
|
|||
|
||||
enabledServices = [
|
||||
# List of services to enable
|
||||
"monitoring"
|
||||
];
|
||||
|
||||
extraConfig = {
|
||||
|
|
1
machines/web02/monitoring.nix
Normal file
1
machines/web02/monitoring.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ dgn-node-monitoring.enable = false; }
|
|
@ -43,6 +43,7 @@
|
|||
"dgn-console"
|
||||
"dgn-fail2ban"
|
||||
"dgn-hardware"
|
||||
"dgn-node-monitoring"
|
||||
"dgn-notify"
|
||||
"dgn-netbox-agent"
|
||||
"dgn-network"
|
||||
|
|
43
modules/dgn-node-monitoring.nix
Normal file
43
modules/dgn-node-monitoring.nix
Normal file
|
@ -0,0 +1,43 @@
|
|||
{ 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;
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 9002;
|
||||
description = lib.mdDoc ''
|
||||
Port to listen on.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.prometheus = {
|
||||
exporters = {
|
||||
node = {
|
||||
enable = true;
|
||||
enabledCollectors = [
|
||||
"processes"
|
||||
"systemd"
|
||||
];
|
||||
inherit (cfg) port;
|
||||
listenAddress = "0.0.0.0";
|
||||
};
|
||||
};
|
||||
};
|
||||
networking.firewall.interfaces.wt0.allowedTCPPorts = [ cfg.port ];
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue