From 752e7bc3dfdd4331c16d22bd561ccca6ddbd7061 Mon Sep 17 00:00:00 2001
From: godog <godog@autistici.org>
Date: Sat, 21 Mar 2020 19:27:54 +0100
Subject: [PATCH] Use dedicated stats listener for old_stats

By default Dovecot old_stats will create the socket owned by root (non
overridable from the configuration). Thus switch to a dedicated socket
and provide an example configuration.
---
 README.md                       | 14 +++++++++++++-
 debian/dovecot-exporter.default |  2 +-
 dovecot_exporter.go             |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 934407b..cc7d638 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,21 @@ This repository provides a `dovecot_exporter` utility that can be used
 to scrape statistics from Dovecot and export them as Prometheus metrics.
 It extracts the metrics that are exposed by
 [Dovecot's stats module](https://wiki2.dovecot.org/Statistics/Old) by
-connecting to UNIX socket `/var/run/dovecot/stats` and serves them as
+connecting to UNIX socket `/var/run/dovecot/stats-exporter` and serves them as
 Prometheus metrics over TCP port 9166.
 
+The socket will be created with the appropriate permissions by this Dovecot
+configuration:
+
+```
+service stats {
+  fifo_listener stats-exporter {
+    user = dovecot
+    mode = 0600
+  }
+}
+```
+
 A list of command line flags supported by this utility can be obtained
 by looking at this exporter's `main()` function. Do note that all
 command line flags require two leading dashes (e.g.,
diff --git a/debian/dovecot-exporter.default b/debian/dovecot-exporter.default
index 6e6a481..fca076a 100644
--- a/debian/dovecot-exporter.default
+++ b/debian/dovecot-exporter.default
@@ -1,3 +1,3 @@
 ADDR=:9166
 SCOPES=global
-DOVECOT_SOCKET=/var/run/dovecot/old-stats
+DOVECOT_SOCKET=/var/run/dovecot/stats-exporter
diff --git a/dovecot_exporter.go b/dovecot_exporter.go
index 6f614cf..127211d 100644
--- a/dovecot_exporter.go
+++ b/dovecot_exporter.go
@@ -208,7 +208,7 @@ func main() {
 		app           = kingpin.New("dovecot_exporter", "Prometheus metrics exporter for Dovecot")
 		listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9166").String()
 		metricsPath   = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
-		socketPath    = app.Flag("dovecot.socket-path", "Path under which to expose metrics.").Default("/var/run/dovecot/stats").String()
+		socketPath    = app.Flag("dovecot.socket-path", "Path under which to expose metrics.").Default("/var/run/dovecot/stats-exporter").String()
 		dovecotScopes = app.Flag("dovecot.scopes", "Stats scopes to query (comma separated)").Default("user").String()
 	)
 	kingpin.MustParse(app.Parse(os.Args[1:]))
-- 
GitLab