nixos/prometheus-exporters/py-air-control: init

This commit is contained in:
Matej Urbas 2020-12-05 23:26:59 +00:00
parent 1f65211aa3
commit 4948743705
3 changed files with 78 additions and 0 deletions

View File

@ -41,6 +41,7 @@ let
"openvpn"
"postfix"
"postgres"
"py-air-control"
"redis"
"rspamd"
"rtl_433"

View File

@ -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}"
];
};
};
}

View File

@ -530,6 +530,21 @@ let
'';
};
py-air-control = {
nodeName = "py_air_control";
exporterConfig = {
enable = true;
deviceHostname = "127.0.0.1";
};
exporterTest = ''
wait_for_unit("prometheus-py-air-control-exporter.service")
wait_for_open_port(9896)
succeed(
"curl -sSf http://localhost:9896/metrics | grep -q 'py_air_control_sampling_error_total'"
)
'';
};
redis = {
exporterConfig = {
enable = true;