summaryrefslogtreecommitdiff
path: root/modules/prometheus-lvm-exporter.nix
blob: ad46f835a195c1a7f37327a297a04c5c53893c60 (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
{ lib, config, pkgs, utils, ... }:

with lib;

let
  cfg = config.services.prometheus.exporters.lvm;
in {
  options = {
    services.prometheus.exporters.lvm = {
      enable = mkEnableOption "Prometheus LVM exporter";

      listenAddress = mkOption {
        type = types.nullOr types.str;
        default = "127.0.0.1";
      };
      port = mkOption {
        type = types.port;
        default = 9845;
      };

      openFirewall = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Open port in firewall for incoming connections.
        '';
      };
      firewallFilter = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = literalExpression ''
          "-i eth0 -p tcp -m tcp --dport ${toString cfg.port}"
        '';
        description = ''
          Specify a filter for iptables to use when
          {option}`services.prometheus.exporters.lvm.openFirewall`
          is true. It is used as `ip46tables -I nixos-fw firewallFilter -j nixos-fw-accept`.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services."prometheus-lvm-exporter" = {
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];

      serviceConfig = {
        ExecStart = "${pkgs.prometheus-lvm-exporter}/bin/prometheus-lvm-exporter ${utils.escapeSystemdExecArgs [
          "--web.systemd-socket"
        ]}";

        Restart = "always";
        Sockets = "prometheus-lvm-exporter.socket";
      };
    };

    systemd.sockets."prometheus-lvm-exporter" = {
      socketConfig.ListenStream = "${optionalString (cfg.listenAddress != null) (cfg.listenAddress + ":")}${toString cfg.port}";
    };
  };
}