From 9d68a37a199ac4594505e3ee75fb35ed2c769829 Mon Sep 17 00:00:00 2001 From: Phil Winder Date: Mon, 13 Mar 2017 13:46:53 +0000 Subject: [PATCH] Add service name to prometheus labels --- cmd/cataloguesvc/main.go | 1 + middleware/instrument.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/cataloguesvc/main.go b/cmd/cataloguesvc/main.go index 67b176ac..cee10a68 100644 --- a/cmd/cataloguesvc/main.go +++ b/cmd/cataloguesvc/main.go @@ -112,6 +112,7 @@ func main() { middleware.Instrument{ Duration: middleware.HTTPLatency, RouteMatcher: router, + Service: ServiceName, }, } diff --git a/middleware/instrument.go b/middleware/instrument.go index 3dfafb62..3ec1b921 100644 --- a/middleware/instrument.go +++ b/middleware/instrument.go @@ -17,7 +17,7 @@ var ( Name: "request_duration_seconds", Help: "Time (in seconds) spent serving HTTP requests.", Buckets: prometheus.DefBuckets, - }, []string{"method", "route", "status_code"}) + }, []string{"service", "method", "route", "status_code"}) ) func init() { @@ -33,6 +33,7 @@ type RouteMatcher interface { type Instrument struct { RouteMatcher RouteMatcher Duration *prometheus.HistogramVec + Service string } // Wrap implements middleware.Interface @@ -45,7 +46,7 @@ func (i Instrument) Wrap(next http.Handler) http.Handler { status = strconv.Itoa(interceptor.Code) took = time.Since(begin) ) - i.Duration.WithLabelValues(r.Method, route, status).Observe(took.Seconds()) + i.Duration.WithLabelValues(i.Service, r.Method, route, status).Observe(took.Seconds()) }) }