dotfiles/modules/services/prometheus/default.nix

60 lines
1.4 KiB
Nix

{
options,
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.aa.services.prometheus;
exporters = config.services.prometheus.exporters;
in {
options.aa.services.prometheus = with types; {
enable = mkEnableOption "prometheus";
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";
};
};
config = mkIf cfg.enable {
services.prometheus = {
enable = cfg.enableServer;
exporters = {
node = {
enable = cfg.enableNodeExporter;
enabledCollectors = ["systemd"];
port = 9002;
openFirewall = true;
};
};
scrapeConfigs = mkIf cfg.enableServer [
{
job_name = "node";
static_configs = [
{
# 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}"
];
}
];
}
];
};
networking.firewall = mkIf cfg.enableServer {
allowedTCPPorts = [config.services.prometheus.port];
};
};
}