{ pkgs, lib, config, hostName, ... }: let inherit (config.services) prometheus; listenAddress = "127.0.0.1"; in { services.prometheus = { enable = true; inherit listenAddress; port = 9090; extraFlags = [ "--storage.tsdb.retention.time 30d" ]; exporters = { apcupsd = { enable = true; inherit listenAddress; }; node = { enable = true; inherit listenAddress; #enabledCollectors = [ "wifi" ]; }; smokeping = { #enable = true; inherit listenAddress; buckets = "0.0001,0.001,0.005,0.01,0.02,0.04,0.06,0.08,0.16,0.24,0.32,0.4,0.48,0.8,1.6,3.2,6.4"; hosts = [ "www.fdn.fr" "8.8.8.8" ]; pingInterval = "3s"; }; systemd = { enable = true; inherit listenAddress; }; wireguard = { #enable = true; inherit listenAddress; withRemoteIp = true; }; }; scrapeConfigs = [ { job_name = hostName; static_configs = [ { targets = [ "${listenAddress}:${toString prometheus.exporters.apcupsd.port}" "${listenAddress}:${toString prometheus.exporters.node.port}" #"[${listenAddress}:${toString prometheus.exporters.smokeping.port}" "${listenAddress}:${toString prometheus.exporters.systemd.port}" #"${listenAddress}:${toString prometheus.exporters.wireguard.port}" ]; } ]; } ]; /* alertmanagers = [ { static_configs = [ { targets = [ "${listenAddress}:9093" ]; } ]; } ]; alertmanager = { enable = true; inherit listenAddress; configuration = { global = { "smtp_smarthost" = "localhost:25"; "smtp_require_tls" = false; "smtp_from" = "alertmanager@${domain}"; }; route = { "group_by" = [ "alertname" "alias" ]; "group_wait" = "30s"; "group_interval" = "2m"; "repeat_interval" = "12h"; "receiver" = "root"; }; receivers = [ { "name" = "root"; "email_configs" = [ { "to" = "root+alertmanager@${domain}"; "send_resolved" = true; } ]; } ]; }; }; rules = [ '' groups: - name: custom_rules rules: - record: battery_percent expr: 100 * battery_energy_now / battery_energy_full - alert: battery_soon_out expr: predict_linear(battery_percent[30m], 3600) <= 10 for: 5m labels: severity: warning annotations: summary: "Instance [{{ $labels.instance }}] battery about 1h left" description: "[{{ $labels.instance }}] battery in 1h estimated to {{ $value }}%" '' ]; */ }; systemd.services.grafana.after = ["wireguard-wg-intra.service"]; systemd.services.grafana.requires = ["wireguard-wg-intra.service"]; services.grafana = { enable = true; addr = "${hostName}.wg"; # listenAddress; port = 3000; analytics.reporting.enable = false; extraOptions = { ANALYTICS_CHECK_FOR_UPDATES = "false"; }; }; # override systemd exporter execstart to enable option... # FIXME: use extraFlags systemd.services.prometheus-systemd-exporter.serviceConfig = { ExecStart = lib.mkForce '' ${pkgs.prometheus-systemd-exporter}/bin/systemd_exporter \ --web.listen-address=${listenAddress}:${toString prometheus.exporters.systemd.port} \ --systemd.collector.enable-file-descriptor-size \ --systemd.collector.enable-ip-accounting \ --systemd.collector.enable-restart-count ''; }; }