|
|
|
@ -3,7 +3,6 @@ package metric
|
|
|
|
|
import (
|
|
|
|
|
prom "github.com/prometheus/client_golang/prometheus"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/proc"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/prometheus"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
@ -36,13 +35,12 @@ func NewGaugeVec(cfg *GaugeVecOpts) GaugeVec {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec := prom.NewGaugeVec(
|
|
|
|
|
prom.GaugeOpts{
|
|
|
|
|
Namespace: cfg.Namespace,
|
|
|
|
|
Subsystem: cfg.Subsystem,
|
|
|
|
|
Name: cfg.Name,
|
|
|
|
|
Help: cfg.Help,
|
|
|
|
|
}, cfg.Labels)
|
|
|
|
|
vec := prom.NewGaugeVec(prom.GaugeOpts{
|
|
|
|
|
Namespace: cfg.Namespace,
|
|
|
|
|
Subsystem: cfg.Subsystem,
|
|
|
|
|
Name: cfg.Name,
|
|
|
|
|
Help: cfg.Help,
|
|
|
|
|
}, cfg.Labels)
|
|
|
|
|
prom.MustRegister(vec)
|
|
|
|
|
gv := &promGaugeVec{
|
|
|
|
|
gauge: vec,
|
|
|
|
@ -54,42 +52,34 @@ func NewGaugeVec(cfg *GaugeVecOpts) GaugeVec {
|
|
|
|
|
return gv
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gv *promGaugeVec) Set(v float64, labels ...string) {
|
|
|
|
|
if !prometheus.Enabled() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Set(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gv *promGaugeVec) Inc(labels ...string) {
|
|
|
|
|
if !prometheus.Enabled() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Inc()
|
|
|
|
|
func (gv *promGaugeVec) Add(v float64, labels ...string) {
|
|
|
|
|
update(func() {
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Add(v)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gv *promGaugeVec) Dec(labels ...string) {
|
|
|
|
|
if !prometheus.Enabled() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Dec()
|
|
|
|
|
update(func() {
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Dec()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gv *promGaugeVec) Add(v float64, labels ...string) {
|
|
|
|
|
if !prometheus.Enabled() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
func (gv *promGaugeVec) Inc(labels ...string) {
|
|
|
|
|
update(func() {
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Inc()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Add(v)
|
|
|
|
|
func (gv *promGaugeVec) Set(v float64, labels ...string) {
|
|
|
|
|
update(func() {
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Set(v)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gv *promGaugeVec) Sub(v float64, labels ...string) {
|
|
|
|
|
if !prometheus.Enabled() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Sub(v)
|
|
|
|
|
update(func() {
|
|
|
|
|
gv.gauge.WithLabelValues(labels...).Sub(v)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (gv *promGaugeVec) close() bool {
|
|
|
|
|