feat(oohelperd): add prometheus metrics (#897)
Closes https://github.com/ooni/probe/issues/2183 While there, avoid exposing nil values for optional fields of the THResponse struct (i.e., "ip_info" and "tls_handshake"). While there, fix `measurexlite`'s `OperationLogger` test and make it deterministic rather than racy.
This commit is contained in:
parent
4241ee4bc1
commit
dcdd8fb712
7 changed files with 98 additions and 5 deletions
45
internal/cmd/oohelperd/metrics.go
Normal file
45
internal/cmd/oohelperd/metrics.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package main
|
||||
|
||||
//
|
||||
// Metrics definitions
|
||||
//
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
// metricRequestsTotal counts the total number of requests
|
||||
metricRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "oohelperd_requests_total",
|
||||
Help: "The total number of processed requests",
|
||||
})
|
||||
|
||||
// metricRequestsByStatusCode counts the number of requests that
|
||||
// have returned a given status code to the caller.
|
||||
metricRequestsByStatusCode = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "oohelperd_requests_by_status_code",
|
||||
Help: "Total number of processed requests by status code",
|
||||
}, []string{"code"})
|
||||
|
||||
// metricRequestsInflight counts the number of requests currently inflight.
|
||||
metricRequestsInflight = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "oohelperd_requests_inflight",
|
||||
Help: "The number or requests currently inflight",
|
||||
})
|
||||
|
||||
// metricMeasurementTime summarizes the time to perform a measurement.
|
||||
metricMeasurementTime = promauto.NewSummary(prometheus.SummaryOpts{
|
||||
Name: "oohelperd_measurement_time",
|
||||
Help: "Summarizes the time to perform a test-helper measurement (in seconds)",
|
||||
// See https://grafana.com/blog/2022/03/01/how-summary-metrics-work-in-prometheus/
|
||||
Objectives: map[float64]float64{
|
||||
0.25: 0.010, // 0.240 <= φ <= 0.260
|
||||
0.5: 0.010, // 0.490 <= φ <= 0.510
|
||||
0.75: 0.010, // 0.740 <= φ <= 0.760
|
||||
0.9: 0.010, // 0.899 <= φ <= 0.901
|
||||
0.99: 0.001, // 0.989 <= φ <= 0.991
|
||||
},
|
||||
})
|
||||
)
|
||||
Loading…
Reference in a new issue