-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_gauge.go
54 lines (44 loc) · 1.36 KB
/
db_gauge.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
51
52
53
54
package prometheus_utils
import (
"github.com/prometheus/client_golang/prometheus"
)
// gauge is a struct that allows to add values
type dbGauge struct {
gaugeVec *prometheus.GaugeVec
}
var _ Gauge = (*dbGauge)(nil)
func NewDBGauge(namespace, subsystem, service, host, dbName string) *dbGauge {
gaugeVec := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "gauge",
Help: "What is the value of the parameter.",
ConstLabels: prometheus.Labels{
"namespace": namespace,
"subsystem": subsystem,
"service": service,
"host": host,
"db": dbName,
},
},
[]string{"value_name"},
)
prometheus.MustRegister(gaugeVec)
return &dbGauge{
gaugeVec: gaugeVec,
}
}
// Add function adds a given value to the gauge
func (g *dbGauge) Add(valueName string, value float64) {
g.gaugeVec.WithLabelValues(valueName).Add(value)
}
// Add function adds a given value to the gauge
func (g *dbGauge) AddWithLabelValues(labelValues *[]string, value float64) {
g.gaugeVec.WithLabelValues((*labelValues)...).Add(value)
}
// Set function sets a given value to the gauge
func (g *dbGauge) Set(valueName string, value float64) {
g.gaugeVec.WithLabelValues(valueName).Set(value)
}
// Set function sets a given value to the gauge
func (g *dbGauge) SetWithLabelValues(labelValues *[]string, value float64) {
g.gaugeVec.WithLabelValues((*labelValues)...).Set(value)
}