...
1 package metrics
2
3 import "github.com/prometheus/client_golang/prometheus"
4
5
6 type Gauge interface {
7 Inc(...float64)
8 Dec(...float64)
9
10
11 Add(float64)
12
13
14 Set(float64)
15 }
16
17
18 type LabeledGauge interface {
19 WithValues(labels ...string) Gauge
20 }
21
22 type labeledGauge struct {
23 pg *prometheus.GaugeVec
24 }
25
26 func (lg *labeledGauge) WithValues(labels ...string) Gauge {
27 return &gauge{pg: lg.pg.WithLabelValues(labels...)}
28 }
29
30 func (lg *labeledGauge) Describe(c chan<- *prometheus.Desc) {
31 lg.pg.Describe(c)
32 }
33
34 func (lg *labeledGauge) Collect(c chan<- prometheus.Metric) {
35 lg.pg.Collect(c)
36 }
37
38 type gauge struct {
39 pg prometheus.Gauge
40 }
41
42 func (g *gauge) Inc(vs ...float64) {
43 if len(vs) == 0 {
44 g.pg.Inc()
45 }
46
47 g.Add(sumFloat64(vs...))
48 }
49
50 func (g *gauge) Dec(vs ...float64) {
51 if len(vs) == 0 {
52 g.pg.Dec()
53 }
54
55 g.Add(-sumFloat64(vs...))
56 }
57
58 func (g *gauge) Add(v float64) {
59 g.pg.Add(v)
60 }
61
62 func (g *gauge) Set(v float64) {
63 g.pg.Set(v)
64 }
65
66 func (g *gauge) Describe(c chan<- *prometheus.Desc) {
67 g.pg.Describe(c)
68 }
69
70 func (g *gauge) Collect(c chan<- prometheus.Metric) {
71 g.pg.Collect(c)
72 }
73
View as plain text