3
0
Fork 0
forked from mirrors/nixpkgs

nixos/rspamd-exporter: fix metrics

In 0.3.0 of the json-exporter[1] it was switched to a different jsonpath
library which made some changes - especially for spaces in keys -
necessary. Also I decided to remove the pretty-printed JSON as this
would interfere with the bash quoting too much. If one needs
pretty-printed output, they can still pipe the output to `jq`.

[1] https://github.com/prometheus-community/json_exporter/releases/tag/v0.3.0
This commit is contained in:
Maximilian Bosch 2021-06-03 12:37:48 +02:00
parent b6e6f1dddd
commit 976d668e5c
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E

View file

@ -5,21 +5,19 @@ with lib;
let let
cfg = config.services.prometheus.exporters.rspamd; cfg = config.services.prometheus.exporters.rspamd;
prettyJSON = conf: mkFile = conf:
pkgs.runCommand "rspamd-exporter-config.yml" { } '' pkgs.writeText "rspamd-exporter-config.yml" (builtins.toJSON conf);
echo '${builtins.toJSON conf}' | ${pkgs.buildPackages.jq}/bin/jq '.' > $out
'';
generateConfig = extraLabels: { generateConfig = extraLabels: {
metrics = (map (path: { metrics = (map (path: {
name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}"; name = "rspamd_${replaceStrings [ "[" "." " " "]" "\\" "'" ] [ "_" "_" "_" "" "" "" ] path}";
path = "{ .${path} }"; path = "{ .${path} }";
labels = extraLabels; labels = extraLabels;
}) [ }) [
"actions.'add header'" "actions['add\\ header']"
"actions.'no action'" "actions['no\\ action']"
"actions.'rewrite subject'" "actions['rewrite\\ subject']"
"actions.'soft reject'" "actions['soft\\ reject']"
"actions.greylist" "actions.greylist"
"actions.reject" "actions.reject"
"bytes_allocated" "bytes_allocated"
@ -40,18 +38,18 @@ let
]) ++ [{ ]) ++ [{
name = "rspamd_statfiles"; name = "rspamd_statfiles";
type = "object"; type = "object";
path = "$.statfiles[*]"; path = "{.statfiles[*]}";
labels = recursiveUpdate { labels = recursiveUpdate {
symbol = "$.symbol"; symbol = "{.symbol}";
type = "$.type"; type = "{.type}";
} extraLabels; } extraLabels;
values = { values = {
revision = "$.revision"; revision = "{.revision}";
size = "$.size"; size = "{.size}";
total = "$.total"; total = "{.total}";
used = "$.used"; used = "{.used}";
languages = "$.languages"; languages = "{.languages}";
users = "$.users"; users = "{.users}";
}; };
}]; }];
}; };
@ -76,7 +74,7 @@ in
}; };
serviceOpts.serviceConfig.ExecStart = '' serviceOpts.serviceConfig.ExecStart = ''
${pkgs.prometheus-json-exporter}/bin/json_exporter \ ${pkgs.prometheus-json-exporter}/bin/json_exporter \
--config.file ${prettyJSON (generateConfig cfg.extraLabels)} \ --config.file ${mkFile (generateConfig cfg.extraLabels)} \
--web.listen-address "${cfg.listenAddress}:${toString cfg.port}" \ --web.listen-address "${cfg.listenAddress}:${toString cfg.port}" \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';