summaryrefslogtreecommitdiff
path: root/systems/atlas/victoria-metrics.nix
blob: fba00ae65b94b24dcac1c64e43f5c4b37182bcc4 (plain)
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
{
  config,
  lib,
  inputs,
  ...
}:

let
  usesNodeExporter = system: system.config.services.prometheus.exporters.node.enable;

  nodeExporterFrom =
    system:
    "http://${system.config.networking.hostName}:${toString system.config.services.prometheus.exporters.node.port}";

  toNodeStaticConfig = system: {
    targets = [ (nodeExporterFrom system) ];
    labels.type = "node";
  };

  remoteNodes = lib.mapAttrsToList (lib.const toNodeStaticConfig) (
    lib.filterAttrs (lib.const usesNodeExporter) inputs.self.nixosConfigurations
  );
in

{
  borealis = {
    victorialogs = {
      enable = true;
    };
  };

  services = {
    journald.upload.enable = true;

    prometheus.exporters.node.enable = true;

    victoriametrics = {
      enable = true;

      retentionPeriod = "7d";

      prometheusConfig = {
        scrape_configs = [
          {
            job_name = "forgejo";
            metrics_path = "/metrics";
            static_configs = [
              {
                targets = [
                  "http://${config.services.forgejo.settings.server.HTTP_ADDR}:${toString config.services.forgejo.settings.server.HTTP_PORT}"
                ];
                labels.type = "forgejo";
              }
            ];
          }

          {
            job_name = "miniflux";
            metrics_path = "/metrics";
            static_configs = [
              {
                targets = [ "http://${config.services.miniflux.config.LISTEN_ADDR}" ];
                labels.type = "miniflux";
              }
            ];
          }

          {
            job_name = "node-exporter";
            metrics_path = "/metrics";
            static_configs = remoteNodes;
          }

          {
            job_name = "victoria-logs";
            metrics_path = "/metrics";
            static_configs = [
              {
                targets = [ "localhost:9428" ];
                labels.type = "victoria-logs";
              }
            ];
          }

          {
            job_name = "victoria-metrics";
            metrics_path = "/metrics";
            static_configs = [
              {
                targets = [ "localhost${config.services.victoriametrics.listenAddress}" ];
                labels.type = "victoria-logs";
              }
            ];
          }
        ];
      };
    };
  };
}