From acf7a9791770ef3c56ca32065cb80a75f9338c69 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Jan 2019 01:26:05 +0100 Subject: [PATCH 01/23] Use Go modules --- go.mod | 16 ++++++++++++++++ go.sum | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..24970d3 --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module github.com/kumina/postfix_exporter + +require ( + github.com/alecthomas/kingpin v2.2.6+incompatible + github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect + github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect + github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 + github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect + github.com/fsnotify/fsnotify v1.4.7 // indirect + github.com/hpcloud/tail v1.0.0 + github.com/prometheus/client_golang v0.9.2 + github.com/stretchr/testify v1.3.0 // indirect + golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 // indirect + gopkg.in/fsnotify.v1 v1.4.7 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..871a6e5 --- /dev/null +++ b/go.sum @@ -0,0 +1,44 @@ +github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI= +github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 h1:3jFq2xL4ZajGK4aZY8jz+DAF0FHjI51BXjjSwCzS1Dk= +github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= +github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8= +github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE= +github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 h1:3Nsfe5Xa1wTt01QxlAFIY5j9ycDtS+d7mhvI8ZY5bn0= +golang.org/x/sys v0.0.0-20190220154126-629670e5acc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= From 99db0017f82b23ce065dc98ab88da21a4f6d98d1 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Jan 2019 01:26:44 +0100 Subject: [PATCH 02/23] Update Dockerfile to use Go 1.11 with modules --- Dockerfile | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index bad4572..16f9a50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,23 @@ -FROM golang:1.8 -ADD . /go/src/github.com/kumina/postfix_exporter -WORKDIR /go/src/github.com/kumina/postfix_exporter +FROM golang:1.11 AS builder +WORKDIR /src + +# avoid downloading the dependencies on succesive builds RUN apt-get update -qq && apt-get install -qqy \ build-essential \ libsystemd-dev -RUN go get -v ./... -RUN go build + +COPY go.mod go.sum ./ +RUN go mod download +RUN go mod verify + +COPY . . + +# Force the go compiler to use modules +ENV GO111MODULE=on +RUN go build -o /bin/postfix_exporter FROM debian:latest EXPOSE 9154 WORKDIR / -COPY --from=0 /go/src/github.com/kumina/postfix_exporter/postfix_exporter . -ENTRYPOINT ["/postfix_exporter"] +COPY --from=builder /bin/postfix_exporter /bin/ +ENTRYPOINT ["/bin/postfix_exporter"] From 243cb7977972f5c9e48ef4994542390d2ecd317e Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Jan 2019 20:40:52 +0100 Subject: [PATCH 03/23] Reduce indentation --- postfix_exporter.go | 328 ++++++++++++++++++++++---------------------- 1 file changed, 167 insertions(+), 161 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 7fdd1a1..98460dd 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -130,37 +130,39 @@ func CollectTextualShowqFromReader(file io.Reader, ch chan<- prometheus.Metric) for scanner.Scan() { matches := messageLine.FindStringSubmatch(scanner.Text()) if matches != nil { - // Derive the name of the message queue. - queue := "other" - if matches[1] == "*" { - queue = "active" - } else if matches[1] == "!" { - queue = "hold" - } - - // Parse the message size. - size, err := strconv.ParseFloat(matches[2], 64) - if err != nil { - return err - } - - // Parse the message date. Unfortunately, the - // output contains no year number. Assume it - // applies to the last year for which the - // message date doesn't exceed time.Now(). - date, err := time.ParseInLocation("Mon Jan 2 15:04:05", - matches[3], location) - if err != nil { - return err - } - date = date.AddDate(now.Year(), 0, 0) - if date.After(now) { - date = date.AddDate(-1, 0, 0) - } - - sizeHistogram.WithLabelValues(queue).Observe(size) - ageHistogram.WithLabelValues(queue).Observe(now.Sub(date).Seconds()) + continue } + + // Derive the name of the message queue. + queue := "other" + if matches[1] == "*" { + queue = "active" + } else if matches[1] == "!" { + queue = "hold" + } + + // Parse the message size. + size, err := strconv.ParseFloat(matches[2], 64) + if err != nil { + return err + } + + // Parse the message date. Unfortunately, the + // output contains no year number. Assume it + // applies to the last year for which the + // message date doesn't exceed time.Now(). + date, err := time.ParseInLocation("Mon Jan 2 15:04:05", + matches[3], location) + if err != nil { + return err + } + date = date.AddDate(now.Year(), 0, 0) + if date.After(now) { + date = date.AddDate(-1, 0, 0) + } + + sizeHistogram.WithLabelValues(queue).Observe(size) + ageHistogram.WithLabelValues(queue).Observe(now.Sub(date).Seconds()) } sizeHistogram.Collect(ch) @@ -289,139 +291,143 @@ var ( // CollectFromLogline collects metrict from a Postfix log line. func (e *PostfixExporter) CollectFromLogline(line string) { // Strip off timestamp, hostname, etc. - if logMatches := logLine.FindStringSubmatch(line); logMatches != nil { - // Group patterns to check by Postfix service. - if logMatches[1] == "cleanup" { - if strings.Contains(logMatches[2], ": message-id=<") { - e.cleanupProcesses.Inc() - } else if strings.Contains(logMatches[2], ": reject: ") { - e.cleanupRejects.Inc() - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "lmtp" { - if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); lmtpMatches != nil { - pdelay, err := strconv.ParseFloat(lmtpMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert LMTP pdelay: %v", err) - } - e.lmtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(lmtpMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert LMTP adelay: %v", err) - } - e.lmtpDelays.WithLabelValues("queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(lmtpMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert LMTP adelay: %v", err) - } - e.lmtpDelays.WithLabelValues("connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(lmtpMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert LMTP xdelay: %v", err) - } - e.lmtpDelays.WithLabelValues("transmission").Observe(xdelay) - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "pipe" { - if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); pipeMatches != nil { - pdelay, err := strconv.ParseFloat(pipeMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert PIPE pdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(pipeMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert PIPE adelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(pipeMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert PIPE sdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(pipeMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert PIPE xdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "transmission").Observe(xdelay) - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "qmgr" { - if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(logMatches[2]); qmgrInsertMatches != nil { - size, err := strconv.ParseFloat(qmgrInsertMatches[1], 64) - if err != nil { - log.Printf("Couldn't convert QMGR size: %v", err) - } - e.qmgrInsertsSize.Observe(size) - nrcpt, err := strconv.ParseFloat(qmgrInsertMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert QMGR nrcpt: %v", err) - } - e.qmgrInsertsNrcpt.Observe(nrcpt) - } else if strings.HasSuffix(logMatches[2], ": removed") { - e.qmgrRemoves.Inc() - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "smtp" { - if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); smtpMatches != nil { - pdelay, err := strconv.ParseFloat(smtpMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert SMTP pdelay: %v", err) - } - e.smtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(smtpMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert SMTP adelay: %v", err) - } - e.smtpDelays.WithLabelValues("queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(smtpMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert SMTP sdelay: %v", err) - } - e.smtpDelays.WithLabelValues("connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(smtpMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert SMTP xdelay: %v", err) - } - e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) - } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(logMatches[2]); smtpTLSMatches != nil { - e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "smtpd" { - if strings.HasPrefix(logMatches[2], "connect from ") { - e.smtpdConnects.Inc() - } else if strings.HasPrefix(logMatches[2], "disconnect from ") { - e.smtpdDisconnects.Inc() - } else if smtpdFCrDNSErrorsLine.MatchString(logMatches[2]) { - e.smtpdFCrDNSErrors.Inc() - } else if smtpdLostConnectionMatches := smtpdLostConnectionLine.FindStringSubmatch(logMatches[2]); smtpdLostConnectionMatches != nil { - e.smtpdLostConnections.WithLabelValues(smtpdLostConnectionMatches[1]).Inc() - } else if smtpdProcessesSASLMatches := smtpdProcessesSASLLine.FindStringSubmatch(logMatches[2]); smtpdProcessesSASLMatches != nil { - e.smtpdProcesses.WithLabelValues(smtpdProcessesSASLMatches[1]).Inc() - } else if strings.Contains(logMatches[2], ": client=") { - e.smtpdProcesses.WithLabelValues("").Inc() - } else if smtpdRejectsMatches := smtpdRejectsLine.FindStringSubmatch(logMatches[2]); smtpdRejectsMatches != nil { - e.smtpdRejects.WithLabelValues(smtpdRejectsMatches[1]).Inc() - } else if smtpdSASLAuthenticationFailuresLine.MatchString(logMatches[2]) { - e.smtpdSASLAuthenticationFailures.Inc() - } else if smtpdTLSMatches := smtpdTLSLine.FindStringSubmatch(logMatches[2]); smtpdTLSMatches != nil { - e.smtpdTLSConnects.WithLabelValues(smtpdTLSMatches[1:]...).Inc() - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else { - // Unknown Postfix service. - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else { + logMatches := logLine.FindStringSubmatch(line) + + if logMatches == nil { // Unknown log entry format. e.unsupportedLogEntries.WithLabelValues("").Inc() + return + } + + // Group patterns to check by Postfix service. + switch logMatches[1] { + case "cleanup": + if strings.Contains(logMatches[2], ": message-id=<") { + e.cleanupProcesses.Inc() + } else if strings.Contains(logMatches[2], ": reject: ") { + e.cleanupRejects.Inc() + } else { + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + } + case "lmtp": + if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); lmtpMatches != nil { + pdelay, err := strconv.ParseFloat(lmtpMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert LMTP pdelay: %v", err) + } + e.lmtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) + adelay, err := strconv.ParseFloat(lmtpMatches[3], 64) + if err != nil { + log.Printf("Couldn't convert LMTP adelay: %v", err) + } + e.lmtpDelays.WithLabelValues("queue_manager").Observe(adelay) + sdelay, err := strconv.ParseFloat(lmtpMatches[4], 64) + if err != nil { + log.Printf("Couldn't convert LMTP adelay: %v", err) + } + e.lmtpDelays.WithLabelValues("connection_setup").Observe(sdelay) + xdelay, err := strconv.ParseFloat(lmtpMatches[5], 64) + if err != nil { + log.Printf("Couldn't convert LMTP xdelay: %v", err) + } + e.lmtpDelays.WithLabelValues("transmission").Observe(xdelay) + } else { + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + } + case "pipe": + if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); pipeMatches != nil { + pdelay, err := strconv.ParseFloat(pipeMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert PIPE pdelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "before_queue_manager").Observe(pdelay) + adelay, err := strconv.ParseFloat(pipeMatches[3], 64) + if err != nil { + log.Printf("Couldn't convert PIPE adelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "queue_manager").Observe(adelay) + sdelay, err := strconv.ParseFloat(pipeMatches[4], 64) + if err != nil { + log.Printf("Couldn't convert PIPE sdelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "connection_setup").Observe(sdelay) + xdelay, err := strconv.ParseFloat(pipeMatches[5], 64) + if err != nil { + log.Printf("Couldn't convert PIPE xdelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "transmission").Observe(xdelay) + } else { + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + } + case "qmgr": + if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(logMatches[2]); qmgrInsertMatches != nil { + size, err := strconv.ParseFloat(qmgrInsertMatches[1], 64) + if err != nil { + log.Printf("Couldn't convert QMGR size: %v", err) + } + e.qmgrInsertsSize.Observe(size) + nrcpt, err := strconv.ParseFloat(qmgrInsertMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert QMGR nrcpt: %v", err) + } + e.qmgrInsertsNrcpt.Observe(nrcpt) + } else if strings.HasSuffix(logMatches[2], ": removed") { + e.qmgrRemoves.Inc() + } else { + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + } + case "smtp": + if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); smtpMatches != nil { + pdelay, err := strconv.ParseFloat(smtpMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert SMTP pdelay: %v", err) + } + e.smtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) + adelay, err := strconv.ParseFloat(smtpMatches[3], 64) + if err != nil { + log.Printf("Couldn't convert SMTP adelay: %v", err) + } + e.smtpDelays.WithLabelValues("queue_manager").Observe(adelay) + sdelay, err := strconv.ParseFloat(smtpMatches[4], 64) + if err != nil { + log.Printf("Couldn't convert SMTP sdelay: %v", err) + } + e.smtpDelays.WithLabelValues("connection_setup").Observe(sdelay) + xdelay, err := strconv.ParseFloat(smtpMatches[5], 64) + if err != nil { + log.Printf("Couldn't convert SMTP xdelay: %v", err) + } + e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) + } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(logMatches[2]); smtpTLSMatches != nil { + e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() + } else { + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + } + case "smtpd": + if strings.HasPrefix(logMatches[2], "connect from ") { + e.smtpdConnects.Inc() + } else if strings.HasPrefix(logMatches[2], "disconnect from ") { + e.smtpdDisconnects.Inc() + } else if smtpdFCrDNSErrorsLine.MatchString(logMatches[2]) { + e.smtpdFCrDNSErrors.Inc() + } else if smtpdLostConnectionMatches := smtpdLostConnectionLine.FindStringSubmatch(logMatches[2]); smtpdLostConnectionMatches != nil { + e.smtpdLostConnections.WithLabelValues(smtpdLostConnectionMatches[1]).Inc() + } else if smtpdProcessesSASLMatches := smtpdProcessesSASLLine.FindStringSubmatch(logMatches[2]); smtpdProcessesSASLMatches != nil { + e.smtpdProcesses.WithLabelValues(smtpdProcessesSASLMatches[1]).Inc() + } else if strings.Contains(logMatches[2], ": client=") { + e.smtpdProcesses.WithLabelValues("").Inc() + } else if smtpdRejectsMatches := smtpdRejectsLine.FindStringSubmatch(logMatches[2]); smtpdRejectsMatches != nil { + e.smtpdRejects.WithLabelValues(smtpdRejectsMatches[1]).Inc() + } else if smtpdSASLAuthenticationFailuresLine.MatchString(logMatches[2]) { + e.smtpdSASLAuthenticationFailures.Inc() + } else if smtpdTLSMatches := smtpdTLSLine.FindStringSubmatch(logMatches[2]); smtpdTLSMatches != nil { + e.smtpdTLSConnects.WithLabelValues(smtpdTLSMatches[1:]...).Inc() + } else { + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + } + default: + // Unknown Postfix service. + e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() } } From 7072c5242f1b7244dfe094988a68c70f0aede2d5 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Jan 2019 21:13:37 +0100 Subject: [PATCH 04/23] Small refactoring --- postfix_exporter.go | 100 +++++++++++++------------------------------- 1 file changed, 30 insertions(+), 70 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 98460dd..5ec0e19 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -311,66 +311,26 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } case "lmtp": if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); lmtpMatches != nil { - pdelay, err := strconv.ParseFloat(lmtpMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert LMTP pdelay: %v", err) - } - e.lmtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(lmtpMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert LMTP adelay: %v", err) - } - e.lmtpDelays.WithLabelValues("queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(lmtpMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert LMTP adelay: %v", err) - } - e.lmtpDelays.WithLabelValues("connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(lmtpMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert LMTP xdelay: %v", err) - } - e.lmtpDelays.WithLabelValues("transmission").Observe(xdelay) + addToHistogramVec(e.lmtpDelays, lmtpMatches[2], "LMTP pdelay", "before_queue_manager") + addToHistogramVec(e.lmtpDelays, lmtpMatches[3], "LMTP adelay", "queue_manager") + addToHistogramVec(e.lmtpDelays, lmtpMatches[4], "LMTP sdelay", "connection_setup") + addToHistogramVec(e.lmtpDelays, lmtpMatches[5], "LMTP xdelay", "transmission") } else { e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() } case "pipe": if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); pipeMatches != nil { - pdelay, err := strconv.ParseFloat(pipeMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert PIPE pdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(pipeMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert PIPE adelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(pipeMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert PIPE sdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(pipeMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert PIPE xdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "transmission").Observe(xdelay) + addToHistogramVec(e.pipeDelays, pipeMatches[2], "PIPE pdelay", pipeMatches[1], "before_queue_manager") + addToHistogramVec(e.pipeDelays, pipeMatches[3], "PIPE adelay", pipeMatches[1], "queue_manager") + addToHistogramVec(e.pipeDelays, pipeMatches[4], "PIPE sdelay", pipeMatches[1], "connection_setup") + addToHistogramVec(e.pipeDelays, pipeMatches[5], "PIPE xdelay", pipeMatches[1], "transmission") } else { e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() } case "qmgr": if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(logMatches[2]); qmgrInsertMatches != nil { - size, err := strconv.ParseFloat(qmgrInsertMatches[1], 64) - if err != nil { - log.Printf("Couldn't convert QMGR size: %v", err) - } - e.qmgrInsertsSize.Observe(size) - nrcpt, err := strconv.ParseFloat(qmgrInsertMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert QMGR nrcpt: %v", err) - } - e.qmgrInsertsNrcpt.Observe(nrcpt) + addToHistogram(e.qmgrInsertsSize, qmgrInsertMatches[1], "QMGR size") + addToHistogram(e.qmgrInsertsNrcpt, qmgrInsertMatches[2], "QMGR nrcpt") } else if strings.HasSuffix(logMatches[2], ": removed") { e.qmgrRemoves.Inc() } else { @@ -378,26 +338,10 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } case "smtp": if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); smtpMatches != nil { - pdelay, err := strconv.ParseFloat(smtpMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert SMTP pdelay: %v", err) - } - e.smtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(smtpMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert SMTP adelay: %v", err) - } - e.smtpDelays.WithLabelValues("queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(smtpMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert SMTP sdelay: %v", err) - } - e.smtpDelays.WithLabelValues("connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(smtpMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert SMTP xdelay: %v", err) - } - e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) + addToHistogramVec(e.smtpDelays, smtpMatches[2], "before_queue_manager") + addToHistogramVec(e.smtpDelays, smtpMatches[3], "queue_manager") + addToHistogramVec(e.smtpDelays, smtpMatches[4], "connection_setup") + addToHistogramVec(e.smtpDelays, smtpMatches[5], "transmission") } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(logMatches[2]); smtpTLSMatches != nil { e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() } else { @@ -431,6 +375,22 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } } +func addToHistogram(h prometheus.Histogram, value, fieldName string) { + float, err := strconv.ParseFloat(value, 64) + if err != nil { + log.Printf("Couldn't convert value '%s' for %v: %v", value, fieldName, err) + } + h.Observe(float) +} + +func addToHistogramVec(h *prometheus.HistogramVec, value, fieldName string, labels ...string) { + float, err := strconv.ParseFloat(value, 64) + if err != nil { + log.Printf("Couldn't convert value '%s' for %v: %v", value, fieldName, err) + } + h.WithLabelValues(labels...).Observe(float) +} + // CollectLogfileFromFile tails a Postfix log file and collects entries from it. func (e *PostfixExporter) CollectLogfileFromFile() error { for { From 43221afdb0039727598871d16c837bc6d79a09fc Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Thu, 21 Feb 2019 00:03:41 +0100 Subject: [PATCH 05/23] Move main function to main.go --- main.go | 63 +++++++++++++++++++++++++++++++++++++++++++++ postfix_exporter.go | 56 ---------------------------------------- 2 files changed, 63 insertions(+), 56 deletions(-) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..27f6737 --- /dev/null +++ b/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "log" + "net/http" + "os" + + "github.com/alecthomas/kingpin" + "github.com/prometheus/client_golang/prometheus" +) + +func main() { + var ( + app = kingpin.New("postfix_exporter", "Prometheus metrics exporter for postfix") + listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9154").String() + metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() + postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String() + postfixLogfilePath = app.Flag("postfix.logfile_path", "Path where Postfix writes log entries. This file will be truncated by this exporter.").Default("/var/log/postfix_exporter_input.log").String() + systemdEnable bool + systemdUnit, systemdSlice, systemdJournalPath string + ) + systemdFlags(&systemdEnable, &systemdUnit, &systemdSlice, &systemdJournalPath, app) + + kingpin.MustParse(app.Parse(os.Args[1:])) + + var journal *Journal + if systemdEnable { + var err error + journal, err = NewJournal(systemdUnit, systemdSlice, systemdJournalPath) + if err != nil { + log.Fatalf("Error opening systemd journal: %s", err) + } + defer journal.Close() + } + + exporter, err := NewPostfixExporter( + *postfixShowqPath, + *postfixLogfilePath, + journal, + ) + if err != nil { + log.Fatalf("Failed to create PostfixExporter: %s", err) + } + prometheus.MustRegister(exporter) + + http.Handle(*metricsPath, prometheus.Handler()) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + _, err = w.Write([]byte(` + + Postfix Exporter + +

Postfix Exporter

+

Metrics

+ + `)) + if err != nil { + panic(err) + } + }) + + log.Print("Listening on ", *listenAddress) + log.Fatal(http.ListenAndServe(*listenAddress, nil)) +} diff --git a/postfix_exporter.go b/postfix_exporter.go index 5ec0e19..cd22bff 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -18,12 +18,9 @@ import ( "bytes" "errors" "fmt" - "github.com/alecthomas/kingpin" "io" "log" "net" - "net/http" - "os" "regexp" "strconv" "strings" @@ -622,56 +619,3 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.smtpdTLSConnects.Collect(ch) e.unsupportedLogEntries.Collect(ch) } - -func main() { - var ( - app = kingpin.New("postfix_exporter", "Prometheus metrics exporter for postfix") - listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9154").String() - metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() - postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String() - postfixLogfilePath = app.Flag("postfix.logfile_path", "Path where Postfix writes log entries. This file will be truncated by this exporter.").Default("/var/log/postfix_exporter_input.log").String() - systemdEnable bool - systemdUnit, systemdSlice, systemdJournalPath string - ) - systemdFlags(&systemdEnable, &systemdUnit, &systemdSlice, &systemdJournalPath, app) - - kingpin.MustParse(app.Parse(os.Args[1:])) - - var journal *Journal - if systemdEnable { - var err error - journal, err = NewJournal(systemdUnit, systemdSlice, systemdJournalPath) - if err != nil { - log.Fatalf("Error opening systemd journal: %s", err) - } - defer journal.Close() - } - - exporter, err := NewPostfixExporter( - *postfixShowqPath, - *postfixLogfilePath, - journal, - ) - if err != nil { - log.Fatalf("Failed to create PostfixExporter: %s", err) - } - prometheus.MustRegister(exporter) - - http.Handle(*metricsPath, prometheus.Handler()) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - _, err = w.Write([]byte(` - - Postfix Exporter - -

Postfix Exporter

-

Metrics

- - `)) - if err != nil { - panic(err) - } - }) - - log.Print("Listening on ", *listenAddress) - log.Fatal(http.ListenAndServe(*listenAddress, nil)) -} From 8e333e774e1397fc4fdfd383f72e1aafce651d21 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Thu, 21 Feb 2019 00:14:45 +0100 Subject: [PATCH 06/23] Update dependencies --- go.mod | 7 ++++--- go.sum | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 24970d3..082a7f3 100644 --- a/go.mod +++ b/go.mod @@ -2,13 +2,14 @@ module github.com/kumina/postfix_exporter require ( github.com/alecthomas/kingpin v2.2.6+incompatible - github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect - github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect - github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 + github.com/coreos/go-systemd v0.0.0-20190212144455-93d5ec2c7f76 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/fsnotify/fsnotify v1.4.7 // indirect github.com/hpcloud/tail v1.0.0 github.com/prometheus/client_golang v0.9.2 + github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect + github.com/prometheus/common v0.2.0 // indirect + github.com/prometheus/procfs v0.0.0-20190219184716-e4d4a2206da0 // indirect github.com/stretchr/testify v1.3.0 // indirect golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 // indirect gopkg.in/fsnotify.v1 v1.4.7 // indirect diff --git a/go.sum b/go.sum index 871a6e5..371ef30 100644 --- a/go.sum +++ b/go.sum @@ -6,39 +6,70 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZq github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 h1:3jFq2xL4ZajGK4aZY8jz+DAF0FHjI51BXjjSwCzS1Dk= -github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190212144455-93d5ec2c7f76 h1:FE783w8WFh+Rvg+7bZ5g8p7gP4SeVS4AoNwkvazlsBg= +github.com/coreos/go-systemd v0.0.0-20190212144455-93d5ec2c7f76/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.2.0 h1:kUZDBDTdBVBYBj5Tmh2NZLlF60mfjA27rM34b+cVwNU= +github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190219184716-e4d4a2206da0 h1:4+Tdy73otddqWxwK30bAMLH9ymeHQ1Y5+fmSoCF1XtU= +github.com/prometheus/procfs v0.0.0-20190219184716-e4d4a2206da0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 h1:3Nsfe5Xa1wTt01QxlAFIY5j9ycDtS+d7mhvI8ZY5bn0= golang.org/x/sys v0.0.0-20190220154126-629670e5acc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From b925d46fcb39672d45b02571b553c75c90c26458 Mon Sep 17 00:00:00 2001 From: Andre Ponert Date: Mon, 15 Apr 2019 18:46:11 +0200 Subject: [PATCH 07/23] Added support for status=deferred metric --- postfix_exporter.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index 7fdd1a1..c7043e0 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -66,6 +66,7 @@ type PostfixExporter struct { smtpdSASLAuthenticationFailures prometheus.Counter smtpdTLSConnects *prometheus.CounterVec unsupportedLogEntries *prometheus.CounterVec + errorStatusDeferred prometheus.Counter } // CollectShowqFromReader parses the output of Postfix's 'showq' command @@ -284,6 +285,7 @@ var ( smtpdLostConnectionLine = regexp.MustCompile(`^lost connection after (\w+) from `) smtpdSASLAuthenticationFailuresLine = regexp.MustCompile(`^warning: \S+: SASL \S+ authentication failed: `) smtpdTLSLine = regexp.MustCompile(`^(\S+) TLS connection established from \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) + errorStatusDeferred = regexp.MustCompile(`, status=deferred`) ) // CollectFromLogline collects metrict from a Postfix log line. @@ -415,6 +417,10 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } else { e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() } + } else if logMatches[1] == "error" { + if errorMatches := errorStatusDeferred.FindStringSubmatch(logMatches[2]) ; errorMatches != nil { + e.errorStatusDeferred.Inc() + } } else { // Unknown Postfix service. e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() @@ -569,6 +575,12 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) Help: "Log entries that could not be processed.", }, []string{"service"}), + errorStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "postfix", + Name: "error_status_deferred", + Help: "Total number of messages deferred.", + }), + }, nil } @@ -593,6 +605,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { e.smtpdRejects.Describe(ch) ch <- e.smtpdSASLAuthenticationFailures.Desc() e.smtpdTLSConnects.Describe(ch) + ch <- e.errorStatusDeferred.Desc() e.unsupportedLogEntries.Describe(ch) } @@ -654,6 +667,7 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.smtpdRejects.Collect(ch) ch <- e.smtpdSASLAuthenticationFailures e.smtpdTLSConnects.Collect(ch) + ch <- e.errorStatusDeferred e.unsupportedLogEntries.Collect(ch) } From 5ceffcde754e2887ef3aa45e996bf2aa5266630c Mon Sep 17 00:00:00 2001 From: Andre Ponert Date: Mon, 15 Apr 2019 18:57:32 +0200 Subject: [PATCH 08/23] [FIX] consistent variable names --- postfix_exporter.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index c7043e0..e57b110 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -285,7 +285,7 @@ var ( smtpdLostConnectionLine = regexp.MustCompile(`^lost connection after (\w+) from `) smtpdSASLAuthenticationFailuresLine = regexp.MustCompile(`^warning: \S+: SASL \S+ authentication failed: `) smtpdTLSLine = regexp.MustCompile(`^(\S+) TLS connection established from \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) - errorStatusDeferred = regexp.MustCompile(`, status=deferred`) + errorStatusDeferredLine = regexp.MustCompile(`, status=deferred`) ) // CollectFromLogline collects metrict from a Postfix log line. @@ -418,7 +418,7 @@ func (e *PostfixExporter) CollectFromLogline(line string) { e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() } } else if logMatches[1] == "error" { - if errorMatches := errorStatusDeferred.FindStringSubmatch(logMatches[2]) ; errorMatches != nil { + if errorMatches := errorStatusDeferredLine.FindStringSubmatch(logMatches[2]) ; errorMatches != nil { e.errorStatusDeferred.Inc() } } else { From 18a48b8d7d028c3ccc430ca08e030296d420f82d Mon Sep 17 00:00:00 2001 From: Andre Ponert Date: Mon, 15 Apr 2019 19:48:49 +0200 Subject: [PATCH 09/23] [FIX] made metric smtp_status_deferred actually work --- postfix_exporter.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index e57b110..560b389 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -66,7 +66,7 @@ type PostfixExporter struct { smtpdSASLAuthenticationFailures prometheus.Counter smtpdTLSConnects *prometheus.CounterVec unsupportedLogEntries *prometheus.CounterVec - errorStatusDeferred prometheus.Counter + smtpStatusDeferred prometheus.Counter } // CollectShowqFromReader parses the output of Postfix's 'showq' command @@ -278,6 +278,7 @@ var ( logLine = regexp.MustCompile(` ?postfix/(\w+)\[\d+\]: (.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) + smtpStatusDeferredLine = regexp.MustCompile(`, status=deferred`) smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) smtpdFCrDNSErrorsLine = regexp.MustCompile(`^warning: hostname \S+ does not resolve to address `) smtpdProcessesSASLLine = regexp.MustCompile(`: client=.*, sasl_username=(\S+)`) @@ -285,7 +286,6 @@ var ( smtpdLostConnectionLine = regexp.MustCompile(`^lost connection after (\w+) from `) smtpdSASLAuthenticationFailuresLine = regexp.MustCompile(`^warning: \S+: SASL \S+ authentication failed: `) smtpdTLSLine = regexp.MustCompile(`^(\S+) TLS connection established from \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) - errorStatusDeferredLine = regexp.MustCompile(`, status=deferred`) ) // CollectFromLogline collects metrict from a Postfix log line. @@ -390,6 +390,10 @@ func (e *PostfixExporter) CollectFromLogline(line string) { log.Printf("Couldn't convert SMTP xdelay: %v", err) } e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) + + if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(logMatches[2]) ; smtpMatches != nil { + e.smtpStatusDeferred.Inc() + } } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(logMatches[2]); smtpTLSMatches != nil { e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() } else { @@ -417,10 +421,6 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } else { e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() } - } else if logMatches[1] == "error" { - if errorMatches := errorStatusDeferredLine.FindStringSubmatch(logMatches[2]) ; errorMatches != nil { - e.errorStatusDeferred.Inc() - } } else { // Unknown Postfix service. e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() @@ -575,9 +575,9 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) Help: "Log entries that could not be processed.", }, []string{"service"}), - errorStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{ + smtpStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: "postfix", - Name: "error_status_deferred", + Name: "smtp_status_deferred", Help: "Total number of messages deferred.", }), @@ -605,7 +605,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { e.smtpdRejects.Describe(ch) ch <- e.smtpdSASLAuthenticationFailures.Desc() e.smtpdTLSConnects.Describe(ch) - ch <- e.errorStatusDeferred.Desc() + ch <- e.smtpStatusDeferred.Desc() e.unsupportedLogEntries.Describe(ch) } @@ -667,7 +667,7 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.smtpdRejects.Collect(ch) ch <- e.smtpdSASLAuthenticationFailures e.smtpdTLSConnects.Collect(ch) - ch <- e.errorStatusDeferred + ch <- e.smtpStatusDeferred e.unsupportedLogEntries.Collect(ch) } From 365a2e307a48aeb5ffebb8a04d124810944efd10 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 12 Feb 2020 13:38:03 +0100 Subject: [PATCH 10/23] Ignoring more files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f238da4..7dd92f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ # Editor files *~ --.idea/ +.idea/ # Test binary, build with `go test -c` *.test # Binaries postfix_exporter + +*.iml +vendor/ From b0a28deeca71741a9dc731208b94b6e7f4934856 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 12 Feb 2020 13:39:13 +0100 Subject: [PATCH 11/23] Added logging of log event source --- postfix_exporter.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index ff5357b..4a3bb54 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -703,6 +703,9 @@ func main() { log.Fatalf("Error opening systemd journal: %s", err) } defer journal.Close() + log.Println("Reading log events from systemd") + } else { + log.Printf("Reading log events from %v", *postfixLogfilePath) } exporter, err := NewPostfixExporter( From da5280083a82c0310102fe77afd0a0c0c518e53e Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 12 Feb 2020 13:40:22 +0100 Subject: [PATCH 12/23] Added extra build tags to enable testing on no-linux systems --- nosystemd.go | 5 ++--- systemd.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nosystemd.go b/nosystemd.go index 33c1a16..901d270 100644 --- a/nosystemd.go +++ b/nosystemd.go @@ -1,15 +1,14 @@ -// +build nosystemd +// +build nosystemd !linux // This file contains stubs to support non-systemd use package main -import( +import ( "io" "github.com/alecthomas/kingpin" ) - type Journal struct { io.Closer Path string diff --git a/systemd.go b/systemd.go index d9d02f7..b507925 100644 --- a/systemd.go +++ b/systemd.go @@ -1,4 +1,4 @@ -// +build !nosystemd +// +build !nosystemd,linux package main From 851c00f29f4c47316064607360dead7401a2e821 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 12 Feb 2020 13:41:29 +0100 Subject: [PATCH 13/23] Added a simple test and migrated to vgo --- Dockerfile | 4 +- go.mod | 15 ++++ postfix_exporter_test.go | 161 +++++++++++++++++++++++++++++++++++++++ systemd.go | 2 +- 4 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 go.mod create mode 100644 postfix_exporter_test.go diff --git a/Dockerfile b/Dockerfile index b07e198..0b222c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Builder stage to -FROM golang:1.12 as builder +FROM golang:1.13 as builder # Add the project in the image ADD . /go/src/github.com/kumina/postfix_exporter @@ -11,7 +11,7 @@ RUN apt-get update -q && apt-get install -qy \ libsystemd-dev # Get dependencies and build the static binary -RUN go get -d ./... +RUN go test RUN go build -a -tags static_all # Real image diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3d5e663 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module github.com/kumina/postfix_exporter + +go 1.13 + +require ( + github.com/alecthomas/kingpin v2.2.6+incompatible + github.com/coreos/go-systemd/v22 v22.0.0 + github.com/fsnotify/fsnotify v1.4.7 // indirect + github.com/hpcloud/tail v1.0.0 + github.com/prometheus/client_golang v1.4.1 + github.com/prometheus/client_model v0.2.0 + github.com/stretchr/testify v1.4.0 + gopkg.in/fsnotify.v1 v1.4.7 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect +) diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go new file mode 100644 index 0000000..064f501 --- /dev/null +++ b/postfix_exporter_test.go @@ -0,0 +1,161 @@ +package main + +import ( + "github.com/hpcloud/tail" + "github.com/prometheus/client_golang/prometheus" + io_prometheus_client "github.com/prometheus/client_model/go" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestPostfixExporter_CollectFromLogline(t *testing.T) { + type fields struct { + showqPath string + journal *Journal + tailer *tail.Tail + cleanupProcesses prometheus.Counter + cleanupRejects prometheus.Counter + cleanupNotAccepted prometheus.Counter + lmtpDelays *prometheus.HistogramVec + pipeDelays *prometheus.HistogramVec + qmgrInsertsNrcpt prometheus.Histogram + qmgrInsertsSize prometheus.Histogram + qmgrRemoves prometheus.Counter + smtpDelays *prometheus.HistogramVec + smtpTLSConnects *prometheus.CounterVec + smtpDeferreds prometheus.Counter + smtpdConnects prometheus.Counter + smtpdDisconnects prometheus.Counter + smtpdFCrDNSErrors prometheus.Counter + smtpdLostConnections *prometheus.CounterVec + smtpdProcesses *prometheus.CounterVec + smtpdRejects *prometheus.CounterVec + smtpdSASLAuthenticationFailures prometheus.Counter + smtpdTLSConnects *prometheus.CounterVec + unsupportedLogEntries *prometheus.CounterVec + } + type args struct { + line []string + count int + } + tests := []struct { + name string + fields fields + args args + }{ + { + name: "Single line", + args: args{ + line: []string{ + "Feb 11 16:49:24 letterman postfix/qmgr[8204]: AAB4D259B1: removed", + }, + count: 1, + }, + }, + { + name: "Multiple lines", + args: args{ + line: []string{ + "Feb 11 16:49:24 letterman postfix/qmgr[8204]: AAB4D259B1: removed", + "Feb 11 16:49:24 letterman postfix/qmgr[8204]: C2032259E6: removed", + "Feb 11 16:49:24 letterman postfix/qmgr[8204]: B83C4257DC: removed", + "Feb 11 16:49:24 letterman postfix/qmgr[8204]: 721BE256EA: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: CA94A259EB: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: AC1E3259E1: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: D114D221E3: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: A55F82104D: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: D6DAA259BC: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: E3908259F0: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: 0CBB8259BF: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: EA3AD259F2: removed", + "Feb 11 16:49:25 letterman postfix/qmgr[8204]: DDEF824B48: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 289AF21DB9: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 6192B260E8: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: F2831259F4: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 09D60259F8: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 13A19259FA: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 2D42722065: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 746E325A0E: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 4D2F125A02: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: E30BC259EF: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: DC88924DA1: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 2164B259FD: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 8C30525A14: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: 8DCCE25A15: removed", + "Feb 11 16:49:26 letterman postfix/qmgr[8204]: C5217255D5: removed", + "Feb 11 16:49:27 letterman postfix/qmgr[8204]: D8EE625A28: removed", + "Feb 11 16:49:27 letterman postfix/qmgr[8204]: 9AD7C25A19: removed", + "Feb 11 16:49:27 letterman postfix/qmgr[8204]: D0EEE2596C: removed", + "Feb 11 16:49:27 letterman postfix/qmgr[8204]: DFE732172E: removed", + }, + count: 31, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + e := &PostfixExporter{ + showqPath: tt.fields.showqPath, + journal: tt.fields.journal, + tailer: tt.fields.tailer, + cleanupProcesses: tt.fields.cleanupProcesses, + cleanupRejects: tt.fields.cleanupRejects, + cleanupNotAccepted: tt.fields.cleanupNotAccepted, + lmtpDelays: tt.fields.lmtpDelays, + pipeDelays: tt.fields.pipeDelays, + qmgrInsertsNrcpt: tt.fields.qmgrInsertsNrcpt, + qmgrInsertsSize: tt.fields.qmgrInsertsSize, + qmgrRemoves: tt.fields.qmgrRemoves, + smtpDelays: tt.fields.smtpDelays, + smtpTLSConnects: tt.fields.smtpTLSConnects, + smtpDeferreds: tt.fields.smtpDeferreds, + smtpdConnects: tt.fields.smtpdConnects, + smtpdDisconnects: tt.fields.smtpdDisconnects, + smtpdFCrDNSErrors: tt.fields.smtpdFCrDNSErrors, + smtpdLostConnections: tt.fields.smtpdLostConnections, + smtpdProcesses: tt.fields.smtpdProcesses, + smtpdRejects: tt.fields.smtpdRejects, + smtpdSASLAuthenticationFailures: tt.fields.smtpdSASLAuthenticationFailures, + smtpdTLSConnects: tt.fields.smtpdTLSConnects, + unsupportedLogEntries: tt.fields.unsupportedLogEntries, + } + counter := testCounter{} + e.qmgrRemoves = &counter + for _, line := range tt.args.line { + e.CollectFromLogline(line) + } + assert.Equal(t, tt.args.count, counter.Count(), "Wrong number of lines counted") + if counter.Count() != tt.args.count { + t.Fatal("Counter wrong: ") + } + }) + } +} + +type testCounter struct { + count int +} + +func (t *testCounter) setCount(count int) { + t.count = count +} + +func (t *testCounter) Count() int { + return t.count +} + +func (t *testCounter) Add(add float64) { +} +func (t *testCounter) Collect(c chan<- prometheus.Metric) { +} +func (t *testCounter) Describe(c chan<- *prometheus.Desc) { +} +func (t *testCounter) Desc() *prometheus.Desc { + return nil +} +func (t *testCounter) Inc() { + t.count++ +} +func (t *testCounter) Write(x *io_prometheus_client.Metric) error { + return nil +} diff --git a/systemd.go b/systemd.go index b507925..232cae6 100644 --- a/systemd.go +++ b/systemd.go @@ -9,7 +9,7 @@ import ( "time" "github.com/alecthomas/kingpin" - "github.com/coreos/go-systemd/sdjournal" + "github.com/coreos/go-systemd/v22/sdjournal" ) // Journal represents a lockable systemd journal. From 3e8a3a4917c1f5b0b17c32c0838cb3077b347dd6 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Tue, 18 Feb 2020 13:33:30 +0100 Subject: [PATCH 14/23] Cleaning up the Dockerfile --- .dockerignore | 4 ++++ Dockerfile | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b528b7d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +# Created by .ignore support plugin (hsz.mobi) +.idea/ +*.iml +.git/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0b222c1..ab916aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM golang:1.13 as builder # Add the project in the image -ADD . /go/src/github.com/kumina/postfix_exporter -WORKDIR /go/src/github.com/kumina/postfix_exporter +ADD . /build +WORKDIR /build # Install needed dependencies for the build RUN apt-get update -q && apt-get install -qy \ @@ -21,6 +21,6 @@ EXPOSE 9154 WORKDIR / # Copy the binary from the build image to the real one -COPY --from=builder /go/src/github.com/kumina/postfix_exporter/postfix_exporter . +COPY --from=builder /build/postfix_exporter . ENTRYPOINT ["/postfix_exporter"] From 26d06428312ac8cbf2dfb9d917f85ec0057035f1 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Tue, 18 Feb 2020 15:31:07 +0100 Subject: [PATCH 15/23] Moved the collection of stats into its own go routine --- postfix_exporter.go | 94 ++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 5c9fad7..f756488 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -16,6 +16,7 @@ package main import ( "bufio" "bytes" + "context" "errors" "fmt" "github.com/alecthomas/kingpin" @@ -293,7 +294,7 @@ var ( ) // CollectFromLogline collects metrict from a Postfix log line. -func (e *PostfixExporter) CollectFromLogline(line string) { +func (e *PostfixExporter) CollectFromLogLine(line string) { // Strip off timestamp, hostname, etc. if logMatches := logLine.FindStringSubmatch(line); logMatches != nil { // Group patterns to check by Postfix service. @@ -397,7 +398,7 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) - if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(logMatches[2]) ; smtpMatches != nil { + if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(logMatches[2]); smtpMatches != nil { e.smtpStatusDeferred.Inc() } } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(logMatches[2]); smtpTLSMatches != nil { @@ -438,14 +439,25 @@ func (e *PostfixExporter) CollectFromLogline(line string) { } // CollectLogfileFromFile tails a Postfix log file and collects entries from it. -func (e *PostfixExporter) CollectLogfileFromFile() error { +func (e *PostfixExporter) CollectLogfileFromFile(ctx context.Context) { + gaugeVec := prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "postfix", + Subsystem: "", + Name: "up", + Help: "Whether scraping Postfix's metrics was successful.", + }, + []string{"path"}) + gauge := gaugeVec.With(prometheus.Labels{"path": e.tailer.Filename}) for { select { case line := <-e.tailer.Lines: - e.CollectFromLogline(line.Text) - default: - return nil + e.CollectFromLogLine(line.Text) + case <-ctx.Done(): + gauge.Set(0) + return } + gauge.Set(1) } } @@ -596,7 +608,6 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) Name: "smtp_status_deferred", Help: "Total number of messages deferred.", }), - }, nil } @@ -627,6 +638,48 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { e.unsupportedLogEntries.Describe(ch) } +func (e *PostfixExporter) foreverCollectFromJournal(ctx context.Context) { + gauge := prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "postfix", + Subsystem: "", + Name: "up", + Help: "Whether scraping Postfix's metrics was successful.", + }, + []string{"path"}).With(prometheus.Labels{"path": e.journal.Path}) + select { + case <-ctx.Done(): + gauge.Set(0) + return + default: + err := e.CollectLogfileFromJournal() + if err != nil { + log.Printf("Couldn't read journal: %v", err) + gauge.Set(0) + } else { + gauge.Set(1) + } + } +} + +func (e *PostfixExporter) StartMetricCollection(ctx context.Context) { + if e.journal != nil { + e.foreverCollectFromJournal(ctx) + } else { + e.CollectLogfileFromFile(ctx) + } + + prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: "postfix", + Subsystem: "", + Name: "up", + Help: "Whether scraping Postfix's metrics was successful.", + }, + []string{"path"}) + return +} + // Collect metrics from Postfix's showq socket and its log file. func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { err := CollectShowqFromSocket(e.showqPath, ch) @@ -645,29 +698,6 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.showqPath) } - var src string - if e.journal != nil { - err = e.CollectLogfileFromJournal() - src = e.journal.Path - } else { - err = e.CollectLogfileFromFile() - src = e.tailer.Filename - } - if err == nil { - ch <- prometheus.MustNewConstMetric( - postfixUpDesc, - prometheus.GaugeValue, - 1.0, - src) - } else { - log.Printf("Failed to scrape log: %s", err) - ch <- prometheus.MustNewConstMetric( - postfixUpDesc, - prometheus.GaugeValue, - 0.0, - src) - } - ch <- e.cleanupProcesses ch <- e.cleanupRejects ch <- e.cleanupNotAccepted @@ -742,7 +772,9 @@ func main() { panic(err) } }) - + ctx, cancelFunc := context.WithCancel(context.Background()) + defer cancelFunc() + go exporter.StartMetricCollection(ctx) log.Print("Listening on ", *listenAddress) log.Fatal(http.ListenAndServe(*listenAddress, nil)) } From 574e478b44e13a0c3ed112c601f4b9cf08c89557 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Tue, 18 Feb 2020 15:32:44 +0100 Subject: [PATCH 16/23] Removed unused variable --- postfix_exporter.go | 1 - 1 file changed, 1 deletion(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index f756488..7189d4b 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -284,7 +284,6 @@ var ( qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) smtpStatusDeferredLine = regexp.MustCompile(`, status=deferred`) smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) - smtpDeferredsLine = regexp.MustCompile(`status=deferred`) smtpdFCrDNSErrorsLine = regexp.MustCompile(`^warning: hostname \S+ does not resolve to address `) smtpdProcessesSASLLine = regexp.MustCompile(`: client=.*, sasl_username=(\S+)`) smtpdRejectsLine = regexp.MustCompile(`^NOQUEUE: reject: RCPT from \S+: ([0-9]+) `) From e416d73974dc527c32e37275ae6006b154792989 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Tue, 18 Feb 2020 16:17:13 +0100 Subject: [PATCH 17/23] Fixed test --- postfix_exporter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index 064f501..59b9a6f 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -122,7 +122,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { counter := testCounter{} e.qmgrRemoves = &counter for _, line := range tt.args.line { - e.CollectFromLogline(line) + e.CollectFromLogLine(line) } assert.Equal(t, tt.args.count, counter.Count(), "Wrong number of lines counted") if counter.Count() != tt.args.count { From 3af4390187246f757718cbedfcb32d5128d67397 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Tue, 18 Feb 2020 16:54:25 +0100 Subject: [PATCH 18/23] - Added flag for logging lines that were not processed (mainly for debugging/development) - Added Counter for smtp Connection Timed Out events - Added counter for OpenDKIM signatures added --- postfix_exporter.go | 334 ++++++++++++++++++++++++++------------------ 1 file changed, 200 insertions(+), 134 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 7189d4b..c992256 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -45,9 +45,10 @@ var ( // PostfixExporter holds the state that should be preserved by the // Postfix Prometheus metrics exporter across scrapes. type PostfixExporter struct { - showqPath string - journal *Journal - tailer *tail.Tail + showqPath string + journal *Journal + tailer *tail.Tail + logUnsupportedLines bool // Metrics that should persist after refreshes, based on logs. cleanupProcesses prometheus.Counter @@ -60,6 +61,7 @@ type PostfixExporter struct { qmgrRemoves prometheus.Counter smtpDelays *prometheus.HistogramVec smtpTLSConnects *prometheus.CounterVec + smtpConnectionTimedOut prometheus.Counter smtpDeferreds prometheus.Counter smtpdConnects prometheus.Counter smtpdDisconnects prometheus.Counter @@ -71,6 +73,7 @@ type PostfixExporter struct { smtpdTLSConnects *prometheus.CounterVec unsupportedLogEntries *prometheus.CounterVec smtpStatusDeferred prometheus.Counter + opendkimSignatureAdded *prometheus.CounterVec } // CollectShowqFromReader parses the output of Postfix's 'showq' command @@ -279,160 +282,205 @@ func CollectShowqFromSocket(path string, ch chan<- prometheus.Metric) error { // Patterns for parsing log messages. var ( - logLine = regexp.MustCompile(` ?postfix/(\w+)\[\d+\]: (.*)`) + logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) smtpStatusDeferredLine = regexp.MustCompile(`, status=deferred`) smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) + smtpConnectionTimedOut = regexp.MustCompile(`^connect\s+to\s+(.*)\[(.*)\]:(\d+):\s+(Connection timed out)$`) smtpdFCrDNSErrorsLine = regexp.MustCompile(`^warning: hostname \S+ does not resolve to address `) smtpdProcessesSASLLine = regexp.MustCompile(`: client=.*, sasl_username=(\S+)`) smtpdRejectsLine = regexp.MustCompile(`^NOQUEUE: reject: RCPT from \S+: ([0-9]+) `) smtpdLostConnectionLine = regexp.MustCompile(`^lost connection after (\w+) from `) smtpdSASLAuthenticationFailuresLine = regexp.MustCompile(`^warning: \S+: SASL \S+ authentication failed: `) smtpdTLSLine = regexp.MustCompile(`^(\S+) TLS connection established from \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)$`) + opendkimSignatureAdded = regexp.MustCompile(`^[\w\d]+: DKIM-Signature field added \(s=(\w+), d=(.*)\)$`) ) // CollectFromLogline collects metrict from a Postfix log line. func (e *PostfixExporter) CollectFromLogLine(line string) { // Strip off timestamp, hostname, etc. if logMatches := logLine.FindStringSubmatch(line); logMatches != nil { - // Group patterns to check by Postfix service. - if logMatches[1] == "cleanup" { - if strings.Contains(logMatches[2], ": message-id=<") { - e.cleanupProcesses.Inc() - } else if strings.Contains(logMatches[2], ": reject: ") { - e.cleanupRejects.Inc() - } else if strings.Contains(logMatches[2], "message not accepted") { - e.cleanupNotAccepted.Inc() - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "lmtp" { - if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); lmtpMatches != nil { - pdelay, err := strconv.ParseFloat(lmtpMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert LMTP pdelay: %v", err) + process := logMatches[1] + subprocess := logMatches[3] + remainder := logMatches[4] + switch process { + case "postfix": + // Group patterns to check by Postfix service. + if subprocess == "cleanup" { + if strings.Contains(remainder, ": message-id=<") { + e.cleanupProcesses.Inc() + } else if strings.Contains(remainder, ": reject: ") { + e.cleanupRejects.Inc() + } else if strings.Contains(remainder, "message not accepted") { + e.cleanupNotAccepted.Inc() + } else { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - e.lmtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(lmtpMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert LMTP adelay: %v", err) + } else if subprocess == "lmtp" { + if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); lmtpMatches != nil { + pdelay, err := strconv.ParseFloat(lmtpMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert LMTP pdelay: %v", err) + } + e.lmtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) + adelay, err := strconv.ParseFloat(lmtpMatches[3], 64) + if err != nil { + log.Printf("Couldn't convert LMTP adelay: %v", err) + } + e.lmtpDelays.WithLabelValues("queue_manager").Observe(adelay) + sdelay, err := strconv.ParseFloat(lmtpMatches[4], 64) + if err != nil { + log.Printf("Couldn't convert LMTP adelay: %v", err) + } + e.lmtpDelays.WithLabelValues("connection_setup").Observe(sdelay) + xdelay, err := strconv.ParseFloat(lmtpMatches[5], 64) + if err != nil { + log.Printf("Couldn't convert LMTP xdelay: %v", err) + } + e.lmtpDelays.WithLabelValues("transmission").Observe(xdelay) + } else { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - e.lmtpDelays.WithLabelValues("queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(lmtpMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert LMTP adelay: %v", err) + } else if subprocess == "pipe" { + if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); pipeMatches != nil { + pdelay, err := strconv.ParseFloat(pipeMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert PIPE pdelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "before_queue_manager").Observe(pdelay) + adelay, err := strconv.ParseFloat(pipeMatches[3], 64) + if err != nil { + log.Printf("Couldn't convert PIPE adelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "queue_manager").Observe(adelay) + sdelay, err := strconv.ParseFloat(pipeMatches[4], 64) + if err != nil { + log.Printf("Couldn't convert PIPE sdelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "connection_setup").Observe(sdelay) + xdelay, err := strconv.ParseFloat(pipeMatches[5], 64) + if err != nil { + log.Printf("Couldn't convert PIPE xdelay: %v", err) + } + e.pipeDelays.WithLabelValues(pipeMatches[1], "transmission").Observe(xdelay) + } else { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - e.lmtpDelays.WithLabelValues("connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(lmtpMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert LMTP xdelay: %v", err) + } else if subprocess == "qmgr" { + if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(remainder); qmgrInsertMatches != nil { + size, err := strconv.ParseFloat(qmgrInsertMatches[1], 64) + if err != nil { + log.Printf("Couldn't convert QMGR size: %v", err) + } + e.qmgrInsertsSize.Observe(size) + nrcpt, err := strconv.ParseFloat(qmgrInsertMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert QMGR nrcpt: %v", err) + } + e.qmgrInsertsNrcpt.Observe(nrcpt) + } else if strings.HasSuffix(remainder, ": removed") { + e.qmgrRemoves.Inc() + } else { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - e.lmtpDelays.WithLabelValues("transmission").Observe(xdelay) - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "pipe" { - if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); pipeMatches != nil { - pdelay, err := strconv.ParseFloat(pipeMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert PIPE pdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(pipeMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert PIPE adelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(pipeMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert PIPE sdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(pipeMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert PIPE xdelay: %v", err) - } - e.pipeDelays.WithLabelValues(pipeMatches[1], "transmission").Observe(xdelay) - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "qmgr" { - if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(logMatches[2]); qmgrInsertMatches != nil { - size, err := strconv.ParseFloat(qmgrInsertMatches[1], 64) - if err != nil { - log.Printf("Couldn't convert QMGR size: %v", err) - } - e.qmgrInsertsSize.Observe(size) - nrcpt, err := strconv.ParseFloat(qmgrInsertMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert QMGR nrcpt: %v", err) - } - e.qmgrInsertsNrcpt.Observe(nrcpt) - } else if strings.HasSuffix(logMatches[2], ": removed") { - e.qmgrRemoves.Inc() - } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() - } - } else if logMatches[1] == "smtp" { - if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(logMatches[2]); smtpMatches != nil { - pdelay, err := strconv.ParseFloat(smtpMatches[2], 64) - if err != nil { - log.Printf("Couldn't convert SMTP pdelay: %v", err) - } - e.smtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) - adelay, err := strconv.ParseFloat(smtpMatches[3], 64) - if err != nil { - log.Printf("Couldn't convert SMTP adelay: %v", err) - } - e.smtpDelays.WithLabelValues("queue_manager").Observe(adelay) - sdelay, err := strconv.ParseFloat(smtpMatches[4], 64) - if err != nil { - log.Printf("Couldn't convert SMTP sdelay: %v", err) - } - e.smtpDelays.WithLabelValues("connection_setup").Observe(sdelay) - xdelay, err := strconv.ParseFloat(smtpMatches[5], 64) - if err != nil { - log.Printf("Couldn't convert SMTP xdelay: %v", err) - } - e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) + } else if subprocess == "smtp" { + if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); smtpMatches != nil { + pdelay, err := strconv.ParseFloat(smtpMatches[2], 64) + if err != nil { + log.Printf("Couldn't convert SMTP pdelay: %v", err) + } + e.smtpDelays.WithLabelValues("before_queue_manager").Observe(pdelay) + adelay, err := strconv.ParseFloat(smtpMatches[3], 64) + if err != nil { + log.Printf("Couldn't convert SMTP adelay: %v", err) + } + e.smtpDelays.WithLabelValues("queue_manager").Observe(adelay) + sdelay, err := strconv.ParseFloat(smtpMatches[4], 64) + if err != nil { + log.Printf("Couldn't convert SMTP sdelay: %v", err) + } + e.smtpDelays.WithLabelValues("connection_setup").Observe(sdelay) + xdelay, err := strconv.ParseFloat(smtpMatches[5], 64) + if err != nil { + log.Printf("Couldn't convert SMTP xdelay: %v", err) + } + e.smtpDelays.WithLabelValues("transmission").Observe(xdelay) - if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(logMatches[2]); smtpMatches != nil { - e.smtpStatusDeferred.Inc() + if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(remainder); smtpMatches != nil { + e.smtpStatusDeferred.Inc() + } + } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(remainder); smtpTLSMatches != nil { + e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() + } else if smtpMatches := smtpConnectionTimedOut.FindStringSubmatch(remainder); smtpMatches != nil { + e.smtpConnectionTimedOut.Inc() + } else { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + } + } else if subprocess == "smtpd" { + if strings.HasPrefix(remainder, "connect from ") { + e.smtpdConnects.Inc() + } else if strings.HasPrefix(remainder, "disconnect from ") { + e.smtpdDisconnects.Inc() + } else if smtpdFCrDNSErrorsLine.MatchString(remainder) { + e.smtpdFCrDNSErrors.Inc() + } else if smtpdLostConnectionMatches := smtpdLostConnectionLine.FindStringSubmatch(remainder); smtpdLostConnectionMatches != nil { + e.smtpdLostConnections.WithLabelValues(smtpdLostConnectionMatches[1]).Inc() + } else if smtpdProcessesSASLMatches := smtpdProcessesSASLLine.FindStringSubmatch(remainder); smtpdProcessesSASLMatches != nil { + e.smtpdProcesses.WithLabelValues(smtpdProcessesSASLMatches[1]).Inc() + } else if strings.Contains(remainder, ": client=") { + e.smtpdProcesses.WithLabelValues("").Inc() + } else if smtpdRejectsMatches := smtpdRejectsLine.FindStringSubmatch(remainder); smtpdRejectsMatches != nil { + e.smtpdRejects.WithLabelValues(smtpdRejectsMatches[1]).Inc() + } else if smtpdSASLAuthenticationFailuresLine.MatchString(remainder) { + e.smtpdSASLAuthenticationFailures.Inc() + } else if smtpdTLSMatches := smtpdTLSLine.FindStringSubmatch(remainder); smtpdTLSMatches != nil { + e.smtpdTLSConnects.WithLabelValues(smtpdTLSMatches[1:]...).Inc() + } else { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(logMatches[2]); smtpTLSMatches != nil { - e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + // Unknown Postfix service. + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - } else if logMatches[1] == "smtpd" { - if strings.HasPrefix(logMatches[2], "connect from ") { - e.smtpdConnects.Inc() - } else if strings.HasPrefix(logMatches[2], "disconnect from ") { - e.smtpdDisconnects.Inc() - } else if smtpdFCrDNSErrorsLine.MatchString(logMatches[2]) { - e.smtpdFCrDNSErrors.Inc() - } else if smtpdLostConnectionMatches := smtpdLostConnectionLine.FindStringSubmatch(logMatches[2]); smtpdLostConnectionMatches != nil { - e.smtpdLostConnections.WithLabelValues(smtpdLostConnectionMatches[1]).Inc() - } else if smtpdProcessesSASLMatches := smtpdProcessesSASLLine.FindStringSubmatch(logMatches[2]); smtpdProcessesSASLMatches != nil { - e.smtpdProcesses.WithLabelValues(smtpdProcessesSASLMatches[1]).Inc() - } else if strings.Contains(logMatches[2], ": client=") { - e.smtpdProcesses.WithLabelValues("").Inc() - } else if smtpdRejectsMatches := smtpdRejectsLine.FindStringSubmatch(logMatches[2]); smtpdRejectsMatches != nil { - e.smtpdRejects.WithLabelValues(smtpdRejectsMatches[1]).Inc() - } else if smtpdSASLAuthenticationFailuresLine.MatchString(logMatches[2]) { - e.smtpdSASLAuthenticationFailures.Inc() - } else if smtpdTLSMatches := smtpdTLSLine.FindStringSubmatch(logMatches[2]); smtpdTLSMatches != nil { - e.smtpdTLSConnects.WithLabelValues(smtpdTLSMatches[1:]...).Inc() + case "opendkim": + if opendkimMatches := opendkimSignatureAdded.FindStringSubmatch(remainder); opendkimMatches != nil { + e.opendkimSignatureAdded.WithLabelValues(opendkimMatches[1], opendkimMatches[2]).Inc() } else { - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() } - } else { - // Unknown Postfix service. - e.unsupportedLogEntries.WithLabelValues(logMatches[1]).Inc() + default: + } } else { // Unknown log entry format. + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } e.unsupportedLogEntries.WithLabelValues("").Inc() } } @@ -447,7 +495,7 @@ func (e *PostfixExporter) CollectLogfileFromFile(ctx context.Context) { Help: "Whether scraping Postfix's metrics was successful.", }, []string{"path"}) - gauge := gaugeVec.With(prometheus.Labels{"path": e.tailer.Filename}) + gauge := gaugeVec.WithLabelValues(e.tailer.Filename) for { select { case line := <-e.tailer.Lines: @@ -461,7 +509,7 @@ func (e *PostfixExporter) CollectLogfileFromFile(ctx context.Context) { } // NewPostfixExporter creates a new Postfix exporter instance. -func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) (*PostfixExporter, error) { +func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal, logUnsupportedLines bool) (*PostfixExporter, error) { var tailer *tail.Tail if logfilePath != "" { var err error @@ -475,9 +523,10 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) } } return &PostfixExporter{ - showqPath: showqPath, - tailer: tailer, - journal: journal, + logUnsupportedLines: logUnsupportedLines, + showqPath: showqPath, + tailer: tailer, + journal: journal, cleanupProcesses: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: "postfix", @@ -547,6 +596,11 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) Name: "smtp_deferred_messages_total", Help: "Total number of messages that have been deferred on SMTP.", }), + smtpConnectionTimedOut: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "postfix", + Name: "smtp_connection_timed_out_total", + Help: "Total number of messages that have been deferred on SMTP.", + }), smtpdConnects: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: "postfix", Name: "smtpd_connects_total", @@ -607,6 +661,14 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal) Name: "smtp_status_deferred", Help: "Total number of messages deferred.", }), + opendkimSignatureAdded: prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "opendkim", + Name: "signatures_added_total", + Help: "Total number of messages signed.", + }, + []string{"subject", "domain"}, + ), }, nil } @@ -645,7 +707,7 @@ func (e *PostfixExporter) foreverCollectFromJournal(ctx context.Context) { Name: "up", Help: "Whether scraping Postfix's metrics was successful.", }, - []string{"path"}).With(prometheus.Labels{"path": e.journal.Path}) + []string{"path"}).WithLabelValues(e.journal.Path) select { case <-ctx.Done(): gauge.Set(0) @@ -718,6 +780,8 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.smtpdTLSConnects.Collect(ch) ch <- e.smtpStatusDeferred e.unsupportedLogEntries.Collect(ch) + ch <- e.smtpConnectionTimedOut + e.opendkimSignatureAdded.Collect(ch) } func main() { @@ -727,6 +791,7 @@ func main() { metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String() postfixLogfilePath = app.Flag("postfix.logfile_path", "Path where Postfix writes log entries. This file will be truncated by this exporter.").Default("/var/log/postfix_exporter_input.log").String() + logUnsupportedLines = app.Flag("log.unsupported", "Log all unsupported lines.").Bool() systemdEnable bool systemdUnit, systemdSlice, systemdJournalPath string ) @@ -751,6 +816,7 @@ func main() { *postfixShowqPath, *postfixLogfilePath, journal, + *logUnsupportedLines, ) if err != nil { log.Fatalf("Failed to create PostfixExporter: %s", err) From eab41dab6b08945021210bd0c1a18416186f11d2 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Tue, 18 Feb 2020 16:56:31 +0100 Subject: [PATCH 19/23] Fixed compile failure --- systemd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd.go b/systemd.go index 232cae6..e459c8b 100644 --- a/systemd.go +++ b/systemd.go @@ -112,7 +112,7 @@ func (e *PostfixExporter) CollectLogfileFromJournal() error { if c == 0 { break } - e.CollectFromLogline(m) + e.CollectFromLogLine(m) } return nil From 7428bf432be6fd338e06b8dc959946b2a7ab8d0f Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 19 Feb 2020 13:08:47 +0100 Subject: [PATCH 20/23] Added better counting of unsupported lines --- postfix_exporter.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index c992256..ef5adf0 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -471,10 +471,13 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { if e.logUnsupportedLines { log.Printf("Unsupported Line: %v", line) } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.unsupportedLogEntries.WithLabelValues(process).Inc() } default: - + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(process).Inc() } } else { // Unknown log entry format. From d23c664b657a1d9f4a959481885ba3da865e17ee Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 19 Feb 2020 18:10:45 +0100 Subject: [PATCH 21/23] Fixing merge issues --- main.go | 13 ++++- postfix_exporter.go | 133 ++++++++------------------------------------ 2 files changed, 35 insertions(+), 111 deletions(-) diff --git a/main.go b/main.go index 27f6737..5e3adb8 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "context" + "github.com/prometheus/client_golang/prometheus/promhttp" "log" "net/http" "os" @@ -16,6 +18,7 @@ func main() { metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String() postfixLogfilePath = app.Flag("postfix.logfile_path", "Path where Postfix writes log entries. This file will be truncated by this exporter.").Default("/var/log/postfix_exporter_input.log").String() + logUnsupportedLines = app.Flag("log.unsupported", "Log all unsupported lines.").Bool() systemdEnable bool systemdUnit, systemdSlice, systemdJournalPath string ) @@ -31,19 +34,23 @@ func main() { log.Fatalf("Error opening systemd journal: %s", err) } defer journal.Close() + log.Println("Reading log events from systemd") + } else { + log.Printf("Reading log events from %v", *postfixLogfilePath) } exporter, err := NewPostfixExporter( *postfixShowqPath, *postfixLogfilePath, journal, + *logUnsupportedLines, ) if err != nil { log.Fatalf("Failed to create PostfixExporter: %s", err) } prometheus.MustRegister(exporter) - http.Handle(*metricsPath, prometheus.Handler()) + http.Handle(*metricsPath, promhttp.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { _, err = w.Write([]byte(` @@ -57,7 +64,9 @@ func main() { panic(err) } }) - + ctx, cancelFunc := context.WithCancel(context.Background()) + defer cancelFunc() + go exporter.StartMetricCollection(ctx) log.Print("Listening on ", *listenAddress) log.Fatal(http.ListenAndServe(*listenAddress, nil)) } diff --git a/postfix_exporter.go b/postfix_exporter.go index ce59e0a..18f906c 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -258,16 +258,6 @@ func CollectBinaryShowqFromReader(file io.Reader, ch chan<- prometheus.Metric) e return scanner.Err() } -// CollectShowqFromFile collects Postfix queue statistics from a file. -//func CollectShowqFromFile(path string, ch chan<- prometheus.Metric) error { -// fd, err := os.Open(path) -// if err != nil { -// return err -// } -// defer fd.Close() -// return CollectShowqFromReader(fd, ch) -//} - // CollectShowqFromSocket collects Postfix queue statistics from a socket. func CollectShowqFromSocket(path string, ch chan<- prometheus.Metric) error { fd, err := net.Dial("unix", path) @@ -302,15 +292,15 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { if logMatches == nil { // Unknown log entry format. - e.unsupportedLogEntries.WithLabelValues("").Inc() + e.addToUnsupportedLine(line, "") return } process := logMatches[1] - subprocess := logMatches[3] remainder := logMatches[4] switch process { case "postfix": // Group patterns to check by Postfix service. + subprocess := logMatches[3] switch subprocess { case "cleanup": if strings.Contains(remainder, ": message-id=<") { @@ -318,10 +308,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if strings.Contains(remainder, ": reject: ") { e.cleanupRejects.Inc() } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } case "lmtp": if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); lmtpMatches != nil { @@ -330,10 +317,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.lmtpDelays, lmtpMatches[4], "LMTP sdelay", "connection_setup") addToHistogramVec(e.lmtpDelays, lmtpMatches[5], "LMTP xdelay", "transmission") } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } case "pipe": if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); pipeMatches != nil { @@ -342,10 +326,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.pipeDelays, pipeMatches[4], "PIPE sdelay", pipeMatches[1], "connection_setup") addToHistogramVec(e.pipeDelays, pipeMatches[5], "PIPE xdelay", pipeMatches[1], "transmission") } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } case "qmgr": if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(remainder); qmgrInsertMatches != nil { @@ -354,10 +335,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if strings.HasSuffix(remainder, ": removed") { e.qmgrRemoves.Inc() } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } case "smtp": if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); smtpMatches != nil { @@ -365,13 +343,15 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.smtpDelays, smtpMatches[3], "queue_manager") addToHistogramVec(e.smtpDelays, smtpMatches[4], "connection_setup") addToHistogramVec(e.smtpDelays, smtpMatches[5], "transmission") + if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(remainder); smtpMatches != nil { + e.smtpStatusDeferred.Inc() + } } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(remainder); smtpTLSMatches != nil { e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() + } else if smtpMatches := smtpConnectionTimedOut.FindStringSubmatch(remainder); smtpMatches != nil { + e.smtpConnectionTimedOut.Inc() } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } case "smtpd": if strings.HasPrefix(remainder, "connect from ") { @@ -393,35 +373,30 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if smtpdTLSMatches := smtpdTLSLine.FindStringSubmatch(remainder); smtpdTLSMatches != nil { e.smtpdTLSConnects.WithLabelValues(smtpdTLSMatches[1:]...).Inc() } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } default: - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - // Unknown Postfix service. - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.addToUnsupportedLine(line, subprocess) } case "opendkim": if opendkimMatches := opendkimSignatureAdded.FindStringSubmatch(remainder); opendkimMatches != nil { e.opendkimSignatureAdded.WithLabelValues(opendkimMatches[1], opendkimMatches[2]).Inc() } else { - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues(process).Inc() + e.addToUnsupportedLine(line, process) } default: // Unknown log entry format. - if e.logUnsupportedLines { - log.Printf("Unsupported Line: %v", line) - } - e.unsupportedLogEntries.WithLabelValues("").Inc() + e.addToUnsupportedLine(line, "") } } + +func (e *PostfixExporter) addToUnsupportedLine(line string, subprocess string) { + if e.logUnsupportedLines { + log.Printf("Unsupported Line: %v", line) + } + e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() +} + func addToHistogram(h prometheus.Histogram, value, fieldName string) { float, err := strconv.ParseFloat(value, 64) if err != nil { @@ -735,63 +710,3 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { ch <- e.smtpConnectionTimedOut e.opendkimSignatureAdded.Collect(ch) } - -func main() { - var ( - app = kingpin.New("postfix_exporter", "Prometheus metrics exporter for postfix") - listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9154").String() - metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() - postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String() - postfixLogfilePath = app.Flag("postfix.logfile_path", "Path where Postfix writes log entries. This file will be truncated by this exporter.").Default("/var/log/postfix_exporter_input.log").String() - logUnsupportedLines = app.Flag("log.unsupported", "Log all unsupported lines.").Bool() - systemdEnable bool - systemdUnit, systemdSlice, systemdJournalPath string - ) - systemdFlags(&systemdEnable, &systemdUnit, &systemdSlice, &systemdJournalPath, app) - - kingpin.MustParse(app.Parse(os.Args[1:])) - - var journal *Journal - if systemdEnable { - var err error - journal, err = NewJournal(systemdUnit, systemdSlice, systemdJournalPath) - if err != nil { - log.Fatalf("Error opening systemd journal: %s", err) - } - defer journal.Close() - log.Println("Reading log events from systemd") - } else { - log.Printf("Reading log events from %v", *postfixLogfilePath) - } - - exporter, err := NewPostfixExporter( - *postfixShowqPath, - *postfixLogfilePath, - journal, - *logUnsupportedLines, - ) - if err != nil { - log.Fatalf("Failed to create PostfixExporter: %s", err) - } - prometheus.MustRegister(exporter) - - http.Handle(*metricsPath, promhttp.Handler()) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - _, err = w.Write([]byte(` - - Postfix Exporter - -

Postfix Exporter

-

Metrics

- - `)) - if err != nil { - panic(err) - } - }) - ctx, cancelFunc := context.WithCancel(context.Background()) - defer cancelFunc() - go exporter.StartMetricCollection(ctx) - log.Print("Listening on ", *listenAddress) - log.Fatal(http.ListenAndServe(*listenAddress, nil)) -} From 30711892c6405b3e61f57b7cafc109826dafeda9 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 19 Feb 2020 18:11:52 +0100 Subject: [PATCH 22/23] added go.sum --- go.sum | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 go.sum diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bea5d93 --- /dev/null +++ b/go.sum @@ -0,0 +1,111 @@ +github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI= +github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/coreos/go-systemd/v22 v22.0.0 h1:XJIw/+VlJ+87J+doOxznsAWIdmWuViOVhkQamW5YV28= +github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.4.1 h1:FFSuS004yOQEtDdTq+TAOLP5xUq63KqAFYyOi8zA+Y8= +github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 2e1ca8fd52cbb00ca9e201d9ea3f0191ec6df66d Mon Sep 17 00:00:00 2001 From: Per Abich Date: Wed, 19 Feb 2020 18:18:31 +0100 Subject: [PATCH 23/23] ran "go mod tidy" after merge --- go.mod | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 9eba737..3d5e663 100644 --- a/go.mod +++ b/go.mod @@ -10,14 +10,6 @@ require ( github.com/prometheus/client_golang v1.4.1 github.com/prometheus/client_model v0.2.0 github.com/stretchr/testify v1.4.0 - github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect - github.com/fsnotify/fsnotify v1.4.7 // indirect - github.com/hpcloud/tail v1.0.0 - github.com/prometheus/client_golang v0.9.2 - github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect - github.com/prometheus/common v0.2.0 // indirect - github.com/prometheus/procfs v0.0.0-20190219184716-e4d4a2206da0 // indirect - github.com/stretchr/testify v1.3.0 // indirect - golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 // indirect + gopkg.in/fsnotify.v1 v1.4.7 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect )