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:
@@ -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.
|
||||
|
||||
@@ -55,6 +55,13 @@ fetch http://localhost:1099/debug/config .data-A/dbg-config \
|
||||
|| fail "failed to fetch /debug/config"
|
||||
fetch http://localhost:1099/404 .data-A/dbg-404 \
|
||||
&& fail "fetch /404 worked, should have failed"
|
||||
fetch http://localhost:1099/metrics .data-A/metrics \
|
||||
&& linesgt10 .data-A/metrics \
|
||||
|| fail "failed to fetch /metrics"
|
||||
|
||||
# Quick sanity-check of the /metrics page, just in case.
|
||||
grep -q '^chasquid_queue_itemsWritten [0-9]\+$' .data-A/metrics \
|
||||
|| fail "A /metrics is missing the chasquid_queue_itemsWritten counter"
|
||||
|
||||
# Wait until one of them has noticed and stopped the loop.
|
||||
while sleep 0.1; do
|
||||
|
||||
Reference in New Issue
Block a user