-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogram.go
50 lines (44 loc) · 1.13 KB
/
histogram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package metric
import (
"github.com/prometheus/client_golang/prometheus"
)
// HistogramVecOpts is histogram vector opts.
type HistogramVecOpts struct {
Namespace string
Subsystem string
Name string
Help string
Labels []string
Buckets []float64
}
// HistogramVec gauge vec.
type HistogramVec interface {
// Observe adds a single observation to the histogram.
Observe(v int64, labels ...string)
}
// Histogram prom histogram collection.
type promHistogramVec struct {
histogram *prometheus.HistogramVec
}
// NewHistogramVec new a histogram vec.
func NewHistogramVec(cfg *HistogramVecOpts) HistogramVec {
if cfg == nil {
return nil
}
vec := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: cfg.Namespace,
Subsystem: cfg.Subsystem,
Name: cfg.Name,
Help: cfg.Help,
Buckets: cfg.Buckets,
}, cfg.Labels)
prometheus.MustRegister(vec)
return &promHistogramVec{
histogram: vec,
}
}
// Timing adds a single observation to the histogram.
func (histogram *promHistogramVec) Observe(v int64, labels ...string) {
histogram.histogram.WithLabelValues(labels...).Observe(float64(v))
}