DEVELOPMENT ENVIRONMENT

~liljamo/nix-arta

ref: b6b039dab59bf7ee6f0856bb5e2953de9d7b1a58 nix-arta/systems/hosts/metrics/default.nix -rw-r--r-- 3.7 KiB
b6b039daJonni Liljamo feat(lib/util): more functions 2 months 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
181
182
183
184
{...}: 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 = ["localhost:${toString prometheusPort}"];
          }
        ];
      }

      # lxcmetrics
      # node, systemd
      {
        job_name = "lxcmetrics_job";
        static_configs = [
          {
            targets = ["localhost:9100" "localhost:9558"];
          }
        ];
      }

      # lxcproxy
      # haproxy, node, systemd
      {
        job_name = "lxcproxy_job";
        static_configs = [
          {
            targets = ["10.1.2.10:8404" "10.1.2.10:9100" "10.1.2.10:9558"];
          }
        ];
      }

      # lxccloud
      # node, systemd
      {
        job_name = "lxccloud_job";
        static_configs = [
          {
            targets = ["10.1.2.15:9100" "10.1.2.15:9558"];
          }
        ];
      }

      # uwulpine vm
      {
        job_name = "node_uwulpine";
        static_configs = [
          {
            targets = ["10.1.1.10:9091"];
          }
        ];
      }
      {
        job_name = "cadvisor_uwulpine";
        static_configs = [
          {
            targets = ["10.1.1.10:9092"];
          }
        ];
      }
      {
        job_name = "jellyfin";
        static_configs = [
          {
            targets = ["10.1.2.20: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;
    };
  };

  system.stateVersion = "24.05";
}