diffu/modules/nixos/prometheus.nix

96 lines
2.4 KiB
Nix
Raw Normal View History

2023-12-18 02:46:01 +00:00
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.custom.prometheus;
in
{
options = {
custom.prometheus = {
enable = mkEnableOption "Prometheus instance";
exporters = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable Prometheus exporter on every supported services";
};
};
2023-12-20 03:13:20 +00:00
grafana = {
enable = mkEnableOption "Grafana Cloud";
password_file = mkOption {
type = types.path;
};
};
2023-12-18 02:46:01 +00:00
};
};
2024-07-30 03:31:27 +00:00
config = mkIf cfg.enable (mkMerge [{
2023-12-20 03:13:20 +00:00
services.caddy.globalConfig = ''
servers {
metrics
}
'';
services.restic.server.prometheus = cfg.enable;
services.gotosocial.settings = {
metrics-enable = true;
};
2023-12-18 02:46:01 +00:00
services.prometheus = mkIf cfg.enable {
enable = true;
port = 9091;
2023-12-20 03:13:20 +00:00
globalConfig.external_labels = { hostname = config.networking.hostName; };
remoteWrite = mkIf cfg.grafana.enable [
{ name = "grafana";
url = "https://prometheus-prod-24-prod-eu-west-2.grafana.net/api/prom/push";
basic_auth = {
username = "1340065";
password_file = cfg.grafana.password_file;
};
}
];
2023-12-18 02:46:01 +00:00
exporters = {
node = {
enable = true;
enabledCollectors = [ "systemd" ];
port = 9100;
};
};
scrapeConfigs = [
{ job_name = "prometheus";
static_configs = [
{ targets = [ "localhost:${toString config.services.prometheus.port}" ]; }
];
}
{ job_name = "node";
static_configs = [
{ targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ]; }
];
}
];
};
2023-12-20 03:13:20 +00:00
}
{
services.prometheus.scrapeConfigs = [
( mkIf config.services.caddy.enable {
job_name = "caddy";
static_configs = [
{ targets = [ "localhost:2019" ]; }
];
})
( mkIf config.services.restic.server.enable {
job_name = "restic";
static_configs = [
{ targets = [ config.services.restic.server.listenAddress ]; }
];
})
( mkIf config.services.gotosocial.enable {
job_name = "gotosocial";
static_configs = [
{ targets = [ "localhost:${toString config.services.gotosocial.settings.port}" ]; }
];
})
];
}
2024-07-30 03:31:27 +00:00
]);
2023-12-20 03:13:20 +00:00
}