Skip to content

Commit

Permalink
prometheus-unifi-poller-exporter: init module
Browse files Browse the repository at this point in the history
  • Loading branch information
elseym committed Sep 6, 2020
1 parent 8c49e5a commit aaf0002
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/modules/services/monitoring/prometheus/exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let
"surfboard"
"tor"
"unifi"
"unifi-poller"
"varnish"
"wireguard"
] (name:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ config, lib, pkgs, options }:

with lib;

let
cfg = config.services.prometheus.exporters.unifi-poller;

configFile = pkgs.writeText "prometheus-unifi-poller-exporter.json" (generators.toJSON {} {
poller = { inherit (cfg.log) debug quiet; };
unifi = { inherit (cfg) controllers; };
influxdb.disable = true;
prometheus = {
http_listen = "${cfg.listenAddress}:${toString cfg.port}";
report_errors = cfg.log.prometheusErrors;
};
});

in {
port = 9130;

extraOpts = {
inherit (options.services.unifi-poller.unifi) controllers;
log = {
debug = mkEnableOption "debug logging including line numbers, high resolution timestamps, per-device logs.";
quiet = mkEnableOption "startup and error logs only.";
prometheusErrors = mkEnableOption "emitting errors to prometheus.";
};
};

serviceOpts.serviceConfig = {
ExecStart = "${pkgs.unifi-poller}/bin/unifi-poller --config ${configFile}";
DynamicUser = false;
};
}
13 changes: 13 additions & 0 deletions nixos/tests/prometheus-exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,19 @@ let
'';
};

unifi-poller = {
nodeName = "unifi_poller";
exporterConfig.enable = true;
exporterConfig.controllers = [ { } ];
exporterTest = ''
wait_for_unit("prometheus-unifi-poller-exporter.service")
wait_for_open_port(9130)
succeed(
"curl -sSf localhost:9130/metrics | grep -q 'unifipoller_build_info{.\\+} 1'"
)
'';
};

varnish = {
exporterConfig = {
enable = true;
Expand Down

0 comments on commit aaf0002

Please sign in to comment.