1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.dovecot; 7in 8{ 9 port = 9166; 10 extraOpts = { 11 telemetryPath = mkOption { 12 type = types.str; 13 default = "/metrics"; 14 description = lib.mdDoc '' 15 Path under which to expose metrics. 16 ''; 17 }; 18 socketPath = mkOption { 19 type = types.path; 20 default = "/var/run/dovecot/stats"; 21 example = "/var/run/dovecot2/old-stats"; 22 description = lib.mdDoc '' 23 Path under which the stats socket is placed. 24 The user/group under which the exporter runs, 25 should be able to access the socket in order 26 to scrape the metrics successfully. 27 28 Please keep in mind that the stats module has changed in 29 [Dovecot 2.3+](https://wiki2.dovecot.org/Upgrading/2.3) which 30 is not [compatible with this exporter](https://github.com/kumina/dovecot_exporter/issues/8). 31 32 The following extra config has to be passed to Dovecot to ensure that recent versions 33 work with this exporter: 34 ``` 35 { 36 services.prometheus.exporters.dovecot.enable = true; 37 services.prometheus.exporters.dovecot.socketPath = "/var/run/dovecot2/old-stats"; 38 services.dovecot2.mailPlugins.globally.enable = [ "old_stats" ]; 39 services.dovecot2.extraConfig = ''' 40 service old-stats { 41 unix_listener old-stats { 42 user = dovecot-exporter 43 group = dovecot-exporter 44 mode = 0660 45 } 46 fifo_listener old-stats-mail { 47 mode = 0660 48 user = dovecot 49 group = dovecot 50 } 51 fifo_listener old-stats-user { 52 mode = 0660 53 user = dovecot 54 group = dovecot 55 } 56 } 57 plugin { 58 old_stats_refresh = 30 secs 59 old_stats_track_cmds = yes 60 } 61 '''; 62 } 63 ``` 64 ''; 65 }; 66 scopes = mkOption { 67 type = types.listOf types.str; 68 default = [ "user" ]; 69 example = [ "user" "global" ]; 70 description = lib.mdDoc '' 71 Stats scopes to query. 72 ''; 73 }; 74 }; 75 serviceOpts = { 76 serviceConfig = { 77 DynamicUser = false; 78 ExecStart = '' 79 ${pkgs.prometheus-dovecot-exporter}/bin/dovecot_exporter \ 80 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 81 --web.telemetry-path ${cfg.telemetryPath} \ 82 --dovecot.socket-path ${escapeShellArg cfg.socketPath} \ 83 --dovecot.scopes ${concatStringsSep "," cfg.scopes} \ 84 ${concatStringsSep " \\\n " cfg.extraFlags} 85 ''; 86 RestrictAddressFamilies = [ 87 # Need AF_UNIX to collect data 88 "AF_UNIX" 89 ]; 90 }; 91 }; 92}