1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-08 17:51:57 +00:00

monitoring: Add OpenMetrics exporter

This patch makes chasquid's monitoring server expose an OpenMetrics
metrics endpoint.

It adds a new package "expvarom" which implements an HTTP handler that
exports expvar variables in the OpenMetrics text format.

Then, the handler is registered by the monitoring server at /metrics
(where most things expect it to be).

The existing exported variables are also extended with descriptions,
which is optional, but improves the readability of the metrics.
This commit is contained in:
Alberto Bertogli
2020-08-19 20:42:28 +01:00
parent 7e412db19b
commit 7fe42a368a
12 changed files with 447 additions and 154 deletions

View File

@@ -5,7 +5,6 @@ import (
"bytes"
"context"
"crypto/tls"
"expvar"
"flag"
"fmt"
"io"
@@ -25,6 +24,7 @@ import (
"blitiri.com.ar/go/chasquid/internal/auth"
"blitiri.com.ar/go/chasquid/internal/domaininfo"
"blitiri.com.ar/go/chasquid/internal/envelope"
"blitiri.com.ar/go/chasquid/internal/expvarom"
"blitiri.com.ar/go/chasquid/internal/maillog"
"blitiri.com.ar/go/chasquid/internal/normalize"
"blitiri.com.ar/go/chasquid/internal/queue"
@@ -36,13 +36,20 @@ import (
// Exported variables.
var (
commandCount = expvar.NewMap("chasquid/smtpIn/commandCount")
responseCodeCount = expvar.NewMap("chasquid/smtpIn/responseCodeCount")
spfResultCount = expvar.NewMap("chasquid/smtpIn/spfResultCount")
loopsDetected = expvar.NewInt("chasquid/smtpIn/loopsDetected")
tlsCount = expvar.NewMap("chasquid/smtpIn/tlsCount")
slcResults = expvar.NewMap("chasquid/smtpIn/securityLevelChecks")
hookResults = expvar.NewMap("chasquid/smtpIn/hookResults")
commandCount = expvarom.NewMap("chasquid/smtpIn/commandCount",
"command", "count of SMTP commands received, by command")
responseCodeCount = expvarom.NewMap("chasquid/smtpIn/responseCodeCount",
"code", "response codes returned to SMTP commands")
spfResultCount = expvarom.NewMap("chasquid/smtpIn/spfResultCount",
"result", "SPF result count")
loopsDetected = expvarom.NewInt("chasquid/smtpIn/loopsDetected",
"count of loops detected")
tlsCount = expvarom.NewMap("chasquid/smtpIn/tlsCount",
"status", "count of TLS usage in incoming connections")
slcResults = expvarom.NewMap("chasquid/smtpIn/securityLevelChecks",
"result", "incoming security level check results")
hookResults = expvarom.NewMap("chasquid/smtpIn/hookResults",
"result", "count of hook invocations, by result")
)
var (