aboutsummaryrefslogtreecommitdiff
path: root/plugin/metrics/registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/metrics/registry.go')
-rw-r--r--plugin/metrics/registry.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugin/metrics/registry.go b/plugin/metrics/registry.go
new file mode 100644
index 000000000..2d6a92e0d
--- /dev/null
+++ b/plugin/metrics/registry.go
@@ -0,0 +1,28 @@
+package metrics
+
+import (
+ "sync"
+
+ "github.com/prometheus/client_golang/prometheus"
+)
+
+type reg struct {
+ sync.RWMutex
+ r map[string]*prometheus.Registry
+}
+
+func newReg() *reg { return &reg{r: make(map[string]*prometheus.Registry)} }
+
+// update sets the registry if not already there and returns the input. Or it returns
+// a previous set value.
+func (r *reg) getOrSet(addr string, pr *prometheus.Registry) *prometheus.Registry {
+ r.Lock()
+ defer r.Unlock()
+
+ if v, ok := r.r[addr]; ok {
+ return v
+ }
+
+ r.r[addr] = pr
+ return pr
+}