track http status codes in metrics

This commit is contained in:
sm
2018-01-26 18:07:20 -08:00
parent cf10974419
commit 5997dc44d8
4 changed files with 24 additions and 2 deletions
+4
View File
@@ -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()
}
+11
View File
@@ -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
}