1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.collectd; 7in 8{ 9 port = 9103; 10 extraOpts = { 11 collectdBinary = { 12 enable = mkEnableOption (lib.mdDoc "collectd binary protocol receiver"); 13 14 authFile = mkOption { 15 default = null; 16 type = types.nullOr types.path; 17 description = lib.mdDoc "File mapping user names to pre-shared keys (passwords)."; 18 }; 19 20 port = mkOption { 21 type = types.port; 22 default = 25826; 23 description = lib.mdDoc "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 = lib.mdDoc '' 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 = lib.mdDoc '' 38 Minimum required security level for accepted packets. 39 ''; 40 }; 41 }; 42 43 logFormat = mkOption { 44 type = types.enum [ "logfmt" "json" ]; 45 default = "logfmt"; 46 example = "json"; 47 description = lib.mdDoc '' 48 Set the log format. 49 ''; 50 }; 51 52 logLevel = mkOption { 53 type = types.enum ["debug" "info" "warn" "error" "fatal"]; 54 default = "info"; 55 description = lib.mdDoc '' 56 Only log messages with the given severity or above. 57 ''; 58 }; 59 }; 60 serviceOpts = let 61 collectSettingsArgs = optionalString (cfg.collectdBinary.enable) '' 62 --collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \ 63 --collectd.security-level ${cfg.collectdBinary.securityLevel} \ 64 ''; 65 in { 66 serviceConfig = { 67 ExecStart = '' 68 ${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \ 69 --log.format ${escapeShellArg cfg.logFormat} \ 70 --log.level ${cfg.logLevel} \ 71 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 72 ${collectSettingsArgs} \ 73 ${concatStringsSep " \\\n " cfg.extraFlags} 74 ''; 75 }; 76 }; 77}