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}";
|
2024-06-05 13:31:50 +00:00
|
|
|
|
|
|
|
# dont have to worry about any external addresses for this
|
|
|
|
# create a list of either "ip@port" or ""
|
|
|
|
# the ""s then get filtered out by filter_empty
|
|
|
|
exporters = {
|
|
|
|
dns = (
|
|
|
|
lib.attrsets.mapAttrsToList (
|
|
|
|
key: value:
|
|
|
|
if value.config.services.skynet.dns.server.enable
|
|
|
|
then "${value.config.deployment.targetHost}:${toString value.config.services.prometheus.exporters.bind.port}"
|
|
|
|
else ""
|
|
|
|
)
|
|
|
|
nodes
|
|
|
|
);
|
|
|
|
node = lib.attrsets.mapAttrsToList (key: value: "${value.config.deployment.targetHost}:${toString config.services.prometheus.exporters.node.port}") nodes;
|
|
|
|
};
|
|
|
|
|
|
|
|
# clears any invalid entries
|
|
|
|
filter_empty = inputs: (builtins.filter (value: value != "") inputs);
|
2024-05-21 05:16:35 +00:00
|
|
|
in {
|
|
|
|
imports = [];
|
|
|
|
|
|
|
|
options.services.skynet."${name}" = {
|
|
|
|
server = {
|
|
|
|
enable = mkEnableOption "Prometheus Server";
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 9001;
|
|
|
|
};
|
2024-05-22 00:51:21 +00:00
|
|
|
|
2024-06-05 13:31:50 +00:00
|
|
|
external.node = mkOption {
|
2024-05-22 00:51:21 +00:00
|
|
|
type = types.listOf types.str;
|
2024-05-23 03:08:50 +00:00
|
|
|
default = [];
|
2024-05-22 00:51:21 +00:00
|
|
|
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 20:48:23 +00:00
|
|
|
config = mkMerge [
|
2024-05-21 05:16:35 +00:00
|
|
|
{
|
|
|
|
services.prometheus.exporters.node = {
|
|
|
|
enable = true;
|
2024-06-05 13:31:50 +00:00
|
|
|
openFirewall = true;
|
2024-05-23 21:34:02 +00:00
|
|
|
# most collectors are on by default see https://github.com/prometheus/node_exporter for more options
|
2024-05-21 05:16:35 +00:00
|
|
|
enabledCollectors = ["systemd"];
|
|
|
|
};
|
|
|
|
}
|
2024-05-23 20:48:23 +00:00
|
|
|
(mkIf cfg.server.enable {
|
2024-05-21 05:16:35 +00:00
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
|
|
|
port = cfg.server.port;
|
|
|
|
scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "node_exporter";
|
|
|
|
static_configs = [
|
|
|
|
{
|
2024-06-05 13:31:50 +00:00
|
|
|
targets = filter_empty (exporters.node ++ cfg.server.external.node);
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "bind";
|
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = filter_empty exporters.dns;
|
2024-05-21 05:16:35 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-05-23 20:48:23 +00:00
|
|
|
})
|
|
|
|
];
|
2024-05-21 05:16:35 +00:00
|
|
|
}
|