aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/mo/monitoring/components/scrutiny.nix
blob: 70d413a87ba79ae8cb21cfd22fc02ddbfd295b83 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
  config,
  pkgs,
  lib,
  ...
}: let
  cfg = config.vhack.monitoring.scrutiny;
in {
  options.vhack.monitoring.scrutiny = {
    enable = lib.mkEnableOption "scrutiny service";

    fqdn = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      description = ''
        If a string, this will be the domain under which the scrutiny web interface will be servced.

        If null, the web interface will not be served and only the prometheus metrics will be accessible.
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    vhack.monitoring = {
      prometheus.sources = [
        {
          name = "scrutiny";
          extra.metrics_path = "/api/metrics";
          target = "127.0.0.1:${toString config.services.scrutiny.settings.web.listen.port}";
        }
        {
          name = "smartctl";
          target = "127.0.0.1:${toString config.services.prometheus.exporters.smartctl.port}";
        }
      ];
      grafana.dashboards = [
        ../dashboards/Health.json
      ];
    };

    users = {
      groups = {
        smartctl-exporter-access.gid = config.vhack.constants.ids.gids.smartctl-exporter-access;
      };
      users = {
        smartctl-exporter-access = {
          isSystemUser = true;
          group = "smartctl-exporter-access";
          uid = config.vhack.constants.ids.uids.smartctl-exporter-access;
        };
      };
    };

    services = {
      scrutiny = {
        enable = true;

        openFirewall = false;

        # This src includes Prometheus metrics exporter.
        package = pkgs.scrutiny.overrideAttrs {
          src = pkgs.fetchFromGitHub {
            owner = "ibizaman";
            repo = "scrutiny";
            rev = "74faf06f77df83f29e7e1806cd88b2fafc0bbb82";
            hash = "sha256-r0AVWL+E046xHxitwMPfRNTOpjuOk+W6tB41YgmLTPg=";
          };

          vendorHash = "sha256-kAlnlWnBMFCdgdak5L5hRquRtyLi5MTmDa/kxwqPs4E=";
        };

        settings = {
          web = {
            metrics.enabled = true; # Enables Prometheus exporter
            listenHost = "127.0.0.1";
          };
        };

        collector = {
          enable = true;
        };
      };

      # nginx.statusPage = lib.mkDefault config.services.nginx.enable;
      nginx = lib.mkIf (cfg.fqdn != null) {
        virtualHosts."${cfg.fqdn}" = {
          locations."/".proxyPass = "http://127.0.0.1:${toString config.services.scrutiny.settings.web.listen.port}";

          enableACME = true;
          forceSSL = true;
        };
      };

      netdata = {
        enable = true;
        config = {
          # web.mode = "none";
          # web."bind to" = "127.0.0.1:19999";
          global = {
            "debug log" = "syslog";
            "access log" = "syslog";
            "error log" = "syslog";
          };
        };
      };
      prometheus = {
        exporters.smartctl = {
          enable = true;
          port = 9115;
          listenAddress = "127.0.0.1";
        };
      };
    };

    # nixpkgs.overlays = [
    #   (final: prev: {
    #     prometheus-systemd-exporter = prev.prometheus-systemd-exporter.overrideAttrs {
    #       src = final.fetchFromGitHub {
    #         owner = "ibizaman";
    #         repo = prev.prometheus-systemd-exporter.pname;
    #         # rev = "v${prev.prometheus-systemd-exporter.version}";
    #         rev = "next_timer";
    #         sha256 = "sha256-jzkh/616tsJbNxFtZ0xbdBQc16TMIYr9QOkPaeQw8xA=";
    #       };
    #
    #       vendorHash = "sha256-4hsQ1417jLNOAqGkfCkzrmEtYR4YLLW2j0CiJtPg6GI=";
    #     };
    #   })
    # ];
  };
}