1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +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

@@ -8,7 +8,6 @@ package queue
import (
"context"
"encoding/base64"
"expvar"
"fmt"
"math/rand"
"os"
@@ -23,6 +22,7 @@ import (
"blitiri.com.ar/go/chasquid/internal/aliases"
"blitiri.com.ar/go/chasquid/internal/courier"
"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/protoio"
"blitiri.com.ar/go/chasquid/internal/set"
@@ -54,10 +54,14 @@ var (
// Exported variables.
var (
putCount = expvar.NewInt("chasquid/queue/putCount")
itemsWritten = expvar.NewInt("chasquid/queue/itemsWritten")
dsnQueued = expvar.NewInt("chasquid/queue/dsnQueued")
deliverAttempts = expvar.NewMap("chasquid/queue/deliverAttempts")
putCount = expvarom.NewInt("chasquid/queue/putCount",
"count of envelopes attempted to be put in the queue")
itemsWritten = expvarom.NewInt("chasquid/queue/itemsWritten",
"count of items the queue wrote to disk")
dsnQueued = expvarom.NewInt("chasquid/queue/dsnQueued",
"count of DSNs that we generated (queued)")
deliverAttempts = expvarom.NewMap("chasquid/queue/deliverAttempts",
"recipient_type", "attempts to deliver mail, by recipient type")
)
// Channel used to get random IDs for items in the queue.