Explorar o código

Add NewRegistered* for each standard metric.

Richard Crowley %!s(int64=12) %!d(string=hai) anos
pai
achega
2f728cc325
Modificáronse 4 ficheiros con 40 adicións e 0 borrados
  1. 10 0
      gauge.go
  2. 10 0
      histogram.go
  3. 10 0
      meter.go
  4. 10 0
      timer.go

+ 10 - 0
gauge.go

@@ -19,6 +19,16 @@ func NewGauge() Gauge {
 	return &StandardGauge{0}
 }
 
+// Create and register a new Gauge.
+func NewRegisteredGauge(name string, r Registry) Gauge {
+	c := NewGauge()
+	if nil == r {
+		r = DefaultRegistry
+	}
+	r.Register(name, c)
+	return c
+}
+
 // No-op Gauge.
 type NilGauge struct{}
 

+ 10 - 0
histogram.go

@@ -39,6 +39,16 @@ func NewHistogram(s Sample) Histogram {
 	}
 }
 
+// Create and register a new Histogram.
+func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram {
+	c := NewHistogram(s)
+	if nil == r {
+		r = DefaultRegistry
+	}
+	r.Register(name, c)
+	return c
+}
+
 // No-op Histogram.
 type NilHistogram struct{}
 

+ 10 - 0
meter.go

@@ -31,6 +31,16 @@ func NewMeter() Meter {
 	return m
 }
 
+// Create and register a new Meter.
+func NewRegisteredMeter(name string, r Registry) Meter {
+	c := NewMeter()
+	if nil == r {
+		r = DefaultRegistry
+	}
+	r.Register(name, c)
+	return c
+}
+
 // No-op Meter.
 type NilMeter struct{}
 

+ 10 - 0
timer.go

@@ -31,6 +31,16 @@ func NewCustomTimer(h Histogram, m Meter) Timer {
 	return &StandardTimer{h, m}
 }
 
+// Create and register a new Timer.
+func NewRegisteredTimer(name string, r Registry) Timer {
+	c := NewTimer()
+	if nil == r {
+		r = DefaultRegistry
+	}
+	r.Register(name, c)
+	return c
+}
+
 // Create a new timer with a standard histogram and meter.  The histogram
 // will use an exponentially-decaying sample with the same reservoir size
 // and alpha as UNIX load averages.