summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-06-26 16:39:57 +0300
committerWolfy-J <[email protected]>2019-06-26 16:39:57 +0300
commit6508bd2e670017382d5c761c53018f9f49c15ffc (patch)
tree2f821f71424a57295f92265a1df699cb76559f35 /service
parent4968bc66f01922cdf0e5bb6cbf891e99a10bb814 (diff)
custom application metrics
Diffstat (limited to 'service')
-rw-r--r--service/metrics/rpc.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/service/metrics/rpc.go b/service/metrics/rpc.go
index 5d1b8102..b0023d73 100644
--- a/service/metrics/rpc.go
+++ b/service/metrics/rpc.go
@@ -70,3 +70,29 @@ func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
*ok = true
return nil
}
+
+// Set the metric value (only for gaude).
+func (rpc *rpcServer) Set(m *Metric, ok *bool) error {
+ c := rpc.svc.Collector(m.Name)
+ if c == nil {
+ return fmt.Errorf("undefined collector `%s`", m.Name)
+ }
+
+ switch c.(type) {
+ case prometheus.Gauge:
+ c.(prometheus.Gauge).Set(m.Value)
+
+ case *prometheus.GaugeVec:
+ if len(m.Labels) == 0 {
+ return fmt.Errorf("required labels for collector `%s`", m.Name)
+ }
+
+ c.(*prometheus.GaugeVec).WithLabelValues(m.Labels...).Set(m.Value)
+
+ default:
+ return fmt.Errorf("collector `%s` is not `gauge` type", m.Name)
+ }
+
+ *ok = true
+ return nil
+}