Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #35 from microservices-demo/monitoring/rationalise…
Browse files Browse the repository at this point in the history
…-prometheus

Add service name to prometheus labels
  • Loading branch information
nustiueudinastea authored Mar 13, 2017
2 parents 057b99c + 9d68a37 commit 4d04796
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/cataloguesvc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
middleware.Instrument{
Duration: middleware.HTTPLatency,
RouteMatcher: router,
Service: ServiceName,
},
}

Expand Down
5 changes: 3 additions & 2 deletions middleware/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -33,6 +33,7 @@ type RouteMatcher interface {
type Instrument struct {
RouteMatcher RouteMatcher
Duration *prometheus.HistogramVec
Service string
}

// Wrap implements middleware.Interface
Expand All @@ -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())
})
}

Expand Down

0 comments on commit 4d04796

Please sign in to comment.