summary refs log tree commit diff
path: root/host/Spacebar-monitoring/configuration.nix
blob: 3369094fb91afa3353c47d36b8fe1199d9bc564c (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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
{ config, pkgs, lib, secrets, ... }:

{
    imports =
        [
        ../../modules/base.nix
        ];

    networking = {
        hostName = "Spacebar-monitoring";
        interfaces.ens18.ipv4.addresses = [ { 
            address = "192.168.1.99";
            prefixLength = 24;
        } ];
        interfaces.ens19.ipv4.addresses = [ {
            address = "10.10.11.99";
            prefixLength = 16;
        } ];
    };

    services = {
        prometheus = {
            enable = true;
            stateDir = "prometheus";
            extraFlags = [
                "--storage.local.retention 8760h"
                "--storage.local.series-file-shrink-ratio 0.3"
                "--storage.local.memory-chunks 2097152"
                "--storage.local.max-chunks-to-persist 1048576"
                "--storage.local.index-cache-size.fingerprint-to-metric 2097152"
                "--storage.local.index-cache-size.fingerprint-to-timerange 1048576"
                "--storage.local.index-cache-size.label-name-to-label-values 2097152"
                "--storage.local.index-cache-size.label-pair-to-fingerprints 41943040"
            ];
            # alertmanagerURL = [ "http://localhost:9093" ];
            # rules = [
            #     ''
            #     ALERT node_down
            #     IF up == 0
            #     FOR 5m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}}: Node is down.",
            #         description = "{{$labels.alias}} has been down for more than 5 minutes."
            #     }
            #     ALERT node_systemd_service_failed
            #     IF node_systemd_unit_state{state="failed"} == 1
            #     FOR 4m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}}: Service {{$labels.name}} failed to start.",
            #         description = "{{$labels.alias}} failed to (re)start service {{$labels.name}}."
            #     }
            #     ALERT node_filesystem_full_90percent
            #     IF sort(node_filesystem_free{device!="ramfs"} < node_filesystem_size{device!="ramfs"} * 0.1) / 1024^3
            #     FOR 5m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}}: Filesystem is running out of space soon.",
            #         description = "{{$labels.alias}} device {{$labels.device}} on {{$labels.mountpoint}} got less than 10% space left on its filesystem."
            #     }
            #     ALERT node_filesystem_full_in_4h
            #     IF predict_linear(node_filesystem_free{device!="ramfs"}[1h], 4*3600) <= 0
            #     FOR 5m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}}: Filesystem is running out of space in 4 hours.",
            #         description = "{{$labels.alias}} device {{$labels.device}} on {{$labels.mountpoint}} is running out of space of in approx. 4 hours"
            #     }
            #     ALERT node_filedescriptors_full_in_3h
            #     IF predict_linear(node_filefd_allocated[1h], 3*3600) >= node_filefd_maximum
            #     FOR 20m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}} is running out of available file descriptors in 3 hours.",
            #         description = "{{$labels.alias}} is running out of available file descriptors in approx. 3 hours"
            #     }
            #     ALERT node_load1_90percent
            #     IF node_load1 / on(alias) count(node_cpu{mode="system"}) by (alias) >= 0.9
            #     FOR 1h
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}}: Running on high load.",
            #         description = "{{$labels.alias}} is running with > 90% total load for at least 1h."
            #     }
            #     ALERT node_cpu_util_90percent
            #     IF 100 - (avg by (alias) (irate(node_cpu{mode="idle"}[5m])) * 100) >= 90
            #     FOR 1h
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary = "{{$labels.alias}}: High CPU utilization.",
            #         description = "{{$labels.alias}} has total CPU utilization over 90% for at least 1h."
            #     }
            #     ALERT node_ram_using_90percent
            #     IF node_memory_MemFree + node_memory_Buffers + node_memory_Cached < node_memory_MemTotal * 0.1
            #     FOR 30m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary="{{$labels.alias}}: Using lots of RAM.",
            #         description="{{$labels.alias}} is using at least 90% of its RAM for at least 30 minutes now.",
            #     }
            #     ALERT node_swap_using_80percent
            #     IF node_memory_SwapTotal - (node_memory_SwapFree + node_memory_SwapCached) > node_memory_SwapTotal * 0.8
            #     FOR 10m
            #     LABELS {
            #         severity="page"
            #     }
            #     ANNOTATIONS {
            #         summary="{{$labels.alias}}: Running out of swap soon.",
            #         description="{{$labels.alias}} is using 80% of its swap space for at least 10 minutes now."
            #     }
            #     ''
            # ];
            scrapeConfigs = [
                {
                    job_name = "node";
                    scrape_interval = "5s";
                    static_configs = [
                        {
                            targets = [
                                "localhost:9100"
                            ];
                            labels = {
                                alias = "monitoring";
                            };
                        }
                        {
                            targets = [
                                "192.168.1.2:9100"
                            ];
                            labels = {
                                alias = "nginx";
                            };
                        }
                        {
                            targets = [
                                "192.168.1.3:9100"
                            ];
                            labels = {
                                alias = "email";
                            };
                        }
                        {
                            targets = [
                                "192.168.1.4:9100"
                            ];
                            labels = {
                                alias = "postgres";
                            };
                        }
                        # {
                        #     targets = [
                        #         "192.168.1.5:9100"
                        #     ];
                        #     labels = {
                        #         alias = "synapse";
                        #     };
                        # }
                    ];
                }
            ];
            alertmanager = {
                enable = false;
                listenAddress = "0.0.0.0";
                configuration = {
                    "global" = {
                        "smtp_smarthost" = "smtp.example.com:587";
                        "smtp_from" = "alertmanager@example.com";
                    };
                    "route" = {
                        "group_by" = [ "alertname" "alias" ];
                        "group_wait" = "30s";
                        "group_interval" = "2m";
                        "repeat_interval" = "4h";
                        "receiver" = "team-admins";
                    };
                    "receivers" = [
                        {
                        "name" = "team-admins";
                        "email_configs" = [
                            {
                            "to" = "devnull@example.com";
                            "send_resolved" = true;
                            }
                        ];
                        "webhook_configs" = [
                            {
                            "url" = "https://example.com/prometheus-alerts";
                            "send_resolved" = true;
                            }
                        ];
                        }
                    ];
                };
            };
        };
        grafana = {
            enable = true;
            addr = "0.0.0.0";
            domain = "grafana.spacebar.chat";
            settings = {
                server = {
                    root_url = "https://grafana.spacebar.chat/";
                    enable_gzip = true;
                    domain = "grafana.spacebar.chat";

                };
                analytics.reporting_enabled = false;
                security.secret_key = secrets.grafana.secret_key;
            };
            provision = {
                datasources.settings = {
                    datasources = [
                         {
                            name = "Prometheus";
                            type = "prometheus";
                            url = "http://localhost:9090";
                            access = "proxy";
                            isDefault = true;
                        }
                    ];
                };
                dashboards.settings = {
                    apiVersion = 1;
                    providers = [
                        {
                            name = "Prometheus 2.0 Overview";
                            revision = "1";
                            folder = "prometheus";
                            uid = "prometheus2";
                            type = "file";
                            options = {
                                path = pkgs.fetchurl {
                                    url = "https://grafana.com/api/dashboards/3662/revisions/2/download";
                                    hash = "sha256:111krihyc4ydwcb9r9a6xrn10841nprvb7sz36az2djqyzrj4yzs";
                                };
                            };
                        }
                        {
                            name = "Node Exporter Full";
                            revision = "31";
                            folder = "prometheus";
                            uid = "node-exporter-full";
                            type = "file";
                            options = {
                                path = pkgs.fetchurl {
                                    url = "https://grafana.com/api/dashboards/1860/revisions/31/download";
                                    hash = "sha256:120wyg0d1ycn8wkyng9ngms4v2hri8b7x37dfd318qdjfsr4gi22";
                                };
                            };
                        }
                    ];
                };
            };
        };
    };

    system.stateVersion = "22.11"; # DO NOT EDIT!
}