nixos/applications/prometheus.nix

73 lines
1.5 KiB
Nix
Raw Normal View History

{
nodes,
lib,
config,
...
}:
with lib; let
name = "prometheus";
cfg = config.services.skynet."${name}";
in {
imports = [];
options.services.skynet."${name}" = {
server = {
enable = mkEnableOption "Prometheus Server";
host = {
ip = mkOption {
type = types.str;
};
name = mkOption {
type = types.str;
};
};
port = mkOption {
type = types.port;
default = 9001;
};
other_nodes = mkOption {
type = types.listOf types.str;
2024-05-23 03:08:50 +00:00
default = [];
description = ''
To add other nodes outside of nix, specify ip and port that server should listen to here
'';
};
};
port_collecter = mkOption {
type = types.port;
default = 9002;
};
};
config = mkMerge [
{
services.prometheus.exporters.node = {
enable = true;
# most collectors are on by default see docs for more options
enabledCollectors = ["systemd"];
port = cfg.port_collecter;
};
}
(mkIf cfg.server.enable {
services.prometheus = {
enable = true;
port = cfg.server.port;
scrapeConfigs = [
{
job_name = "node_exporter";
static_configs = [
{
targets = (lib.attrsets.mapAttrsToList (key: value: "${value.config.deployment.targetHost}:${toString cfg.port_collecter}") nodes) ++ cfg.server.other_nodes;
}
];
}
];
};
})
];
}