summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters/dovecot.nix
blob: 472652fe8a7a9f39cdadd0f7a59e0a26d426df32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{ config, lib, pkgs, options }:

with lib;

let
  cfg = config.services.prometheus.exporters.dovecot;
in
{
  port = 9166;
  extraOpts = {
    telemetryPath = mkOption {
      type = types.str;
      default = "/metrics";
      description = ''
        Path under which to expose metrics.
      '';
    };
    socketPath = mkOption {
      type = types.path;
      default = "/var/run/dovecot/stats";
      example = "/var/run/dovecot2/old-stats";
      description = ''
        Path under which the stats socket is placed.
        The user/group under which the exporter runs,
        should be able to access the socket in order
        to scrape the metrics successfully.

        Please keep in mind that the stats module has changed in
        <link xlink:href="https://wiki2.dovecot.org/Upgrading/2.3">Dovecot 2.3+</link> which
        is not <link xlink:href="https://github.com/kumina/dovecot_exporter/issues/8">compatible with this exporter</link>.

        The following extra config has to be passed to Dovecot to ensure that recent versions
        work with this exporter:
        <programlisting>
        {
          <xref linkend="opt-services.prometheus.exporters.dovecot.enable" /> = true;
          <xref linkend="opt-services.prometheus.exporters.dovecot.socketPath" /> = "/var/run/dovecot2/old-stats";
          <xref linkend="opt-services.dovecot2.mailPlugins.globally.enable" /> = [ "old_stats" ];
          <xref linkend="opt-services.dovecot2.extraConfig" /> = '''
            service old-stats {
              unix_listener old-stats {
                user = dovecot-exporter
                group = dovecot-exporter
                mode = 0660
              }
              fifo_listener old-stats-mail {
                mode = 0660
                user = dovecot
                group = dovecot
              }
              fifo_listener old-stats-user {
                mode = 0660
                user = dovecot
                group = dovecot
              }
            }
            plugin {
              old_stats_refresh = 30 secs
              old_stats_track_cmds = yes
            }
          ''';
        }
        </programlisting>
      '';
    };
    scopes = mkOption {
      type = types.listOf types.str;
      default = [ "user" ];
      example = [ "user" "global" ];
      description = ''
        Stats scopes to query.
      '';
    };
  };
  serviceOpts = {
    serviceConfig = {
      DynamicUser = false;
      ExecStart = ''
        ${pkgs.prometheus-dovecot-exporter}/bin/dovecot_exporter \
          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
          --web.telemetry-path ${cfg.telemetryPath} \
          --dovecot.socket-path ${escapeShellArg cfg.socketPath} \
          --dovecot.scopes ${concatStringsSep "," cfg.scopes} \
          ${concatStringsSep " \\\n  " cfg.extraFlags}
      '';
    };
  };
}