dotfiles/platforms/nixos/modules/nmasur/presets/services/prometheus-remote-write.nix

53 lines
1.4 KiB
Nix
Raw Normal View History

2025-01-20 22:35:40 -05:00
# Prometheus is a timeseries database that exposes system and service metrics
# for use in visualizing, monitoring, and alerting (with Grafana).
# Instead of running traditional Prometheus, I generally run VictoriaMetrics as
# a more efficient drop-in replacement.
{
config,
lib,
...
}:
let
2025-02-08 13:01:16 -05:00
inherit (config.nmasur.settings) hostnames;
cfg = config.nmasur.presets.services.prometheus-remote-write;
2025-01-20 22:35:40 -05:00
in
{
options.nmasur.presets.services.prometheus-remote-write = {
enable = lib.mkEnableOption "Prometheus remote write for agent machines";
};
config = lib.mkIf cfg.enable {
services.prometheus = {
remoteWrite = [
{
name = config.networking.hostName;
2025-02-08 12:58:06 -05:00
url = "https://${hostnames.prometheus}/api/v1/write";
2025-01-20 22:35:40 -05:00
basic_auth = {
# Uses password hashed with bcrypt above
username = "prometheus";
password_file = config.secrets.prometheus.dest;
};
}
];
};
# Create credentials file for remote Prometheus push
secrets.prometheus = {
source = ../../../private/prometheus.age;
dest = "${config.secretsDirectory}/prometheus";
owner = "prometheus";
group = "prometheus";
permissions = "0440";
};
systemd.services.prometheus-secret = {
requiredBy = [ "prometheus.service" ];
before = [ "prometheus.service" ];
};
};
}