2024-01-09 23:11:11 -05:00
|
|
|
# VictoriaMetrics is a more efficient drop-in replacement for Prometheus and
|
|
|
|
# InfluxDB (timeseries databases built for monitoring system metrics).
|
|
|
|
|
2024-04-20 09:42:06 -04:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2023-07-16 13:50:58 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2025-01-20 22:35:40 -05:00
|
|
|
cfg = config.nmasur.presets.services.victoriametrics;
|
|
|
|
|
2023-07-16 13:50:58 +00:00
|
|
|
username = "prometheus";
|
|
|
|
|
2024-06-23 08:55:39 -04:00
|
|
|
prometheusConfig = {
|
2024-04-20 09:42:06 -04:00
|
|
|
scrape_configs = [
|
|
|
|
{
|
|
|
|
job_name = config.networking.hostName;
|
|
|
|
stream_parse = true;
|
|
|
|
static_configs = [ { targets = config.prometheus.scrapeTargets; } ];
|
|
|
|
}
|
|
|
|
];
|
2023-07-16 13:50:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
authConfig = (pkgs.formats.yaml { }).generate "auth.yml" {
|
2024-04-20 09:42:06 -04:00
|
|
|
users = [
|
|
|
|
{
|
|
|
|
username = username;
|
|
|
|
password = "%{PASSWORD}";
|
|
|
|
url_prefix = "http://localhost${config.services.victoriametrics.listenAddress}";
|
|
|
|
}
|
|
|
|
];
|
2023-07-16 13:50:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
authPort = "8427";
|
2024-04-20 09:42:06 -04:00
|
|
|
in
|
|
|
|
{
|
2023-07-16 13:50:58 +00:00
|
|
|
|
2025-01-20 22:35:40 -05:00
|
|
|
options.nmasur.presets.services.victoriametrics.enable =
|
|
|
|
lib.mkEnableOption "VictoriaMetrics timeseries database";
|
2023-07-16 13:50:58 +00:00
|
|
|
|
2025-01-20 22:35:40 -05:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
|
|
|
services.victoriametrics = {
|
|
|
|
enable = true;
|
|
|
|
extraOptions = [
|
|
|
|
"-promscrape.config=${(pkgs.formats.yaml { }).generate "scrape.yml" prometheusConfig}"
|
|
|
|
];
|
|
|
|
};
|
2024-06-29 01:22:59 +00:00
|
|
|
|
2023-07-16 13:50:58 +00:00
|
|
|
systemd.services.vmauth = lib.mkIf config.services.victoriametrics.enable {
|
|
|
|
description = "VictoriaMetrics basic auth proxy";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
startLimitBurst = 5;
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 1;
|
|
|
|
DynamicUser = true;
|
|
|
|
EnvironmentFile = config.secrets.vmauth.dest;
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.victoriametrics}/bin/vmauth \
|
|
|
|
-auth.config=${authConfig} \
|
|
|
|
-httpListenAddr=:${authPort}'';
|
|
|
|
};
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
secrets.vmauth = lib.mkIf config.services.victoriametrics.enable {
|
|
|
|
source = ../../../private/prometheus.age;
|
|
|
|
dest = "${config.secretsDirectory}/vmauth";
|
|
|
|
prefix = "PASSWORD=";
|
|
|
|
};
|
2024-04-20 09:42:06 -04:00
|
|
|
systemd.services.vmauth-secret = lib.mkIf config.services.victoriametrics.enable {
|
|
|
|
requiredBy = [ "vmauth.service" ];
|
|
|
|
before = [ "vmauth.service" ];
|
|
|
|
};
|
2023-07-16 13:50:58 +00:00
|
|
|
|
2025-01-20 22:35:40 -05:00
|
|
|
caddy.routes = [
|
2024-04-20 09:42:06 -04:00
|
|
|
{
|
|
|
|
match = [ { host = [ config.hostnames.prometheus ]; } ];
|
|
|
|
handle = [
|
|
|
|
{
|
|
|
|
handler = "reverse_proxy";
|
|
|
|
upstreams = [ { dial = "localhost:${authPort}"; } ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2023-07-16 13:50:58 +00:00
|
|
|
|
2024-03-30 14:48:56 -04:00
|
|
|
# Configure Cloudflare DNS to point to this machine
|
2025-01-20 22:35:40 -05:00
|
|
|
services.cloudflare-dyndns.domains = [ config.hostnames.prometheus ];
|
2023-07-16 13:50:58 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|