From 4948743705ae821a4e01e48ca6a797571b87b04a Mon Sep 17 00:00:00 2001 From: Matej Urbas Date: Sat, 5 Dec 2020 23:26:59 +0000 Subject: nixos/prometheus-exporters/py-air-control: init --- .../prometheus/exporters/py-air-control.nix | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix (limited to 'nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix') diff --git a/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix b/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix new file mode 100644 index 00000000000..d9a627ca2ea --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix @@ -0,0 +1,62 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.py-air-control; + + py-air-control-exporter-env = pkgs.python3.withPackages (pyPkgs: [ + pyPkgs.py-air-control-exporter + ]); + + workingDir = "/var/lib/${cfg.stateDir}"; + +in +{ + port = 9896; + extraOpts = { + deviceHostname = mkOption { + type = types.str; + example = "192.168.1.123"; + description = '' + The hostname of the air purification device from which to scrape the metrics. + ''; + }; + protocol = mkOption { + type = types.str; + default = "http"; + description = '' + The protocol to use when communicating with the air purification device. + Available: [http, coap, plain_coap] + ''; + }; + stateDir = mkOption { + type = types.str; + default = "prometheus-py-air-control-exporter"; + description = '' + Directory below /var/lib to store runtime data. + This directory will be created automatically using systemd's StateDirectory mechanism. + ''; + }; + }; + serviceOpts = { + serviceConfig = { + DynamicUser = false; + StateDirectory = cfg.stateDir; + WorkingDirectory = workingDir; + ExecStart = '' + ${py-air-control-exporter-env}/bin/python -c \ + "from py_air_control_exporter import app; app.create_app().run( \ + debug=False, \ + port=${toString cfg.port}, \ + host='${cfg.listenAddress}', \ + )" + ''; + Environment = [ + "PY_AIR_CONTROL_HOST=${cfg.deviceHostname}" + "PY_AIR_CONTROL_PROTOCOL=${cfg.protocol}" + "HOME=${workingDir}" + ]; + }; + }; +} -- cgit 1.4.1 From 4970fbedbcab6f7a9d4030952c0a01c33b0f4e97 Mon Sep 17 00:00:00 2001 From: Matej Urbas Date: Mon, 7 Dec 2020 12:15:38 +0000 Subject: nixos/prometheus-exporters/py-air-control: invoke exporter command Package `py-air-control exporter` v0.1.5 comes with a new CLI. This change uses the new CLI (which simplifies the exporter's systemd service setup). --- .../prometheus/exporters/py-air-control.nix | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix') diff --git a/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix b/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix index d9a627ca2ea..d9ab99221d9 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix @@ -5,10 +5,6 @@ with lib; let cfg = config.services.prometheus.exporters.py-air-control; - py-air-control-exporter-env = pkgs.python3.withPackages (pyPkgs: [ - pyPkgs.py-air-control-exporter - ]); - workingDir = "/var/lib/${cfg.stateDir}"; in @@ -45,18 +41,13 @@ in StateDirectory = cfg.stateDir; WorkingDirectory = workingDir; ExecStart = '' - ${py-air-control-exporter-env}/bin/python -c \ - "from py_air_control_exporter import app; app.create_app().run( \ - debug=False, \ - port=${toString cfg.port}, \ - host='${cfg.listenAddress}', \ - )" + ${pkgs.python3Packages.py-air-control-exporter}/bin/py-air-control-exporter \ + --host ${cfg.deviceHostname} \ + --protocol ${cfg.protocol} \ + --listen-port ${toString cfg.port} \ + --listen-address ${cfg.listenAddress} ''; - Environment = [ - "PY_AIR_CONTROL_HOST=${cfg.deviceHostname}" - "PY_AIR_CONTROL_PROTOCOL=${cfg.protocol}" - "HOME=${workingDir}" - ]; + Environment = [ "HOME=${workingDir}" ]; }; }; } -- cgit 1.4.1