1{ config, lib, pkgs }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.collectd;
7in
8{
9 port = 9103;
10 extraOpts = {
11 collectdBinary = {
12 enable = mkEnableOption "collectd binary protocol receiver";
13
14 authFile = mkOption {
15 default = null;
16 type = types.nullOr types.path;
17 description = "File mapping user names to pre-shared keys (passwords).";
18 };
19
20 port = mkOption {
21 type = types.int;
22 default = 25826;
23 description = ''Network address on which to accept collectd binary network packets.'';
24 };
25
26 listenAddress = mkOption {
27 type = types.str;
28 default = "0.0.0.0";
29 description = ''
30 Address to listen on for binary network packets.
31 '';
32 };
33
34 securityLevel = mkOption {
35 type = types.enum ["None" "Sign" "Encrypt"];
36 default = "None";
37 description = ''
38 Minimum required security level for accepted packets.
39 '';
40 };
41 };
42
43 logFormat = mkOption {
44 type = types.str;
45 default = "logger:stderr";
46 example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true";
47 description = ''
48 Set the log target and format.
49 '';
50 };
51
52 logLevel = mkOption {
53 type = types.enum ["debug" "info" "warn" "error" "fatal"];
54 default = "info";
55 description = ''
56 Only log messages with the given severity or above.
57 '';
58 };
59 };
60 serviceOpts = let
61 collectSettingsArgs = if (cfg.collectdBinary.enable) then ''
62 -collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
63 -collectd.security-level ${cfg.collectdBinary.securityLevel} \
64 '' else "";
65 in {
66 serviceConfig = {
67 DynamicUser = true;
68 ExecStart = ''
69 ${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
70 -log.format ${cfg.logFormat} \
71 -log.level ${cfg.logLevel} \
72 -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
73 ${collectSettingsArgs} \
74 ${concatStringsSep " \\\n " cfg.extraFlags}
75 '';
76 };
77 };
78}