micro-meter-prometheus/summary.go
Vasiliy Tolstov d4472e1ab2
Some checks failed
codeql / analyze (go) (push) Failing after 49s
build / test (push) Failing after 4m54s
build / lint (push) Successful in 9m28s
partially fix race cond
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-11-08 15:27:05 +03:00

27 lines
503 B
Go

package prometheus
import (
"sync/atomic"
"time"
dto "github.com/prometheus/client_model/go"
)
type prometheusSummary struct {
name string
c *dto.Metric
sampleCount uint64
SampleSum float64
}
func (c *prometheusSummary) Update(n float64) {
atomic.AddUint64(&(c.sampleCount), 1)
addFloat64(&(c.SampleSum), n)
}
func (c *prometheusSummary) UpdateDuration(t time.Time) {
n := time.Since(t).Seconds()
atomic.AddUint64(&(c.sampleCount), 1)
addFloat64(&(c.SampleSum), n)
}