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

@@ -9,6 +9,7 @@ import (
"time"
"blitiri.com.ar/go/chasquid/internal/config"
"blitiri.com.ar/go/chasquid/internal/expvarom"
"blitiri.com.ar/go/log"
"google.golang.org/protobuf/encoding/prototext"
@@ -45,6 +46,7 @@ func launchMonitoringServer(conf *config.Config) {
}
})
http.HandleFunc("/metrics", expvarom.MetricsHandler)
http.HandleFunc("/debug/flags", debugFlagsHandler)
http.HandleFunc("/debug/config", debugConfigHandler(conf))
@@ -90,8 +92,12 @@ os hostname <i>{{.Hostname}}</i><p>
<ul>
<li><a href="/debug/requests?exp=1">requests (short-lived)</a>
<li><a href="/debug/events?exp=1">events (long-lived)</a>
<li><a href="/debug/vars">exported variables</a>
<small><a href="https://golang.org/pkg/expvar/">(ref)</a></small>
<li><a href="https://blitiri.com.ar/p/chasquid/monitoring/#variables">
exported variables</a>:
<a href="/debug/vars">expvar</a>
<small><a href="https://golang.org/pkg/expvar/">(ref)</a></small>,
<a href="/metrics">openmetrics</a>
<small><a href="https://openmetrics.io/">(ref)</a></small>
</ul>
<li>execution
<ul>