Merge pull request #115185 from Ma27/knot-exporter

prometheus-knot-exporter: init at 2021-01-30; minor module improvements
This commit is contained in:
WilliButz 2021-03-11 18:58:59 +01:00 committed by GitHub
commit 3ceef8186c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 124 additions and 8 deletions

View file

@ -3,7 +3,7 @@
let
inherit (lib) concatStrings foldl foldl' genAttrs literalExample maintainers
mapAttrsToList mkDefault mkEnableOption mkIf mkMerge mkOption
optional types;
optional types mkOptionDefault flip attrNames;
cfg = config.services.prometheus.exporters;
@ -32,6 +32,7 @@ let
"fritzbox"
"json"
"keylight"
"knot"
"lnd"
"mail"
"mikrotik"
@ -65,7 +66,7 @@ let
mkExporterOpts = ({ name, port }: {
enable = mkEnableOption "the prometheus ${name} exporter";
port = mkOption {
type = types.int;
type = types.port;
default = port;
description = ''
Port to listen on.
@ -93,9 +94,8 @@ let
'';
};
firewallFilter = mkOption {
type = types.str;
default = "-p tcp -m tcp --dport ${toString cfg.${name}.port}";
defaultText = "-p tcp -m tcp --dport ${toString port}";
type = types.nullOr types.str;
default = null;
example = literalExample ''
"-i eth0 -p tcp -m tcp --dport ${toString port}"
'';
@ -123,12 +123,14 @@ let
mkSubModule = { name, port, extraOpts, imports }: {
${name} = mkOption {
type = types.submodule {
type = types.submodule [{
inherit imports;
options = (mkExporterOpts {
inherit name port;
} // extraOpts);
};
} ({ config, ... }: mkIf config.openFirewall {
firewallFilter = mkOptionDefault "-p tcp -m tcp --dport ${toString config.port}";
})];
internal = true;
default = {};
};
@ -233,7 +235,13 @@ in
Please specify either 'services.prometheus.exporters.sql.configuration' or
'services.prometheus.exporters.sql.configFile'
'';
} ];
} ] ++ (flip map (attrNames cfg) (exporter: {
assertion = cfg.${exporter}.firewallFilter != null -> cfg.${exporter}.openFirewall;
message = ''
The `firewallFilter'-option of exporter ${exporter} doesn't have any effect unless
`openFirewall' is set to `true'!
'';
}));
}] ++ [(mkIf config.services.minio.enable {
services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;

View file

@ -0,0 +1,50 @@
{ config, lib, pkgs, options }:
with lib;
let
cfg = config.services.prometheus.exporters.knot;
in {
port = 9433;
extraOpts = {
knotLibraryPath = mkOption {
type = types.str;
default = "${pkgs.knot-dns.out}/lib/libknot.so";
defaultText = "\${pkgs.knot-dns}/lib/libknot.so";
description = ''
Path to the library of <package>knot-dns</package>.
'';
};
knotSocketPath = mkOption {
type = types.str;
default = "/run/knot/knot.sock";
description = ''
Socket path of <citerefentry><refentrytitle>knotd</refentrytitle>
<manvolnum>8</manvolnum></citerefentry>.
'';
};
knotSocketTimeout = mkOption {
type = types.int;
default = 2000;
description = ''
Timeout in seconds.
'';
};
};
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-knot-exporter}/bin/knot_exporter \
--web-listen-addr ${cfg.listenAddress} \
--web-listen-port ${toString cfg.port} \
--knot-library-path ${cfg.knotLibraryPath} \
--knot-socket-path ${cfg.knotSocketPath} \
--knot-socket-timeout ${toString cfg.knotSocketTimeout} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
SupplementaryGroups = [ "knot" ];
};
};
}

View file

@ -263,6 +263,24 @@ let
'';
};
knot = {
exporterConfig = {
enable = true;
};
metricProvider = {
services.knot = {
enable = true;
extraArgs = [ "-v" ];
};
};
exporterTest = ''
wait_for_unit("knot.service")
wait_for_unit("prometheus-knot-exporter.service")
wait_for_open_port(9433)
succeed("curl -sSf 'localhost:9433' | grep -q 'knot_server_zone_count 0.0'")
'';
};
keylight = {
# A hardware device is required to properly test this exporter, so just
# perform a couple of basic sanity checks that the exporter is running

View file

@ -0,0 +1,39 @@
{ stdenv, fetchFromGitHub, lib, python3, nixosTests }:
stdenv.mkDerivation rec {
pname = "knot-exporter";
version = "unstable-2020-01-30";
src = fetchFromGitHub {
owner = "ghedo";
repo = "knot_exporter";
rev = "21dd46b401e0c1aea0b173e19462cdf89e1f444e";
sha256 = "sha256-4au4lpaq3jcqC2JXdCcf8h+YN8Nmm4eE0kZwA+1rWlc=";
};
dontBuild = true;
nativeBuildInputs = [ python3.pkgs.wrapPython ];
buildInputs = [ python3 ];
installPhase = ''
runHook preInstall
install -Dm0755 knot_exporter $out/bin/knot_exporter
patchShebangs $out/bin
buildPythonPath ${python3.pkgs.prometheus_client}
patchPythonScript $out/bin/knot_exporter
runHook postInstall
'';
passthru.tests = { inherit (nixosTests.prometheus-exporters) knot; };
meta = with lib; {
homepage = "https://github.com/ghedo/knot_exporter";
description = " Prometheus exporter for Knot DNS";
license = licenses.gpl3Only;
maintainers = with maintainers; [ ma27 ];
platforms = platforms.linux;
};
}

View file

@ -18596,6 +18596,7 @@ in
prometheus-haproxy-exporter = callPackage ../servers/monitoring/prometheus/haproxy-exporter.nix { };
prometheus-json-exporter = callPackage ../servers/monitoring/prometheus/json-exporter.nix { };
prometheus-keylight-exporter = callPackage ../servers/monitoring/prometheus/keylight-exporter.nix { };
prometheus-knot-exporter = callPackage ../servers/monitoring/prometheus/knot-exporter.nix { };
prometheus-lnd-exporter = callPackage ../servers/monitoring/prometheus/lnd-exporter.nix { };
prometheus-mail-exporter = callPackage ../servers/monitoring/prometheus/mail-exporter.nix { };
prometheus-mesos-exporter = callPackage ../servers/monitoring/prometheus/mesos-exporter.nix { };