32 lines
1000 B
Go
32 lines
1000 B
Go
package server
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
httpInFlight = promauto.NewGauge(prometheus.GaugeOpts{
|
|
Name: "telemt_gateway_http_in_flight",
|
|
Help: "Current requests being served.",
|
|
})
|
|
httpRequests = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Name: "telemt_gateway_http_requests_total",
|
|
Help: "HTTP requests by status, method, alias.",
|
|
}, []string{"code", "method", "alias"})
|
|
httpDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Name: "telemt_gateway_http_request_duration_seconds",
|
|
Help: "Request duration in seconds.",
|
|
Buckets: prometheus.DefBuckets,
|
|
}, []string{"method", "alias"})
|
|
)
|
|
|
|
func observeRequest(method, alias string, status int, started time.Time) {
|
|
httpInFlight.Dec()
|
|
httpRequests.WithLabelValues(strconv.Itoa(status), method, alias).Inc()
|
|
httpDuration.WithLabelValues(method, alias).Observe(time.Since(started).Seconds())
|
|
}
|