services/prometheus: init server

This commit is contained in:
Lu Wang 2024-12-21 20:41:30 +08:00
parent a06f67bf23
commit 68d8d0a13c
Signed by: rebmit
SSH key fingerprint: SHA256:3px8QV1zEerIrEWHaqtH5rR9kjetyRST5EipOPrd+bU
3 changed files with 45 additions and 0 deletions

View file

@ -11,6 +11,7 @@
services.caddy services.caddy
services.knot.secondary services.knot.secondary
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.server
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -0,0 +1,43 @@
{ config, lib, ... }:
let
common = import ../../../../zones/common.nix;
publicHosts = lib.filterAttrs (_name: value: value.endpoints != [ ]) common.hosts;
targets = lib.mapAttrsToList (name: _value: "${name}.rebmit.link") publicHosts;
in
{
sops.secrets."prometheus/password" = {
sopsFile = config.sops.secretFiles.host;
owner = config.systemd.services.prometheus.serviceConfig.User;
restartUnits = [ "prometheus.service" ];
};
services.prometheus = {
enable = true;
webExternalUrl = "https://prometheus.rebmit.moe";
listenAddress = "127.0.0.1";
port = config.networking.ports.prometheus;
retentionTime = "7d";
globalConfig = {
scrape_interval = "1m";
evaluation_interval = "1m";
};
scrapeConfigs = [
{
job_name = "metrics";
scheme = "https";
metrics_path = "/metrics";
basic_auth = {
username = "prometheus";
password_file = config.sops.secrets."prometheus/password".path;
};
static_configs = [ { inherit targets; } ];
}
];
};
services.caddy.virtualHosts."prometheus.rebmit.moe" = {
extraConfig = with config.services.prometheus; ''
reverse_proxy ${listenAddress}:${toString port}
'';
};
}

View file

@ -48,5 +48,6 @@ dns.lib.toString "rebmit.moe" {
matrix.CNAME = [ "suwako-vie0.rebmit.link." ]; matrix.CNAME = [ "suwako-vie0.rebmit.link." ];
miniflux.CNAME = [ "suwako-vie0.rebmit.link." ]; miniflux.CNAME = [ "suwako-vie0.rebmit.link." ];
ntfy.CNAME = [ "suwako-vie0.rebmit.link." ]; ntfy.CNAME = [ "suwako-vie0.rebmit.link." ];
prometheus.CNAME = [ "reisen-nrt0.rebmit.link." ];
}; };
} }