1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-22 15:27: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

@@ -23,10 +23,17 @@ mkdir -p .coverage
export COVER_DIR="$PWD/.coverage"
# Normal go tests.
go test -tags coverage \
-covermode=count \
-coverprofile="$COVER_DIR/pkg-tests.out"\
-coverpkg=./... ./...
# We have to run them one by one because the expvar registration causes
# the single-binary tests to fail: cross-package expvars confuse the expvarom
# tests, which don't expect any expvars to exists besides the one registered
# in the tests themselves.
for pkg in $(go list ./... | grep -v chasquid/cmd/); do
OUT_FILE="$COVER_DIR/pkg-`echo $pkg | sed s+/+_+g`.out"
go test -tags coverage \
-covermode=count \
-coverprofile="$OUT_FILE" \
-coverpkg=./... $pkg
done
# Integration tests.
# Will run in coverage mode due to $COVER_DIR being set.