prometheus-shelly-exporter: add NixOS module

Changed files
+42
nixos
modules
services
monitoring
prometheus
tests
+1
nixos/modules/services/monitoring/prometheus/exporters.nix
···
"rspamd"
"rtl_433"
"script"
+
"shelly"
"snmp"
"smartctl"
"smokeping"
+27
nixos/modules/services/monitoring/prometheus/exporters/shelly.nix
···
+
{ 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}
+
'';
+
};
+
};
+
}
+14
nixos/tests/prometheus-exporters.nix
···
'';
};
+
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;