summary refs log tree commit diff
path: root/modules/foundation/monitoring/default.nix
blob: a7bc185ce69249550c1ba640fef0b68a880ec53d (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
{ me, config, lib, ... }:

let
  inherit (lib) mkOption mkEnableOption types;

  cfg = config.foundation.monitoring;

  ports = {
    victoriaDefaultPort = 8428;
    nodeExporterPort = 9001;
    cadvisorExporterPort = 9002;
    nginxExporterPort = 9113;
    dockerExporterPort = 9323;
  };

  serverConfiguration = import ./server.nix ({
    hosts = cfg.server.hosts;
    victoriaAddress = me.tailscale.ip;
  } // ports);

  clientConfiguration = import ./client.nix ({
    listenAddress = me.tailscale.ip;
  } // ports);
in
{
  imports = [ ../../../services/monitoring/wrapper.nix ];

  options.foundation.monitoring = {
    server = {
      enable = mkEnableOption "monitoring server";

      hosts = mkOption {
        type = with types; listOf (submodule {
          options = {
            name = mkOption { type = str; };
            ip = mkOption { type = str; };
          };
        });
        default = [ ];
      };
    };

    client = {
      enable = mkEnableOption "monitoring client";
    };
  };

  config = lib.mkMerge [
    (lib.mkIf cfg.server.enable serverConfiguration)
    (lib.mkIf (cfg.client.enable || cfg.server.enable) clientConfiguration)
  ];
}