From 9f17e032e7e7c34ddf8c04472bee9d627951fc44 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 30 Jan 2023 18:58:42 +0100 Subject: [PATCH] prometheus-shelly-exporter: add NixOS module --- .../monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/shelly.nix | 27 +++++++++++++++++++ nixos/tests/prometheus-exporters.nix | 14 ++++++++++ 3 files changed, 42 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/shelly.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index f3fbfb149ad7..b2132b62d678 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -64,6 +64,7 @@ let "rspamd" "rtl_433" "script" + "shelly" "snmp" "smartctl" "smokeping" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/shelly.nix b/nixos/modules/services/monitoring/prometheus/exporters/shelly.nix new file mode 100644 index 000000000000..b9cfd1b1e84a --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/shelly.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.shelly; +in +{ + port = 9784; + extraOpts = { + metrics-file = mkOption { + type = types.path; + description = lib.mdDoc '' + Path to the JSON file with the metric definitions + ''; + }; + }; + serviceOpts = { + serviceConfig = { + ExecStart = '' + ${pkgs.prometheus-shelly-exporter}/bin/shelly_exporter \ + -metrics-file ${cfg.metrics-file} \ + -listen-address ${cfg.listenAddress}:${toString cfg.port} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 5f50a3f87d5d..82d50da63818 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -1060,6 +1060,20 @@ let ''; }; + shelly = { + exporterConfig = { + enable = true; + metrics-file = "${pkgs.writeText "test.json" ''{}''}"; + }; + exporterTest = '' + wait_for_unit("prometheus-shelly-exporter.service") + wait_for_open_port(9784) + wait_until_succeeds( + "curl -sSf 'localhost:9784/metrics'" + ) + ''; + }; + script = { exporterConfig = { enable = true;