1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.postfix; 7in 8{ 9 port = 9154; 10 extraOpts = { 11 group = mkOption { 12 type = types.str; 13 description = '' 14 Group under which the postfix exporter shall be run. 15 It should match the group that is allowed to access the 16 <literal>showq</literal> socket in the <literal>queue/public/</literal> directory. 17 Defaults to <literal>services.postfix.setgidGroup</literal> when postfix is enabled. 18 ''; 19 }; 20 telemetryPath = mkOption { 21 type = types.str; 22 default = "/metrics"; 23 description = '' 24 Path under which to expose metrics. 25 ''; 26 }; 27 logfilePath = mkOption { 28 type = types.path; 29 default = "/var/log/postfix_exporter_input.log"; 30 example = "/var/log/mail.log"; 31 description = '' 32 Path where Postfix writes log entries. 33 This file will be truncated by this exporter! 34 ''; 35 }; 36 showqPath = mkOption { 37 type = types.path; 38 default = "/var/lib/postfix/queue/public/showq"; 39 example = "/var/spool/postfix/public/showq"; 40 description = '' 41 Path where Postfix places its showq socket. 42 ''; 43 }; 44 systemd = { 45 enable = mkOption { 46 type = types.bool; 47 default = true; 48 description = '' 49 Whether to enable reading metrics from the systemd journal instead of from a logfile 50 ''; 51 }; 52 unit = mkOption { 53 type = types.str; 54 default = "postfix.service"; 55 description = '' 56 Name of the postfix systemd unit. 57 ''; 58 }; 59 slice = mkOption { 60 type = types.nullOr types.str; 61 default = null; 62 description = '' 63 Name of the postfix systemd slice. 64 This overrides the <option>systemd.unit</option>. 65 ''; 66 }; 67 journalPath = mkOption { 68 type = types.nullOr types.path; 69 default = null; 70 description = '' 71 Path to the systemd journal. 72 ''; 73 }; 74 }; 75 }; 76 serviceOpts = { 77 serviceConfig = { 78 DynamicUser = false; 79 ExecStart = '' 80 ${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \ 81 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 82 --web.telemetry-path ${cfg.telemetryPath} \ 83 --postfix.showq_path ${escapeShellArg cfg.showqPath} \ 84 ${concatStringsSep " \\\n " (cfg.extraFlags 85 ++ optional cfg.systemd.enable "--systemd.enable" 86 ++ optional cfg.systemd.enable (if cfg.systemd.slice != null 87 then "--systemd.slice ${cfg.systemd.slice}" 88 else "--systemd.unit ${cfg.systemd.unit}") 89 ++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null)) 90 "--systemd.journal_path ${escapeShellArg cfg.systemd.journalPath}" 91 ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${escapeShellArg cfg.logfilePath}")} 92 ''; 93 }; 94 }; 95}