Merge pull request #115185 from Ma27/knot-exporter
prometheus-knot-exporter: init at 2021-01-30; minor module improvements
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user