From 8fda0125d8641018db73b2ccafe8b8302937660f Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 11 Nov 2022 16:15:19 +0100 Subject: ... --- modules/prometheus-lvm-exporter.nix | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 modules/prometheus-lvm-exporter.nix (limited to 'modules') diff --git a/modules/prometheus-lvm-exporter.nix b/modules/prometheus-lvm-exporter.nix new file mode 100644 index 00000000..f0951d46 --- /dev/null +++ b/modules/prometheus-lvm-exporter.nix @@ -0,0 +1,57 @@ +{ 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.str; + default = "localhost"; + }; + 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.listen-address" "${cfg.listenAddress}:${toString cfg.port}" + ]}"; + + Restart = "always"; + }; + }; + }; +} -- cgit v1.2.3