summary refs log tree commit diff
path: root/modules/monitoring/synapse.nix
blob: a0006983333fd4ae99c37f60bb585cd397cf3e11 (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
{ lib, config, ... }:
let
  cfg = config.monitoring;
in
{
  config = lib.mkIf (cfg.monitorAll && config.services.matrix-synapse.enable) {
    services.matrix-synapse.settings.enable_metrics = true;
    services.matrix-synapse.settings.metrics_flags.known_servers = true;
    # services.matrix-synapse.settings.federation_metrics_domains = [ "matrix.org" ]; # - maybe someday
    services.matrix-synapse.settings.listeners = [
      {
        type = "metrics";
        port = 9200;
        tls = false;
        resources = [ ];
        bind_addresses = [ "127.0.0.1" ];
      }
    ];

    services.matrix-synapse.workers = (
      lib.listToAttrs (
        lib.imap (index: workerName: {
          name = workerName;
          value = {
            worker_listeners = [
              {
                type = "metrics";
                port = 9200 + index + 1;
                resources = [ ];
                bind_addresses = [ "127.0.0.1" ];
              }
            ];
          };
        }) config.monitoring.synapse.workerNames
      )
    );

    services.prometheus.ruleFiles = [
      ./rules/synapse.rules
    ];
    services.prometheus.scrapeConfigs =
      [
        {
          job_name = "synapse-main";
          scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
          static_configs = [
            {
              targets = [ "localhost:9200" ];
              labels.instance = "synapse";
            }
          ];
          metrics_path = "_synapse/metrics";
        }
      ]
      ++ lib.flatten (
        lib.imap (index: workerName: {
          job_name = "synapse-${workerName}";
          scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
          static_configs = [
            {
              targets = [ "localhost:${toString (9200 + index + 1)}" ];
              labels.instance = "synapse";
            }
          ];
          metrics_path = "_synapse/metrics";
        }) config.monitoring.synapse.workerNames
      );

    services.grafana.provision.dashboards.settings = {
      apiVersion = 1;
      providers = [
        {
          name = "matrix-synapse";
          orgId = 1;
          type = "file";
          options = {
            path = builtins.fetchurl {
              url = "https://raw.githubusercontent.com/element-hq/synapse/master/contrib/grafana/synapse.json";
              sha256 = "07qlr0waw9phmyd38bv22bn5v303w3397b89l44l3lzwhpnhs16s";
            };
          };
        }
      ];
    };

  };
}