summaryrefslogtreecommitdiff
path: root/modules/prometheus-lvm-exporter.nix
blob: fe5c4efa9b2504ffdb0a4b5cf4b4faae6eb7163e (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
{ 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 = null;
      };
      port = mkOption {
        type = types.port;
        default = 9845;
      };

      openFirewall = mkOption {
        type = types.bool;
        default = false;
        description = lib.mdDoc ''
          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 = lib.mdDoc ''
          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";
      };
    };

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