dotfiles/modules/services/prometheus/default.nix

65 lines
1.4 KiB
Nix
Raw Normal View History

2023-09-08 03:21:46 +00:00
{
options,
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.aa.services.prometheus;
exporters = config.services.prometheus.exporters;
2023-09-08 03:21:46 +00:00
in {
options.aa.services.prometheus = with types; {
enable = mkEnableOption "prometheus";
acmeCertName = mkOption {
type = str;
default = "";
description = ''
If set to a non-empty string, forces SSL with the supplied acme
certificate.
'';
};
};
config = mkIf cfg.enable {
services.prometheus = {
enable = true;
exporters = {
node = {
enable = true;
enabledCollectors = ["systemd"];
port = 9002;
};
};
scrapeConfigs = [
{
job_name = "foo";
static_configs = [
{
targets = ["127.0.0.1:${toString exporters.node.port}"];
}
];
}
];
};
2023-09-08 03:21:46 +00:00
services.nginx = {
enable = true;
virtualHosts."prometheus.${cfg.acmeCertName}" =
{
locations."/" = {
proxyPass = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}";
};
}
// lib.optionalAttrs (cfg.acmeCertName != "") {
forceSSL = true;
useACMEHost = cfg.acmeCertName;
};
};
networking.firewall = {
allowedTCPPorts = [80 443];
};
};
}