summary refs log tree commit diff
path: root/modules/monitoring/postgres.nix
blob: 25266faf5b174d2c303e30065c4ed18ee2506540 (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
{ lib, config, ... }:
let
  cfg = config.monitoring;
in
{
  config = lib.mkIf (cfg.monitorAll && config.services.postgresql.enable) {
    services.prometheus.exporters.postgres = {
      enable = true;
      extraFlags = [
        "--collector.database_wraparound"
        "--collector.long_running_transactions"
        "--collector.postmaster"
        "--collector.process_idle"
        "--collector.stat_activity_autovacuum"
        "--collector.stat_statements"
        #"--collector.stat_wal_receiver" #we dont have WAL receivers
        "--collector.statio_user_indexes"
        "--collector.xlog_location"
      ];
    };

    services.prometheus.scrapeConfigs = [
      {
        job_name = "postgres";
        scrape_interval = "${toString cfg.prometheusScrapeInterval}s";
        static_configs = [ { targets = [ "localhost:${toString config.services.prometheus.exporters.postgres.port}" ]; } ];
      }
    ];

    services.grafana.provision.dashboards.settings = {
      apiVersion = 1;
      providers = [
        {
          name = "14114-postgres-overview";
          orgId = 1;
          type = "file";
          options = {
            path = builtins.fetchurl {
              url = "https://grafana.com/api/dashboards/14114/revisions/1/download";
              sha256 = "0hk0d2nk8nh5ldd17sy3wwpn1xhyinjlsy5vgmnvpvn6g97n342z";
            };
          };
        }
      ];
    };

  };
}