forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics.go
More file actions
32 lines (28 loc) · 719 Bytes
/
metrics.go
File metadata and controls
32 lines (28 loc) · 719 Bytes
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
package test
import (
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
func GetCounterValue(metric prometheus.Counter) (float64, error) {
var m = &dto.Metric{}
err := metric.Write(m)
if err != nil {
return 0, err
}
return m.Counter.GetValue(), nil
}
func GetGaugeValue(metric prometheus.Gauge) (float64, error) {
var m = &dto.Metric{}
err := metric.Write(m)
if err != nil {
return 0, err
}
return m.Gauge.GetValue(), nil
}
func GetCounterVecValue(metric *prometheus.CounterVec, label string) (float64, error) {
var m = &dto.Metric{}
if err := metric.WithLabelValues(label).Write(m); err != nil {
return 0, err
}
return m.Counter.GetValue(), nil
}