2024-10-06 13:45:33 +03:00
|
|
|
package prometheus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
dto "github.com/prometheus/client_model/go"
|
|
|
|
)
|
|
|
|
|
|
|
|
type prometheusSummary struct {
|
2024-11-08 15:27:05 +03:00
|
|
|
name string
|
|
|
|
c *dto.Metric
|
|
|
|
sampleCount uint64
|
|
|
|
SampleSum float64
|
2024-10-06 13:45:33 +03:00
|
|
|
}
|
|
|
|
|
2024-11-08 15:27:05 +03:00
|
|
|
func (c *prometheusSummary) Update(n float64) {
|
|
|
|
atomic.AddUint64(&(c.sampleCount), 1)
|
|
|
|
addFloat64(&(c.SampleSum), n)
|
2024-10-06 13:45:33 +03:00
|
|
|
}
|
|
|
|
|
2024-11-08 15:27:05 +03:00
|
|
|
func (c *prometheusSummary) UpdateDuration(t time.Time) {
|
|
|
|
n := time.Since(t).Seconds()
|
|
|
|
atomic.AddUint64(&(c.sampleCount), 1)
|
|
|
|
addFloat64(&(c.SampleSum), n)
|
2024-10-06 13:45:33 +03:00
|
|
|
}
|