chore!: Standardize prometheus time metrics to seconds (#5709)

* chore!: Standardize prometheus time metrics to seconds
* Update prometheus docs
This commit is contained in:
Steven Masley
2023-01-13 11:15:25 -06:00
committed by GitHub
parent f91a0d8c37
commit f76ef98a32
5 changed files with 650 additions and 524 deletions

View File

@ -14,10 +14,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)
func durationToFloatMs(d time.Duration) float64 {
return float64(d.Milliseconds())
}
func Prometheus(register prometheus.Registerer) func(http.Handler) http.Handler {
factory := promauto.With(register)
requestsProcessed := factory.NewCounterVec(prometheus.CounterOpts{
@ -30,34 +26,34 @@ func Prometheus(register prometheus.Registerer) func(http.Handler) http.Handler
Namespace: "coderd",
Subsystem: "api",
Name: "concurrent_requests",
Help: "The number of concurrent API requests",
Help: "The number of concurrent API requests.",
})
websocketsConcurrent := factory.NewGauge(prometheus.GaugeOpts{
Namespace: "coderd",
Subsystem: "api",
Name: "concurrent_websockets",
Help: "The total number of concurrent API websockets",
Help: "The total number of concurrent API websockets.",
})
websocketsDist := factory.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "coderd",
Subsystem: "api",
Name: "websocket_durations_ms",
Help: "Websocket duration distribution of requests in milliseconds",
Name: "websocket_durations_seconds",
Help: "Websocket duration distribution of requests in seconds.",
Buckets: []float64{
durationToFloatMs(01 * time.Millisecond),
durationToFloatMs(01 * time.Second),
durationToFloatMs(01 * time.Minute),
durationToFloatMs(01 * time.Hour),
durationToFloatMs(15 * time.Hour),
durationToFloatMs(30 * time.Hour),
0.001, // 1ms
1,
60, // 1 minute
60 * 60, // 1 hour
60 * 60 * 15, // 15 hours
60 * 60 * 30, // 30 hours
},
}, []string{"path"})
requestsDist := factory.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "coderd",
Subsystem: "api",
Name: "request_latencies_ms",
Help: "Latency distribution of requests in milliseconds",
Buckets: []float64{1, 5, 10, 25, 50, 100, 500, 1000, 5000, 10000, 30000},
Name: "request_latencies_seconds",
Help: "Latency distribution of requests in seconds.",
Buckets: []float64{0.001, 0.005, 0.010, 0.025, 0.050, 0.100, 0.500, 1, 5, 10, 30},
}, []string{"method", "path"})
return func(next http.Handler) http.Handler {
@ -98,7 +94,7 @@ func Prometheus(register prometheus.Registerer) func(http.Handler) http.Handler
statusStr := strconv.Itoa(sw.Status)
requestsProcessed.WithLabelValues(statusStr, method, path).Inc()
dist.WithLabelValues(distOpts...).Observe(float64(time.Since(start)) / 1e6)
dist.WithLabelValues(distOpts...).Observe(time.Since(start).Seconds())
})
}
}