summaryrefslogtreecommitdiffstats
path: root/nixos
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2019-06-02 03:13:53 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2019-06-07 17:40:44 +0200
commitbf09e6a14ea1cdb3e07d17acefd67248c614b685 (patch)
tree66926971fa97f547c053605ffce2c3d508883430 /nixos
parentb7d1bd8efbaa875387683060dd7b2f5ceabffa93 (diff)
prometheus-wireguard-exporter: init at 2.0.1
This is a simple exporter which exports the information provided by `wg show all dump` to prometheus. Co-authored-by: Franz Pletz <fpletz@fnordicwalking.de>
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters.nix1
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/wireguard.nix42
-rw-r--r--nixos/tests/prometheus-exporters.nix23
3 files changed, 66 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix
index fa53107ef24b..20e7eba43412 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters.nix
@@ -34,6 +34,7 @@ let
unifi = import ./exporters/unifi.nix { inherit config lib pkgs; };
varnish = import ./exporters/varnish.nix { inherit config lib pkgs; };
bind = import ./exporters/bind.nix { inherit config lib pkgs; };
+ wireguard = import ./exporters/wireguard.nix { inherit config lib pkgs; };
};
mkExporterOpts = ({ name, port }: {
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/wireguard.nix b/nixos/modules/services/monitoring/prometheus/exporters/wireguard.nix
new file mode 100644
index 000000000000..c5b84e574b8d
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/wireguard.nix
@@ -0,0 +1,42 @@
+{ config, lib, pkgs }:
+
+with lib;
+
+let
+ cfg = config.services.prometheus.exporters.wireguard;
+in {
+ port = 9586;
+ extraOpts = {
+ verbose = mkEnableOption "Verbose logging mode for prometheus-wireguard-exporter";
+
+ wireguardConfig = mkOption {
+ type = with types; nullOr (either path str);
+ default = null;
+
+ description = ''
+ Path to the Wireguard Config to
+ <link xlink:href="https://github.com/MindFlavor/prometheus_wireguard_exporter/tree/2.0.0#usage">add the peer's name to the stats of a peer</link>.
+
+ Please note that <literal>networking.wg-quick</literal> is required for this feature
+ as <literal>networking.wireguard</literal> uses
+ <citerefentry><refentrytitle>wg</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ to set the peers up.
+ '';
+ };
+ };
+ serviceOpts = {
+ script = ''
+ ${pkgs.prometheus-wireguard-exporter}/bin/prometheus_wireguard_exporter \
+ -p ${toString cfg.port} \
+ ${optionalString cfg.verbose "-v"} \
+ ${optionalString (cfg.wireguardConfig != null) "-n ${cfg.wireguardConfig}"}
+ '';
+
+ path = [ pkgs.wireguard-tools ];
+
+ serviceConfig = {
+ DynamicUser = true;
+ AmbientCapabilities = [ "CAP_NET_ADMIN" ];
+ };
+ };
+}
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index ac50ca934896..90c7c9701f60 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -315,6 +315,29 @@ let
succeed("curl -sSf http://localhost:9131/metrics | grep -q 'varnish_up 1'");
'';
};
+
+ wireguard = let snakeoil = import ./wireguard/snakeoil-keys.nix; in {
+ exporterConfig.enable = true;
+ metricProvider = {
+ networking.wireguard.interfaces.wg0 = {
+ ips = [ "10.23.42.1/32" "fc00::1/128" ];
+ listenPort = 23542;
+
+ inherit (snakeoil.peer0) privateKey;
+
+ peers = singleton {
+ allowedIPs = [ "10.23.42.2/32" "fc00::2/128" ];
+
+ inherit (snakeoil.peer1) publicKey;
+ };
+ };
+ };
+ exporterTest = ''
+ waitForUnit("prometheus-wireguard-exporter.service");
+ waitForOpenPort(9586);
+ succeed("curl -sSf http://localhost:9586/metrics | grep '${snakeoil.peer1.publicKey}'");
+ '';
+ };
};
in
mapAttrs (exporter: testConfig: (makeTest {