···
1
+
{ config, pkgs, lib, ... }:
6
+
cfg = config.services.prometheus.collectdExporter;
8
+
collectSettingsArgs = if (cfg.collectdBinary.enable) then ''
9
+
-collectd.listen-address ${optionalString (cfg.collectdBinary.listenAddress != null) cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
10
+
-collectd.security-level ${cfg.collectdBinary.securityLevel} \
15
+
services.prometheus.collectdExporter = {
16
+
enable = mkEnableOption "prometheus collectd exporter";
23
+
This is used for scraping as well as the to receive collectd data via the write_http plugin.
27
+
listenAddress = mkOption {
28
+
type = types.nullOr types.str;
30
+
example = "0.0.0.0";
32
+
Address to listen on for web interface, telemetry and collectd JSON data.
37
+
enable = mkEnableOption "collectd binary protocol receiver";
39
+
authFile = mkOption {
41
+
type = types.nullOr types.path;
42
+
description = "File mapping user names to pre-shared keys (passwords).";
48
+
description = ''Network address on which to accept collectd binary network packets.'';
51
+
listenAddress = mkOption {
52
+
type = types.nullOr types.str;
54
+
example = "0.0.0.0";
56
+
Address to listen on for binary network packets.
60
+
securityLevel = mkOption {
61
+
type = types.enum ["None" "Sign" "Encrypt"];
64
+
Minimum required security level for accepted packets.
69
+
extraFlags = mkOption {
70
+
type = types.listOf types.str;
73
+
Extra commandline options when launching the collectd exporter.
77
+
logFormat = mkOption {
79
+
default = "logger:stderr";
80
+
example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true";
82
+
Set the log target and format.
86
+
logLevel = mkOption {
87
+
type = types.enum ["debug" "info" "warn" "error" "fatal"];
90
+
Only log messages with the given severity or above.
94
+
openFirewall = mkOption {
98
+
Open port in firewall for incoming connections.
104
+
config = mkIf cfg.enable {
105
+
networking.firewall.allowedTCPPorts = (optional cfg.openFirewall cfg.port) ++
106
+
(optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port);
108
+
systemd.services.prometheus-collectd-exporter = {
109
+
description = "Prometheus exporter for Collectd metrics";
110
+
unitConfig.Documentation = "https://github.com/prometheus/collectd_exporter";
111
+
wantedBy = [ "multi-user.target" ];
113
+
DynamicUser = true;
114
+
Restart = "always";
116
+
WorkingDirectory = /tmp;
118
+
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
119
+
-log.format ${cfg.logFormat} \
120
+
-log.level ${cfg.logLevel} \
121
+
-web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port} \
122
+
${collectSettingsArgs} \
123
+
${concatStringsSep " " cfg.extraFlags}