diff --git a/prometheus/timer.go b/prometheus/timer.go index f15aba2..d6e0d11 100644 --- a/prometheus/timer.go +++ b/prometheus/timer.go @@ -21,10 +21,15 @@ type Observer interface { Observe(float64) } +type observerFunc func(float64) + +func (o observerFunc) Observe(value float64) { + o(value) +} + type Timer struct { begin time.Time observer Observer - gauge Gauge } func StartTimer() *Timer { @@ -37,7 +42,7 @@ func (t *Timer) With(o Observer) *Timer { } func (t *Timer) WithGauge(g Gauge) *Timer { - t.gauge = g + t.observer = observerFunc(g.Set) return t } @@ -45,7 +50,4 @@ func (t *Timer) Stop() { if t.observer != nil { t.observer.Observe(time.Since(t.begin).Seconds()) } - if t.gauge != nil { - t.gauge.Set(time.Since(t.begin).Seconds()) - } }