about summary refs log tree commit diff
path: root/modules/services/monitoring/grafana.nix
blob: 28e86f619c7c22f4e33129d77181d782fd52d446 (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
{ config, lib, pkgs, ... }:
let
  cfg = config.my.services.monitoring.grafana;
  secrets = config.age.secrets;
in
{
  options.my.services.monitoring.grafana = with lib; {
    enable = mkEnableOption "grafana observability stack";
    vhostName = mkOption {
      type = types.str;
      example = "dash.fcuny.net";
      description = "Name for the virtual host";
    };
  };

  config = lib.mkIf cfg.enable {
    services.grafana = {
      enable = true;
      settings = {
        security.adminUser = "fcuny";
        analytics.reporting_enabled = false;
        server.http_port = 4000;
        server.http_addr = "127.0.0.1";
      };
      provision = {
        enable = true;
        datasources.settings.datasources = [
          {
            name = "prometheus";
            type = "prometheus";
            isDefault = true;
            url = "http://${config.my.services.monitoring.prometheus.listenAddress}:${toString config.my.services.monitoring.prometheus.listenPort}";
          }
          {
            name = "loki";
            url = "http://${config.my.services.monitoring.loki.listenAddress}:${toString config.my.services.monitoring.loki.listenPort}";
            type = "loki";
          }
        ];
        dashboards.settings.providers = [{
          disableDeletion = true;
          options.path = ./dashboards;
        }];
      };
    };

    services.nginx.virtualHosts."${cfg.vhostName}" = {
      forceSSL = true;
      useACMEHost = config.homelab.domain;
      listen = [
        {
          addr = "192.168.6.40";
          port = 443;
          ssl = true;
        }
        {
          addr = "192.168.6.40";
          port = 80;
          ssl = false;
        }
      ];
      locations."/" = {
        proxyPass = "http://${config.services.grafana.settings.server.http_addr}:${
            toString config.services.grafana.settings.server.http_port
          }";
        proxyWebsockets = true;
      };
    };

    my.services.backup = {
      paths = [ "/var/lib/grafana" ];
      exclude = [
        "/var/lib/grafana/data/log/"
        "/var/lib/grafana/log/"
      ];
    };
  };
}