dotfiles/modules/nixos/services/prometheus/default.nix

59 lines
1.4 KiB
Nix
Raw Normal View History

2023-09-08 03:21:46 +00:00
{
config,
lib,
...
}: let
inherit (lib) mkIf;
2023-09-08 03:21:46 +00:00
cfg = config.aa.services.prometheus;
exporters = config.services.prometheus.exporters;
2023-09-08 03:21:46 +00:00
in {
options.aa.services.prometheus = with lib; {
2023-09-08 03:21:46 +00:00
enable = mkEnableOption "prometheus";
2023-09-10 16:20:11 +00:00
enableServer = mkOption {
type = types.bool;
2023-09-10 16:20:11 +00:00
default = false;
description = "Whether or not to enable the prometheus server";
};
enableNodeExporter = mkOption {
type = types.bool;
2023-09-10 16:20:11 +00:00
default = true;
description = "Whether or not to enable the node exporter";
2023-09-08 03:21:46 +00:00
};
};
config = mkIf cfg.enable {
services.prometheus = {
2023-09-10 16:20:11 +00:00
enable = cfg.enableServer;
exporters = {
node = {
2023-09-10 16:20:11 +00:00
enable = cfg.enableNodeExporter;
enabledCollectors = ["systemd"];
port = 9002;
2023-09-10 16:20:11 +00:00
openFirewall = true;
};
};
2023-09-10 16:20:11 +00:00
scrapeConfigs = mkIf cfg.enableServer [
{
2023-09-10 16:20:11 +00:00
job_name = "node";
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 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
};
};
}