summary refs log tree commit diff
path: root/nix/modules/default/integration-prometheus.nix
blob: 3917bb38a3fc17470c7eaa5b53c1a931eb3f150e (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
{
  config,
  lib,
  ...
}:

let
  cfg = config.services.spacebarchat-server;
in
{
  options.services.spacebarchat-server.prometheus = {
    enable = lib.mkEnableOption "prometheus integration";
  };

  config = lib.mkIf (cfg.enable && cfg.prometheus.enable) {
    services.prometheus.scrapeConfigs = [
      {
        job_name = "spacebar-api-${builtins.toString cfg.apiEndpoint.localPort}";
        scrape_interval = "1s";
        static_configs = [
          { targets = [ "localhost:${builtins.toString cfg.apiEndpoint.localPort}" ]; }
        ];
      }
      {
        job_name = "spacebar-gateway-${builtins.toString cfg.gatewayEndpoint.localPort}";
        scrape_interval = "1s";
        static_configs = [
          { targets = [ "localhost:${builtins.toString cfg.gatewayEndpoint.localPort}" ]; }
        ];
      }
      {
        job_name = "spacebar-cdn-${builtins.toString cfg.cdnEndpoint.localPort}";
        scrape_interval = "1s";
        static_configs = [
          { targets = [ "localhost:${builtins.toString cfg.cdnEndpoint.localPort}" ]; }
        ];
      }
    ]
    ++ (lib.map (port: {
      job_name = "spacebar-gateway-${builtins.toString port}";
      scrape_interval = "1s";
      static_configs = [
        { targets = [ "localhost:${builtins.toString port}" ]; }
      ];
    }) cfg.extraGatewayPorts);
  };
}