track http status codes in metrics
This commit is contained in:
@@ -7,3 +7,7 @@ import (
|
||||
func HTTPLatency(path string, dur time.Duration) {
|
||||
httpReqLat.WithLabelValues(path).Observe(float64(dur) / float64(time.Millisecond))
|
||||
}
|
||||
|
||||
func HTTPCode(path string, status string) {
|
||||
httpStatus.WithLabelValues(path, status).Inc()
|
||||
}
|
||||
|
||||
@@ -21,11 +21,22 @@ var (
|
||||
},
|
||||
[]string{"path"},
|
||||
)
|
||||
|
||||
httpStatus = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "hwt_http_requests_total",
|
||||
Help: "How many HTTP requests processed, partitioned by status code and HTTP method.",
|
||||
},
|
||||
[]string{"path", "code"},
|
||||
)
|
||||
)
|
||||
|
||||
func RegisterPromMetrics() error {
|
||||
if err := prometheus.Register(httpReqLat); err != nil {
|
||||
return errors.Wrap(err, "registering http request latency")
|
||||
}
|
||||
if err := prometheus.Register(httpStatus); err != nil {
|
||||
return errors.Wrap(err, "registering http request status")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user