Skip to content

Commit

Permalink
Add Prometheus Gauge with timer
Browse files Browse the repository at this point in the history
Co-authored-by: Jose Luis Lucas <[email protected]>
  • Loading branch information
2 people authored and iknite committed Feb 19, 2019
1 parent bb9ab67 commit 4c045b2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/apihttp/apihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import (
)

var (
funcDuration = promauto.NewGauge(prometheus.GaugeOpts{
Name: "example_function_duration_seconds",
Help: "Duration of the last call of an example function.",
})

requestDuration = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "example_request_duration_seconds",
Help: "Histogram for the runtime of a simple example function.",
Expand Down Expand Up @@ -68,6 +73,9 @@ func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {
timer := prometheus.NewTimer(requestDuration)
defer timer.ObserveDuration()

timer2 := prometheus.NewTimer(prometheus.ObserverFunc(funcDuration.Set))
defer timer2.ObserveDuration()

// Do something here that takes time.
time.Sleep(time.Duration(rand.NormFloat64()*10000+50000) * time.Microsecond)

Expand Down

0 comments on commit 4c045b2

Please sign in to comment.