@@ -10,64 +10,55 @@ let
1010 echo '${builtins.toJSON conf}' | ${pkgs.buildPackages.jq}/bin/jq '.' > $out
1111 '';
1212
13− generateConfig = extraLabels: (map (path: {
14− name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}";
15− path = "$.${path}";
16− labels = extraLabels;
17− }) [
18− "actions.'add header'"
19− "actions.'no action'"
20− "actions.'rewrite subject'"
21− "actions.'soft reject'"
22− "actions.greylist"
23− "actions.reject"
24− "bytes_allocated"
25− "chunks_allocated"
26− "chunks_freed"
27− "chunks_oversized"
28− "connections"
29− "control_connections"
30− "ham_count"
31− "learned"
32− "pools_allocated"
33− "pools_freed"
34− "read_only"
35− "scanned"
36− "shared_chunks_allocated"
37− "spam_count"
38− "total_learns"
39− ]) ++ [{
40− name = "rspamd_statfiles";
41− type = "object";
42− path = "$.statfiles[*]";
43− labels = recursiveUpdate {
44− symbol = "$.symbol";
45− type = "$.type";
46− } extraLabels;
47− values = {
48− revision = "$.revision";
49− size = "$.size";
50− total = "$.total";
51− used = "$.used";
52− languages = "$.languages";
53− users = "$.users";
54− };
55− }];
13+ generateConfig = extraLabels: {
14+ metrics = (map (path: {
15+ name = "rspamd_${replaceStrings [ "." " " ] [ "_" "_" ] path}";
16+ path = "$.${path}";
17+ labels = extraLabels;
18+ }) [
19+ "actions.'add header'"
20+ "actions.'no action'"
21+ "actions.'rewrite subject'"
22+ "actions.'soft reject'"
23+ "actions.greylist"
24+ "actions.reject"
25+ "bytes_allocated"
26+ "chunks_allocated"
27+ "chunks_freed"
28+ "chunks_oversized"
29+ "connections"
30+ "control_connections"
31+ "ham_count"
32+ "learned"
33+ "pools_allocated"
34+ "pools_freed"
35+ "read_only"
36+ "scanned"
37+ "shared_chunks_allocated"
38+ "spam_count"
39+ "total_learns"
40+ ]) ++ [{
41+ name = "rspamd_statfiles";
42+ type = "object";
43+ path = "$.statfiles[*]";
44+ labels = recursiveUpdate {
45+ symbol = "$.symbol";
46+ type = "$.type";
47+ } extraLabels;
48+ values = {
49+ revision = "$.revision";
50+ size = "$.size";
51+ total = "$.total";
52+ used = "$.used";
53+ languages = "$.languages";
54+ users = "$.users";
55+ };
56+ }];
57+ };
5658in
5759{
5860 port = 7980;
5961 extraOpts = {
60− listenAddress = {}; # not used
61−
62− url = mkOption {
63− type = types.str;
64− description = ''
65− URL to the rspamd metrics endpoint.
66− Defaults to http://localhost:11334/stat when
67− <option>services.rspamd.enable</option> is true.
68− '';
69− };
70−
7162 extraLabels = mkOption {
7263 type = types.attrsOf types.str;
7364 default = {
@@ -84,9 +75,25 @@ in
8475 };
8576 };
8677 serviceOpts.serviceConfig.ExecStart = ''
87− ${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
88− --port ${toString cfg.port} \
89− ${cfg.url} ${prettyJSON (generateConfig cfg.extraLabels)} \
78+ ${pkgs.prometheus-json-exporter}/bin/json_exporter \
79+ --config.file ${prettyJSON (generateConfig cfg.extraLabels)} \
80+ --web.listen-address "${cfg.listenAddress}:${toString cfg.port}" \
9081 ${concatStringsSep " \\\n " cfg.extraFlags}
9182 '';
83+
84+ imports = [
85+ (mkRemovedOptionModule [ "url" ] ''
86+ This option was removed. The URL of the rspamd metrics endpoint
87+ must now be provided to the exporter by prometheus via the url
88+ parameter `target'.
89+
90+ In prometheus a scrape URL would look like this:
91+
92+ http://some.rspamd-exporter.host:7980/probe?target=http://some.rspamd.host:11334/stat
93+
94+ For more information, take a look at the official documentation
95+ (https://github.com/prometheus-community/json_exporter) of the json_exporter.
96+ '')
97+ ({ options.warnings = options.warnings; options.assertions = options.assertions; })
98+ ];
9299}