2023-09-08 03:21:46 +00:00
|
|
|
{
|
|
|
|
options,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.aa.services.prometheus;
|
2023-09-08 05:51:38 +00:00
|
|
|
exporters = config.services.prometheus.exporters;
|
2023-09-08 03:21:46 +00:00
|
|
|
in {
|
|
|
|
options.aa.services.prometheus = with types; {
|
|
|
|
enable = mkEnableOption "prometheus";
|
2023-09-10 16:20:11 +00:00
|
|
|
enableServer = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether or not to enable the prometheus server";
|
|
|
|
};
|
|
|
|
enableNodeExporter = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether or not to enable the node exporter";
|
2023-09-08 03:21:46 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-09-08 05:51:38 +00:00
|
|
|
services.prometheus = {
|
2023-09-10 16:20:11 +00:00
|
|
|
enable = cfg.enableServer;
|
2023-09-08 05:51:38 +00:00
|
|
|
exporters = {
|
|
|
|
node = {
|
2023-09-10 16:20:11 +00:00
|
|
|
enable = cfg.enableNodeExporter;
|
2023-09-08 05:51:38 +00:00
|
|
|
enabledCollectors = ["systemd"];
|
|
|
|
port = 9002;
|
2023-09-10 16:20:11 +00:00
|
|
|
openFirewall = true;
|
2023-09-08 05:51:38 +00:00
|
|
|
};
|
|
|
|
};
|
2023-09-10 16:20:11 +00:00
|
|
|
scrapeConfigs = mkIf cfg.enableServer [
|
2023-09-08 05:51:38 +00:00
|
|
|
{
|
2023-09-10 16:20:11 +00:00
|
|
|
job_name = "node";
|
2023-09-08 05:51:38 +00:00
|
|
|
static_configs = [
|
|
|
|
{
|
2023-09-10 16:20:11 +00:00
|
|
|
# TODO: How to automatically generate this whenever an exporter
|
|
|
|
# is configured
|
|
|
|
targets = [
|
|
|
|
"node:${toString exporters.node.port}"
|
|
|
|
"gospel:${toString exporters.node.port}"
|
|
|
|
"pi4:${toString exporters.node.port}"
|
|
|
|
];
|
2023-09-08 05:51:38 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-09-08 03:21:46 +00:00
|
|
|
|
2023-09-10 16:20:11 +00:00
|
|
|
networking.firewall = mkIf cfg.enableServer {
|
|
|
|
allowedTCPPorts = [config.services.prometheus.port];
|
2023-09-08 03:21:46 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|