about summary refs log tree commit diff
path: root/hosts/common/server/prometheus.nix
blob: 401dd2b931b7004d5da56df015551b378bda4e7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{ config, pkgs, lib, ... }:

let
  relabelConfigs = [
    {
      source_labels = [ "__address__" ];
      target_label = "instance";
      replacement = "nas";
      action = "replace";
      regex = "192.168.6.10:(.*)";
    }
    {
      source_labels = [ "__address__" ];
      target_label = "instance";
      replacement = "rtr";
      action = "replace";
      regex = "192.168.6.1:(.*)";
    }
    {
      source_labels = [ "__address__" ];
      target_label = "instance";
      replacement = "tahoe";
      action = "replace";
      regex = "192.168.6.20:(.*)";
    }
  ];
in {
  services.prometheus = {
    enable = true;

    globalConfig.scrape_interval = "15s";

    extraFlags = [
      # 3 years of retention
      "--storage.tsdb.retention=${toString (365 * 3)}d"
      "--web.enable-admin-api"
    ];

    scrapeConfigs = [
      {
        job_name = "node";
        static_configs = [{
          targets =
            [ "192.168.6.1:9100" "192.168.6.10:9100" "192.168.6.20:9100" ];
        }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "prometheus";
        static_configs = [{ targets = [ "192.168.6.20:9090" ]; }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "traefik";
        static_configs = [{ targets = [ "192.168.6.20:8090" ]; }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "gitea";
        static_configs = [{ targets = [ "192.168.6.20:8002" ]; }];
        relabel_configs = relabelConfigs;
      }

      {
        job_name = "dnsd";
        static_configs = [{ targets = [ "192.168.6.1:8053" ]; }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "dnsdd";
        static_configs = [{ targets = [ "192.168.6.1:9060" ]; }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "dhcpd";
        static_configs = [{ targets = [ "192.168.6.1:8067" ]; }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "netd";
        static_configs = [{ targets = [ "192.168.6.1:8055" ]; }];
        relabel_configs = relabelConfigs;
      }
      {
        job_name = "unifi-poller";
        static_configs = [{ targets = [ "192.168.6.20:9130" ]; }];
        relabel_configs = relabelConfigs;
      }
    ];
  };

  age.secrets.restic-repo-systems.file =
    ../../../secrets/restic/repo-systems.age;

  services.restic.backups = {
    prometheus = {
      paths = [ "/var/lib/prometheus2" ];
      repository = "/data/slow/backups/systems";
      passwordFile = config.age.secrets.restic-repo-systems.path;
      initialize = true;
      timerConfig = { OnCalendar = "00:25"; };
      extraBackupArgs = [ "--tag prometheus" ];
      pruneOpts = [ "--keep-daily 7" "--keep-weekly 4" ];
    };
  };
}