1 { config, lib, pkgs, options, ... }:
4 cfg = config.services.prometheus.exporters.postfix;
20 Group under which the postfix exporter shall be run.
21 It should match the group that is allowed to access the
22 `showq` socket in the `queue/public/` directory.
23 Defaults to `services.postfix.setgidGroup` when postfix is enabled.
26 telemetryPath = mkOption {
30 Path under which to expose metrics.
33 logfilePath = mkOption {
35 default = "/var/log/postfix_exporter_input.log";
36 example = "/var/log/mail.log";
38 Path where Postfix writes log entries.
39 This file will be truncated by this exporter!
42 showqPath = mkOption {
44 default = "/var/lib/postfix/queue/public/showq";
45 example = "/var/spool/postfix/public/showq";
47 Path where Postfix places its showq socket.
55 Whether to enable reading metrics from the systemd journal instead of from a logfile
60 default = "postfix.service";
62 Name of the postfix systemd unit.
66 type = types.nullOr types.str;
69 Name of the postfix systemd slice.
70 This overrides the {option}`systemd.unit`.
73 journalPath = mkOption {
74 type = types.nullOr types.path;
77 Path to the systemd journal.
83 after = mkIf cfg.systemd.enable [ cfg.systemd.unit ];
86 # By default, each prometheus exporter only gets AF_INET & AF_INET6,
87 # but AF_UNIX is needed to read from the `showq`-socket.
88 RestrictAddressFamilies = [ "AF_UNIX" ];
89 SupplementaryGroups = mkIf cfg.systemd.enable [ "systemd-journal" ];
91 ${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
92 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
93 --web.telemetry-path ${cfg.telemetryPath} \
94 --postfix.showq_path ${escapeShellArg cfg.showqPath} \
95 ${concatStringsSep " \\\n " (cfg.extraFlags
96 ++ optional cfg.systemd.enable "--systemd.enable"
97 ++ optional cfg.systemd.enable (if cfg.systemd.slice != null
98 then "--systemd.slice ${cfg.systemd.slice}"
99 else "--systemd.unit ${cfg.systemd.unit}")
100 ++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null))
101 "--systemd.journal_path ${escapeShellArg cfg.systemd.journalPath}"
102 ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${escapeShellArg cfg.logfilePath}")}