1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.collectd;
11 inherit (lib)
12 mkOption
13 mkEnableOption
14 types
15 optionalString
16 concatStringsSep
17 escapeShellArg
18 ;
19in
20{
21 port = 9103;
22 extraOpts = {
23 collectdBinary = {
24 enable = mkEnableOption "collectd binary protocol receiver";
25
26 authFile = mkOption {
27 default = null;
28 type = types.nullOr types.path;
29 description = "File mapping user names to pre-shared keys (passwords).";
30 };
31
32 port = mkOption {
33 type = types.port;
34 default = 25826;
35 description = "Network address on which to accept collectd binary network packets.";
36 };
37
38 listenAddress = mkOption {
39 type = types.str;
40 default = "0.0.0.0";
41 description = ''
42 Address to listen on for binary network packets.
43 '';
44 };
45
46 securityLevel = mkOption {
47 type = types.enum [
48 "None"
49 "Sign"
50 "Encrypt"
51 ];
52 default = "None";
53 description = ''
54 Minimum required security level for accepted packets.
55 '';
56 };
57 };
58
59 logFormat = mkOption {
60 type = types.enum [
61 "logfmt"
62 "json"
63 ];
64 default = "logfmt";
65 example = "json";
66 description = ''
67 Set the log format.
68 '';
69 };
70
71 logLevel = mkOption {
72 type = types.enum [
73 "debug"
74 "info"
75 "warn"
76 "error"
77 "fatal"
78 ];
79 default = "info";
80 description = ''
81 Only log messages with the given severity or above.
82 '';
83 };
84 };
85 serviceOpts =
86 let
87 collectSettingsArgs = optionalString (cfg.collectdBinary.enable) ''
88 --collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
89 --collectd.security-level ${cfg.collectdBinary.securityLevel} \
90 '';
91 in
92 {
93 serviceConfig = {
94 ExecStart = ''
95 ${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
96 --log.format ${escapeShellArg cfg.logFormat} \
97 --log.level ${cfg.logLevel} \
98 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
99 ${collectSettingsArgs} \
100 ${concatStringsSep " \\\n " cfg.extraFlags}
101 '';
102 };
103 };
104}