2024-05-21 05:16:35 +00:00
|
|
|
{
|
2024-05-22 00:51:21 +00:00
|
|
|
nodes,
|
2024-05-21 05:16:35 +00:00
|
|
|
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;
|
|
|
|
};
|
2024-05-22 00:51:21 +00:00
|
|
|
|
|
|
|
other_nodes = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
To add other nodes outside of nix, specify ip and port that server should listen to here
|
|
|
|
'';
|
|
|
|
};
|
2024-05-21 05:16:35 +00:00
|
|
|
};
|
|
|
|
|
2024-05-23 00:27:02 +00:00
|
|
|
port_collecter = mkOption {
|
2024-05-21 05:16:35 +00:00
|
|
|
type = types.port;
|
|
|
|
default = 9002;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
{
|
|
|
|
services.prometheus.exporters.node = {
|
|
|
|
enable = true;
|
|
|
|
# most collectors are on by default see docs for more options
|
|
|
|
enabledCollectors = ["systemd"];
|
2024-05-23 00:27:02 +00:00
|
|
|
port = cfg.port_collecter;
|
2024-05-21 05:16:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
// mkIf cfg.server.enable {
|
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
|
|
|
port = cfg.server.port;
|
|
|
|
scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "node_exporter";
|
|
|
|
static_configs = [
|
|
|
|
{
|
2024-05-23 00:27:02 +00:00
|
|
|
targets = (map (hostname: "${hostname}:${cfg.port_collecter}") (lib.attrsets.mapAttrsToList (server: server.deployment.hostname)) nodes) ++ cfg.other_nodes;
|
2024-05-21 05:16:35 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|