Unverified Commit 8af66431 authored by Nick Groenen's avatar Nick Groenen
Browse files

Make scopes configurable

This allows a user to select which sets of dovecot stats he or she is
interested in.

The default has been deliberately changed mainly because it makes the
description/format more obvious, but also because gathering global stats
in addition to user stats generally makes sense.

Original credit goes to @jap
(https://github.com/kumina/dovecot_exporter/pull/4)
parent a0a7bdde
......@@ -28,14 +28,11 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)
var (
dovecotUpDesc = prometheus.NewDesc(
prometheus.BuildFQName("dovecot", "", "up"),
"Whether scraping Dovecot's metrics was successful.",
[]string{"scope"},
nil)
dovecotScopes = [...]string{"user"}
)
var dovecotUpDesc = prometheus.NewDesc(
prometheus.BuildFQName("dovecot", "", "up"),
"Whether scraping Dovecot's metrics was successful.",
[]string{"scope"},
nil)
// Converts the output of Dovecot's EXPORT command to metrics.
func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error {
......@@ -101,11 +98,13 @@ func CollectFromSocket(path string, scope string, ch chan<- prometheus.Metric) e
}
type DovecotExporter struct {
scopes []string
socketPath string
}
func NewDovecotExporter(socketPath string) *DovecotExporter {
func NewDovecotExporter(socketPath string, scopes []string) *DovecotExporter {
return &DovecotExporter{
scopes: scopes,
socketPath: socketPath,
}
}
......@@ -115,7 +114,7 @@ func (e *DovecotExporter) Describe(ch chan<- *prometheus.Desc) {
}
func (e *DovecotExporter) Collect(ch chan<- prometheus.Metric) {
for _, scope := range dovecotScopes {
for _, scope := range e.scopes {
err := CollectFromSocket(e.socketPath, scope, ch)
if err == nil {
ch <- prometheus.MustNewConstMetric(
......@@ -140,10 +139,11 @@ func main() {
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()
dovecotScopes = app.Flag("dovecot.scopes", "Stats scopes to query (comma separated)").Default("global,user").String()
)
kingpin.MustParse(app.Parse(os.Args[1:]))
exporter := NewDovecotExporter(*socketPath)
exporter := NewDovecotExporter(*socketPath, strings.Split(*dovecotScopes, ","))
prometheus.MustRegister(exporter)
http.Handle(*metricsPath, prometheus.Handler())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment