We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4968bc6 commit 6508bd2Copy full SHA for 6508bd2
service/metrics/rpc.go
@@ -70,3 +70,29 @@ func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
70
*ok = true
71
return nil
72
}
73
+
74
+// Set the metric value (only for gaude).
75
+func (rpc *rpcServer) Set(m *Metric, ok *bool) error {
76
+ c := rpc.svc.Collector(m.Name)
77
+ if c == nil {
78
+ return fmt.Errorf("undefined collector `%s`", m.Name)
79
+ }
80
81
+ switch c.(type) {
82
+ case prometheus.Gauge:
83
+ c.(prometheus.Gauge).Set(m.Value)
84
85
+ case *prometheus.GaugeVec:
86
+ if len(m.Labels) == 0 {
87
+ return fmt.Errorf("required labels for collector `%s`", m.Name)
88
89
90
+ c.(*prometheus.GaugeVec).WithLabelValues(m.Labels...).Set(m.Value)
91
92
+ default:
93
+ return fmt.Errorf("collector `%s` is not `gauge` type", m.Name)
94
95
96
+ *ok = true
97
+ return nil
98
+}
0 commit comments