summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix
diff options
context:
space:
mode:
authorMatej Urbas <matej.urbas@gmail.com>2020-12-05 23:26:59 +0000
committerMatej Urbas <matej.urbas@gmail.com>2020-12-10 19:02:30 +0000
commit4948743705ae821a4e01e48ca6a797571b87b04a (patch)
tree3cce1df139109a279e304c1c16ee4b960c4bfdfe /nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix
parent1f65211aa37adfc5a28c4849bbe73dcb2d2d1e2b (diff)
downloadnixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.tar
nixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.tar.gz
nixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.tar.bz2
nixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.tar.lz
nixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.tar.xz
nixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.tar.zst
nixpkgs-4948743705ae821a4e01e48ca6a797571b87b04a.zip
nixos/prometheus-exporters/py-air-control: init
Diffstat (limited to 'nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix62
1 files changed, 62 insertions, 0 deletions
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 <literal>/var/lib</literal> 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}"
+      ];
+    };
+  };
+}