···
+
{ config, pkgs, lib, ... }:
+
cfg = config.services.prometheus.collectdExporter;
+
collectSettingsArgs = if (cfg.collectdBinary.enable) then ''
+
-collectd.listen-address ${optionalString (cfg.collectdBinary.listenAddress != null) cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
+
-collectd.security-level ${cfg.collectdBinary.securityLevel} \
+
services.prometheus.collectdExporter = {
+
enable = mkEnableOption "prometheus collectd exporter";
+
This is used for scraping as well as the to receive collectd data via the write_http plugin.
+
listenAddress = mkOption {
+
type = types.nullOr types.str;
+
Address to listen on for web interface, telemetry and collectd JSON data.
+
enable = mkEnableOption "collectd binary protocol receiver";
+
type = types.nullOr types.path;
+
description = "File mapping user names to pre-shared keys (passwords).";
+
description = ''Network address on which to accept collectd binary network packets.'';
+
listenAddress = mkOption {
+
type = types.nullOr types.str;
+
Address to listen on for binary network packets.
+
securityLevel = mkOption {
+
type = types.enum ["None" "Sign" "Encrypt"];
+
Minimum required security level for accepted packets.
+
extraFlags = mkOption {
+
type = types.listOf types.str;
+
Extra commandline options when launching the collectd exporter.
+
default = "logger:stderr";
+
example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true";
+
Set the log target and format.
+
type = types.enum ["debug" "info" "warn" "error" "fatal"];
+
Only log messages with the given severity or above.
+
openFirewall = mkOption {
+
Open port in firewall for incoming connections.
+
config = mkIf cfg.enable {
+
networking.firewall.allowedTCPPorts = (optional cfg.openFirewall cfg.port) ++
+
(optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port);
+
systemd.services.prometheus-collectd-exporter = {
+
description = "Prometheus exporter for Collectd metrics";
+
unitConfig.Documentation = "https://github.com/prometheus/collectd_exporter";
+
wantedBy = [ "multi-user.target" ];
+
WorkingDirectory = /tmp;
+
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
+
-log.format ${cfg.logFormat} \
+
-log.level ${cfg.logLevel} \
+
-web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port} \
+
${collectSettingsArgs} \
+
${concatStringsSep " " cfg.extraFlags}