|
|
@@ -43,7 +43,7 @@ type Registry interface {
|
|
|
|
|
|
// The standard implementation of a Registry is a set of mutex-protected
|
|
|
// maps of names to metrics.
|
|
|
-type registry struct {
|
|
|
+type StandardRegistry struct {
|
|
|
mutex *sync.Mutex
|
|
|
counters map[string]Counter
|
|
|
gauges map[string]Gauge
|
|
|
@@ -55,7 +55,7 @@ type registry struct {
|
|
|
|
|
|
// Create a new registry.
|
|
|
func NewRegistry() Registry {
|
|
|
- return ®istry {
|
|
|
+ return &StandardRegistry {
|
|
|
&sync.Mutex{},
|
|
|
make(map[string]Counter),
|
|
|
make(map[string]Gauge),
|
|
|
@@ -67,49 +67,49 @@ func NewRegistry() Registry {
|
|
|
}
|
|
|
|
|
|
// Call the given function for each registered counter.
|
|
|
-func (r *registry) EachCounter(f func(string, Counter)) {
|
|
|
+func (r *StandardRegistry) EachCounter(f func(string, Counter)) {
|
|
|
r.mutex.Lock()
|
|
|
for name, c := range r.counters { f(name, c) }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Call the given function for each registered gauge.
|
|
|
-func (r *registry) EachGauge(f func(string, Gauge)) {
|
|
|
+func (r *StandardRegistry) EachGauge(f func(string, Gauge)) {
|
|
|
r.mutex.Lock()
|
|
|
for name, g := range r.gauges { f(name, g) }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Call the given function for each registered healthcheck.
|
|
|
-func (r *registry) EachHealthcheck(f func(string, Healthcheck)) {
|
|
|
+func (r *StandardRegistry) EachHealthcheck(f func(string, Healthcheck)) {
|
|
|
r.mutex.Lock()
|
|
|
for name, h := range r.healthchecks { f(name, h) }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Call the given function for each registered histogram.
|
|
|
-func (r *registry) EachHistogram(f func(string, Histogram)) {
|
|
|
+func (r *StandardRegistry) EachHistogram(f func(string, Histogram)) {
|
|
|
r.mutex.Lock()
|
|
|
for name, h := range r.histograms { f(name, h) }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Call the given function for each registered meter.
|
|
|
-func (r *registry) EachMeter(f func(string, Meter)) {
|
|
|
+func (r *StandardRegistry) EachMeter(f func(string, Meter)) {
|
|
|
r.mutex.Lock()
|
|
|
for name, m := range r.meters { f(name, m) }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Call the given function for each registered timer.
|
|
|
-func (r *registry) EachTimer(f func(string, Timer)) {
|
|
|
+func (r *StandardRegistry) EachTimer(f func(string, Timer)) {
|
|
|
r.mutex.Lock()
|
|
|
for name, t := range r.timers { f(name, t) }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Get the Counter by the given name or nil if none is registered.
|
|
|
-func (r *registry) GetCounter(name string) Counter {
|
|
|
+func (r *StandardRegistry) GetCounter(name string) Counter {
|
|
|
r.mutex.Lock()
|
|
|
c := r.counters[name]
|
|
|
r.mutex.Unlock()
|
|
|
@@ -117,7 +117,7 @@ func (r *registry) GetCounter(name string) Counter {
|
|
|
}
|
|
|
|
|
|
// Get the Gauge by the given name or nil if none is registered.
|
|
|
-func (r *registry) GetGauge(name string) Gauge {
|
|
|
+func (r *StandardRegistry) GetGauge(name string) Gauge {
|
|
|
r.mutex.Lock()
|
|
|
g := r.gauges[name]
|
|
|
r.mutex.Unlock()
|
|
|
@@ -125,7 +125,7 @@ func (r *registry) GetGauge(name string) Gauge {
|
|
|
}
|
|
|
|
|
|
// Get the Healthcheck by the given name or nil if none is registered.
|
|
|
-func (r *registry) GetHealthcheck(name string) Healthcheck {
|
|
|
+func (r *StandardRegistry) GetHealthcheck(name string) Healthcheck {
|
|
|
r.mutex.Lock()
|
|
|
h := r.healthchecks[name]
|
|
|
r.mutex.Unlock()
|
|
|
@@ -133,7 +133,7 @@ func (r *registry) GetHealthcheck(name string) Healthcheck {
|
|
|
}
|
|
|
|
|
|
// Get the Histogram by the given name or nil if none is registered.
|
|
|
-func (r *registry) GetHistogram(name string) Histogram {
|
|
|
+func (r *StandardRegistry) GetHistogram(name string) Histogram {
|
|
|
r.mutex.Lock()
|
|
|
h := r.histograms[name]
|
|
|
r.mutex.Unlock()
|
|
|
@@ -141,7 +141,7 @@ func (r *registry) GetHistogram(name string) Histogram {
|
|
|
}
|
|
|
|
|
|
// Get the Meter by the given name or nil if none is registered.
|
|
|
-func (r *registry) GetMeter(name string) Meter {
|
|
|
+func (r *StandardRegistry) GetMeter(name string) Meter {
|
|
|
r.mutex.Lock()
|
|
|
m := r.meters[name]
|
|
|
r.mutex.Unlock()
|
|
|
@@ -149,7 +149,7 @@ func (r *registry) GetMeter(name string) Meter {
|
|
|
}
|
|
|
|
|
|
// Get the Timer by the given name or nil if none is registered.
|
|
|
-func (r *registry) GetTimer(name string) Timer {
|
|
|
+func (r *StandardRegistry) GetTimer(name string) Timer {
|
|
|
r.mutex.Lock()
|
|
|
t := r.timers[name]
|
|
|
r.mutex.Unlock()
|
|
|
@@ -157,91 +157,91 @@ func (r *registry) GetTimer(name string) Timer {
|
|
|
}
|
|
|
|
|
|
// Register the given Counter under the given name.
|
|
|
-func (r *registry) RegisterCounter(name string, c Counter) {
|
|
|
+func (r *StandardRegistry) RegisterCounter(name string, c Counter) {
|
|
|
r.mutex.Lock()
|
|
|
r.counters[name] = c
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Register the given Gauge under the given name.
|
|
|
-func (r *registry) RegisterGauge(name string, g Gauge) {
|
|
|
+func (r *StandardRegistry) RegisterGauge(name string, g Gauge) {
|
|
|
r.mutex.Lock()
|
|
|
r.gauges[name] = g
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Register the given Healthcheck under the given name.
|
|
|
-func (r *registry) RegisterHealthcheck(name string, h Healthcheck) {
|
|
|
+func (r *StandardRegistry) RegisterHealthcheck(name string, h Healthcheck) {
|
|
|
r.mutex.Lock()
|
|
|
r.healthchecks[name] = h
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Register the given Histogram under the given name.
|
|
|
-func (r *registry) RegisterHistogram(name string, h Histogram) {
|
|
|
+func (r *StandardRegistry) RegisterHistogram(name string, h Histogram) {
|
|
|
r.mutex.Lock()
|
|
|
r.histograms[name] = h
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Register the given Meter under the given name.
|
|
|
-func (r *registry) RegisterMeter(name string, m Meter) {
|
|
|
+func (r *StandardRegistry) RegisterMeter(name string, m Meter) {
|
|
|
r.mutex.Lock()
|
|
|
r.meters[name] = m
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Register the given Timer under the given name.
|
|
|
-func (r *registry) RegisterTimer(name string, t Timer) {
|
|
|
+func (r *StandardRegistry) RegisterTimer(name string, t Timer) {
|
|
|
r.mutex.Lock()
|
|
|
r.timers[name] = t
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Run all registered healthchecks.
|
|
|
-func (r *registry) RunHealthchecks() {
|
|
|
+func (r *StandardRegistry) RunHealthchecks() {
|
|
|
r.mutex.Lock()
|
|
|
for _, h := range r.healthchecks { h.Check() }
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Unregister the given Counter with the given name.
|
|
|
-func (r *registry) UnregisterCounter(name string) {
|
|
|
+func (r *StandardRegistry) UnregisterCounter(name string) {
|
|
|
r.mutex.Lock()
|
|
|
r.counters[name] = nil, false
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Unregister the given Gauge with the given name.
|
|
|
-func (r *registry) UnregisterGauge(name string) {
|
|
|
+func (r *StandardRegistry) UnregisterGauge(name string) {
|
|
|
r.mutex.Lock()
|
|
|
r.gauges[name] = nil, false
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Unregister the given Healthcheck with the given name.
|
|
|
-func (r *registry) UnregisterHealthcheck(name string) {
|
|
|
+func (r *StandardRegistry) UnregisterHealthcheck(name string) {
|
|
|
r.mutex.Lock()
|
|
|
r.healthchecks[name] = nil, false
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Unregister the given Histogram with the given name.
|
|
|
-func (r *registry) UnregisterHistogram(name string) {
|
|
|
+func (r *StandardRegistry) UnregisterHistogram(name string) {
|
|
|
r.mutex.Lock()
|
|
|
r.histograms[name] = nil, false
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Unregister the given Meter with the given name.
|
|
|
-func (r *registry) UnregisterMeter(name string) {
|
|
|
+func (r *StandardRegistry) UnregisterMeter(name string) {
|
|
|
r.mutex.Lock()
|
|
|
r.meters[name] = nil, false
|
|
|
r.mutex.Unlock()
|
|
|
}
|
|
|
|
|
|
// Unregister the given Timer with the given name.
|
|
|
-func (r *registry) UnregisterTimer(name string) {
|
|
|
+func (r *StandardRegistry) UnregisterTimer(name string) {
|
|
|
r.mutex.Lock()
|
|
|
r.timers[name] = nil, false
|
|
|
r.mutex.Unlock()
|