summaryrefslogtreecommitdiff
path: root/nixos/hosts/tente/grafana.nix
blob: 02d26c50828404c5627750bd3cc89e4c6cfe9a4b (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
{ config, lib, pkgs, ... }:

let
  cfg = config.grafana;
in
{
  options.grafana = {
    port = lib.mkOption {
      type = lib.types.int;
    };
    matrixForwarderPort = lib.mkOption {
      type = lib.types.int;
    };
    prometheusSqlExporterPort = lib.mkOption {
      type = lib.types.int;
    };
    matrixServerUrl = lib.mkOption {
      type = lib.types.str;
    };
  };

  imports = [
    <top/shared/prometheus-sql-exporter/service.nix>
    <top/shared/grafana-matrix-forwarder/service.nix>
  ];

  config = {
    age.secrets.grafana-matrix-forwarder-env.file = <top/secrets/grafana-matrix-forwarder-env.age>;

    services.grafana = {
      enable = true;
      settings = {
        server = {
          http_addr = "0.0.0.0";
          http_port = cfg.port;
        };
      };

      provision = {
        enable = true;
        datasources.settings.datasources = [
          {
            name = "Prometheus Tente";
            type = "prometheus";
            url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}";
          }
          {
            name = "Loki Tente";
            type = "loki";
            access = "proxy";
            url = "http://127.0.0.1:${toString config.services.loki.configuration.server.http_listen_port}";
          }
          {
            name = "Prometheus Ev";
            type = "prometheus";
            url = "http://ev.tailnet:9090";
          }
          {
            name = "Loki Ev";
            type = "loki";
            access = "proxy";
            url = "http://ev.tailnet:3030";
          }
        ];
      };
    };
    services.grafana-matrix-forwarder = {
      enable = true;
      port = cfg.matrixForwarderPort;
      homeserver = cfg.matrixServerUrl;
      environmentFile = config.age.secrets.grafana-matrix-forwarder-env.path;
    };
  };
}