DEVELOPMENT ENVIRONMENT

~liljamo/nix-arta

ref: b8c3e871449260e22e469d2d76f3ebfa6f03f056 nix-arta/systems/hosts/metrics/default.nix -rw-r--r-- 3.7 KiB
b8c3e871Jonni Liljamo fix: tamma secrets path 9 days ago
                                                                                
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{artautil, ...}: let
  influxDB2Port = 8086;
  prometheusPort = 9090;
  lokiPort = 9091;
  grafanaPort = 3000;
in {
  networking.firewall.allowedTCPPorts = [
    influxDB2Port
    prometheusPort
    lokiPort
    grafanaPort
  ];

  services.influxdb2 = {
    enable = true;
    settings = {
      http-bind-address = ":${toString influxDB2Port}";
    };
  };

  services.prometheus = {
    enable = true;
    port = prometheusPort;
    globalConfig = {
      scrape_interval = "5s";
    };
    scrapeConfigs = [
      {
        job_name = "prometheus";
        static_configs = [
          {
            targets = ["metrics.home.arpa:${toString prometheusPort}"];
          }
        ];
      }

      {
        job_name = "cadvisor";
        static_configs = [
          {
            targets = map (x: x + ":9080") (builtins.attrNames (artautil.getDNSEntries "lxc"));
          }
        ];
      }

      {
        job_name = "node";
        static_configs = [
          {
            targets = map (x: x + ":9100") (builtins.attrNames (artautil.getDNSEntries "lxc"));
          }
        ];
      }

      {
        job_name = "systemd";
        static_configs = [
          {
            targets = map (x: x + ":9558") (builtins.attrNames (artautil.getDNSEntries "lxc"));
          }
        ];
      }

      {
        job_name = "blocky";
        static_configs = [
          {
            targets = ["dns.home.arpa:80"];
          }
        ];
      }

      {
        job_name = "haproxy";
        static_configs = [
          {
            targets = ["proxy.home.arpa:8404"];
          }
        ];
      }

      {
        job_name = "jellyfin";
        static_configs = [
          {
            targets = ["10.1.2.30:8096"];
          }
        ];
      }
    ];
  };

  services.loki = {
    enable = true;
    configuration = {
      auth_enabled = false;
      server.http_listen_port = lokiPort;

      ingester = {
        lifecycler = {
          address = "0.0.0.0";
          ring = {
            kvstore = {
              store = "inmemory";
            };
            replication_factor = 1;
          };
          final_sleep = "0s";
        };
        chunk_idle_period = "1h";
        max_chunk_age = "1h";
        chunk_target_size = 1048576;
        chunk_retain_period = "30s";
      };

      schema_config = {
        configs = [
          {
            from = "2022-06-06";
            store = "boltdb-shipper";
            object_store = "filesystem";
            schema = "v13";
            index = {
              prefix = "index_";
              period = "24h";
            };
          }
        ];
      };

      storage_config = {
        boltdb_shipper = {
          active_index_directory = "/var/lib/loki/boltdb-shipper-active";
          cache_location = "/var/lib/loki/boltdb-shipper-cache";
          cache_ttl = "24h";
        };

        filesystem = {
          directory = "/var/lib/loki/chunks";
        };
      };

      limits_config = {
        allow_structured_metadata = false;
        reject_old_samples = true;
        reject_old_samples_max_age = "168h";
        max_query_series = 5000;
      };

      table_manager = {
        retention_deletes_enabled = false;
        retention_period = "0s";
      };

      compactor = {
        working_directory = "/var/lib/loki";
        compactor_ring = {
          kvstore = {
            store = "inmemory";
          };
        };
      };
    };
  };

  services.grafana = {
    enable = true;
    settings = {
      server = {
        http_port = grafanaPort;
        http_addr = "0.0.0.0";
      };
      "auth.anonymous".enabled = true;
      security.allow_embedding = true;
      users.default_theme = "light";
    };
  };

  system.stateVersion = "24.05";
}