diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-02-11 22:16:52 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-02-11 22:16:52 +0800 |
commit | b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a (patch) | |
tree | 26e023be6c99a10e82a5a0ebadd1e42cefe9bd3c /Godeps/_workspace/src/github.com/rcrowley/go-metrics | |
parent | b05e472c076d30035233d6a8b5fb3360b236e3ff (diff) | |
download | dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.tar dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.tar.gz dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.tar.bz2 dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.tar.lz dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.tar.xz dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.tar.zst dexon-b019f3ee29ce55c3d515ee8bafe0f4bb14221c0a.zip |
Godeps: update all dependencies to latest code
Diffstat (limited to 'Godeps/_workspace/src/github.com/rcrowley/go-metrics')
30 files changed, 358 insertions, 1583 deletions
diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/.travis.yml b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/.travis.yml new file mode 100644 index 000000000..20aa5d042 --- /dev/null +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/.travis.yml @@ -0,0 +1,14 @@ +language: go + +go: + - 1.2 + - 1.3 + - 1.4 + - 1.5 + +script: + - ./validate.sh + +# this should give us faster builds according to +# http://docs.travis-ci.com/user/migrating-from-legacy/ +sudo: false diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/README.md b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/README.md index e0091a4bd..66ba9cab5 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/README.md +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/README.md @@ -1,7 +1,9 @@ go-metrics ========== -Go port of Coda Hale's Metrics library: <https://github.com/codahale/metrics>. +![travis build status](https://travis-ci.org/rcrowley/go-metrics.svg?branch=master) + +Go port of Coda Hale's Metrics library: <https://github.com/dropwizard/metrics>. Documentation: <http://godoc.org/github.com/rcrowley/go-metrics>. @@ -37,7 +39,7 @@ t.Update(47) Periodically log every metric in human-readable form to standard error: ```go -go metrics.Log(metrics.DefaultRegistry, 60e9, log.New(os.Stderr, "metrics: ", log.Lmicroseconds)) +go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds)) ``` Periodically log every metric in slightly-more-parseable form to syslog: @@ -47,15 +49,23 @@ w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics") go metrics.Syslog(metrics.DefaultRegistry, 60e9, w) ``` -Periodically emit every metric to Graphite: +Periodically emit every metric to Graphite using the [Graphite client](https://github.com/cyberdelia/go-metrics-graphite): ```go + +import "github.com/cyberdelia/go-metrics-graphite" + addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") -go metrics.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr) +go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr) ``` Periodically emit every metric into InfluxDB: +**NOTE:** this has been pulled out of the library due to constant fluctuations +in the InfluxDB API. In fact, all client libraries are on their way out. see +issues [#121](https://github.com/rcrowley/go-metrics/issues/121) and +[#124](https://github.com/rcrowley/go-metrics/issues/124) for progress and details. + ```go import "github.com/rcrowley/go-metrics/influxdb" @@ -67,17 +77,20 @@ go influxdb.Influxdb(metrics.DefaultRegistry, 10e9, &influxdb.Config{ }) ``` -Periodically upload every metric to Librato: +Periodically upload every metric to Librato using the [Librato client](https://github.com/mihasya/go-metrics-librato): + +**Note**: the client included with this repository under the `librato` package +has been deprecated and moved to the repository linked above. ```go -import "github.com/rcrowley/go-metrics/librato" +import "github.com/mihasya/go-metrics-librato" go librato.Librato(metrics.DefaultRegistry, 10e9, // interval "example@example.com", // account owner email address "token", // Librato API token "hostname", // source - []float64{0.95}, // precentiles to send + []float64{0.95}, // percentiles to send time.Millisecond, // time unit ) ``` @@ -90,6 +103,19 @@ import "github.com/rcrowley/go-metrics/stathat" go stathat.Stathat(metrics.DefaultRegistry, 10e9, "example@example.com") ``` +Maintain all metrics along with expvars at `/debug/metrics`: + +This uses the same mechanism as [the official expvar](http://golang.org/pkg/expvar/) +but exposed under `/debug/metrics`, which shows a json representation of all your usual expvars +as well as all your go-metrics. + + +```go +import "github.com/rcrowley/go-metrics/exp" + +exp.Exp(metrics.DefaultRegistry) +``` + Installation ------------ @@ -102,3 +128,12 @@ StatHat support additionally requires their Go client: ```sh go get github.com/stathat/go ``` + +Publishing Metrics +------------------ + +Clients are available for the following destinations: + +* Librato - [https://github.com/mihasya/go-metrics-librato](https://github.com/mihasya/go-metrics-librato) +* Graphite - [https://github.com/cyberdelia/go-metrics-graphite](https://github.com/cyberdelia/go-metrics-graphite) +* InfluxDB - [https://github.com/vrischmann/go-metrics-influxdb](https://github.com/vrischmann/go-metrics-influxdb) diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/counter_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/counter_test.go deleted file mode 100644 index dfb03b4e8..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/counter_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package metrics - -import "testing" - -func BenchmarkCounter(b *testing.B) { - c := NewCounter() - b.ResetTimer() - for i := 0; i < b.N; i++ { - c.Inc(1) - } -} - -func TestCounterClear(t *testing.T) { - c := NewCounter() - c.Inc(1) - c.Clear() - if count := c.Count(); 0 != count { - t.Errorf("c.Count(): 0 != %v\n", count) - } -} - -func TestCounterDec1(t *testing.T) { - c := NewCounter() - c.Dec(1) - if count := c.Count(); -1 != count { - t.Errorf("c.Count(): -1 != %v\n", count) - } -} - -func TestCounterDec2(t *testing.T) { - c := NewCounter() - c.Dec(2) - if count := c.Count(); -2 != count { - t.Errorf("c.Count(): -2 != %v\n", count) - } -} - -func TestCounterInc1(t *testing.T) { - c := NewCounter() - c.Inc(1) - if count := c.Count(); 1 != count { - t.Errorf("c.Count(): 1 != %v\n", count) - } -} - -func TestCounterInc2(t *testing.T) { - c := NewCounter() - c.Inc(2) - if count := c.Count(); 2 != count { - t.Errorf("c.Count(): 2 != %v\n", count) - } -} - -func TestCounterSnapshot(t *testing.T) { - c := NewCounter() - c.Inc(1) - snapshot := c.Snapshot() - c.Inc(1) - if count := snapshot.Count(); 1 != count { - t.Errorf("c.Count(): 1 != %v\n", count) - } -} - -func TestCounterZero(t *testing.T) { - c := NewCounter() - if count := c.Count(); 0 != count { - t.Errorf("c.Count(): 0 != %v\n", count) - } -} - -func TestGetOrRegisterCounter(t *testing.T) { - r := NewRegistry() - NewRegisteredCounter("foo", r).Inc(47) - if c := GetOrRegisterCounter("foo", r); 47 != c.Count() { - t.Fatal(c) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/debug_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/debug_test.go deleted file mode 100644 index 07eb86784..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/debug_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package metrics - -import ( - "runtime" - "runtime/debug" - "testing" - "time" -) - -func BenchmarkDebugGCStats(b *testing.B) { - r := NewRegistry() - RegisterDebugGCStats(r) - b.ResetTimer() - for i := 0; i < b.N; i++ { - CaptureDebugGCStatsOnce(r) - } -} - -func TestDebugGCStatsBlocking(t *testing.T) { - if g := runtime.GOMAXPROCS(0); g < 2 { - t.Skipf("skipping TestDebugGCMemStatsBlocking with GOMAXPROCS=%d\n", g) - return - } - ch := make(chan int) - go testDebugGCStatsBlocking(ch) - var gcStats debug.GCStats - t0 := time.Now() - debug.ReadGCStats(&gcStats) - t1 := time.Now() - t.Log("i++ during debug.ReadGCStats:", <-ch) - go testDebugGCStatsBlocking(ch) - d := t1.Sub(t0) - t.Log(d) - time.Sleep(d) - t.Log("i++ during time.Sleep:", <-ch) -} - -func testDebugGCStatsBlocking(ch chan int) { - i := 0 - for { - select { - case ch <- i: - return - default: - i++ - } - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma.go index 7c152a174..694a1d033 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma.go @@ -77,7 +77,7 @@ func (NilEWMA) Update(n int64) {} // of uncounted events and processes them on each tick. It uses the // sync/atomic package to manage uncounted events. type StandardEWMA struct { - uncounted int64 // /!\ this should be the first member to ensure 64-bit alignment + uncounted int64 // /!\ this should be the first member to ensure 64-bit alignment alpha float64 rate float64 init bool diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma_test.go deleted file mode 100644 index 0430fbd24..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/ewma_test.go +++ /dev/null @@ -1,225 +0,0 @@ -package metrics - -import "testing" - -func BenchmarkEWMA(b *testing.B) { - a := NewEWMA1() - b.ResetTimer() - for i := 0; i < b.N; i++ { - a.Update(1) - a.Tick() - } -} - -func TestEWMA1(t *testing.T) { - a := NewEWMA1() - a.Update(3) - a.Tick() - if rate := a.Rate(); 0.6 != rate { - t.Errorf("initial a.Rate(): 0.6 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.22072766470286553 != rate { - t.Errorf("1 minute a.Rate(): 0.22072766470286553 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.08120116994196772 != rate { - t.Errorf("2 minute a.Rate(): 0.08120116994196772 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.029872241020718428 != rate { - t.Errorf("3 minute a.Rate(): 0.029872241020718428 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.01098938333324054 != rate { - t.Errorf("4 minute a.Rate(): 0.01098938333324054 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.004042768199451294 != rate { - t.Errorf("5 minute a.Rate(): 0.004042768199451294 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.0014872513059998212 != rate { - t.Errorf("6 minute a.Rate(): 0.0014872513059998212 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.0005471291793327122 != rate { - t.Errorf("7 minute a.Rate(): 0.0005471291793327122 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.00020127757674150815 != rate { - t.Errorf("8 minute a.Rate(): 0.00020127757674150815 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 7.404588245200814e-05 != rate { - t.Errorf("9 minute a.Rate(): 7.404588245200814e-05 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 2.7239957857491083e-05 != rate { - t.Errorf("10 minute a.Rate(): 2.7239957857491083e-05 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 1.0021020474147462e-05 != rate { - t.Errorf("11 minute a.Rate(): 1.0021020474147462e-05 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 3.6865274119969525e-06 != rate { - t.Errorf("12 minute a.Rate(): 3.6865274119969525e-06 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 1.3561976441886433e-06 != rate { - t.Errorf("13 minute a.Rate(): 1.3561976441886433e-06 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 4.989172314621449e-07 != rate { - t.Errorf("14 minute a.Rate(): 4.989172314621449e-07 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 1.8354139230109722e-07 != rate { - t.Errorf("15 minute a.Rate(): 1.8354139230109722e-07 != %v\n", rate) - } -} - -func TestEWMA5(t *testing.T) { - a := NewEWMA5() - a.Update(3) - a.Tick() - if rate := a.Rate(); 0.6 != rate { - t.Errorf("initial a.Rate(): 0.6 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.49123845184678905 != rate { - t.Errorf("1 minute a.Rate(): 0.49123845184678905 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.4021920276213837 != rate { - t.Errorf("2 minute a.Rate(): 0.4021920276213837 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.32928698165641596 != rate { - t.Errorf("3 minute a.Rate(): 0.32928698165641596 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.269597378470333 != rate { - t.Errorf("4 minute a.Rate(): 0.269597378470333 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.2207276647028654 != rate { - t.Errorf("5 minute a.Rate(): 0.2207276647028654 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.18071652714732128 != rate { - t.Errorf("6 minute a.Rate(): 0.18071652714732128 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.14795817836496392 != rate { - t.Errorf("7 minute a.Rate(): 0.14795817836496392 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.12113791079679326 != rate { - t.Errorf("8 minute a.Rate(): 0.12113791079679326 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.09917933293295193 != rate { - t.Errorf("9 minute a.Rate(): 0.09917933293295193 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.08120116994196763 != rate { - t.Errorf("10 minute a.Rate(): 0.08120116994196763 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.06648189501740036 != rate { - t.Errorf("11 minute a.Rate(): 0.06648189501740036 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.05443077197364752 != rate { - t.Errorf("12 minute a.Rate(): 0.05443077197364752 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.04456414692860035 != rate { - t.Errorf("13 minute a.Rate(): 0.04456414692860035 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.03648603757513079 != rate { - t.Errorf("14 minute a.Rate(): 0.03648603757513079 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.0298722410207183831020718428 != rate { - t.Errorf("15 minute a.Rate(): 0.0298722410207183831020718428 != %v\n", rate) - } -} - -func TestEWMA15(t *testing.T) { - a := NewEWMA15() - a.Update(3) - a.Tick() - if rate := a.Rate(); 0.6 != rate { - t.Errorf("initial a.Rate(): 0.6 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.5613041910189706 != rate { - t.Errorf("1 minute a.Rate(): 0.5613041910189706 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.5251039914257684 != rate { - t.Errorf("2 minute a.Rate(): 0.5251039914257684 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.4912384518467888184678905 != rate { - t.Errorf("3 minute a.Rate(): 0.4912384518467888184678905 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.459557003018789 != rate { - t.Errorf("4 minute a.Rate(): 0.459557003018789 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.4299187863442732 != rate { - t.Errorf("5 minute a.Rate(): 0.4299187863442732 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.4021920276213831 != rate { - t.Errorf("6 minute a.Rate(): 0.4021920276213831 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.37625345116383313 != rate { - t.Errorf("7 minute a.Rate(): 0.37625345116383313 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.3519877317060185 != rate { - t.Errorf("8 minute a.Rate(): 0.3519877317060185 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.3292869816564153165641596 != rate { - t.Errorf("9 minute a.Rate(): 0.3292869816564153165641596 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.3080502714195546 != rate { - t.Errorf("10 minute a.Rate(): 0.3080502714195546 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.2881831806538789 != rate { - t.Errorf("11 minute a.Rate(): 0.2881831806538789 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.26959737847033216 != rate { - t.Errorf("12 minute a.Rate(): 0.26959737847033216 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.2522102307052083 != rate { - t.Errorf("13 minute a.Rate(): 0.2522102307052083 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.23594443252115815 != rate { - t.Errorf("14 minute a.Rate(): 0.23594443252115815 != %v\n", rate) - } - elapseMinute(a) - if rate := a.Rate(); 0.2207276647028646247028654470286553 != rate { - t.Errorf("15 minute a.Rate(): 0.2207276647028646247028654470286553 != %v\n", rate) - } -} - -func elapseMinute(a EWMA) { - for i := 0; i < 12; i++ { - a.Tick() - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/exp/exp.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/exp/exp.go new file mode 100644 index 000000000..09a496f11 --- /dev/null +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/exp/exp.go @@ -0,0 +1,148 @@ +// Hook go-metrics into expvar +// on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler +package exp + +import ( + "expvar" + "fmt" + "github.com/rcrowley/go-metrics" + "net/http" + "sync" +) + +type exp struct { + expvarLock sync.Mutex // expvar panics if you try to register the same var twice, so we must probe it safely + registry metrics.Registry +} + +func (exp *exp) expHandler(w http.ResponseWriter, r *http.Request) { + // load our variables into expvar + exp.syncToExpvar() + + // now just run the official expvar handler code (which is not publicly callable, so pasted inline) + w.Header().Set("Content-Type", "application/json; charset=utf-8") + fmt.Fprintf(w, "{\n") + first := true + expvar.Do(func(kv expvar.KeyValue) { + if !first { + fmt.Fprintf(w, ",\n") + } + first = false + fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) + }) + fmt.Fprintf(w, "\n}\n") +} + +func Exp(r metrics.Registry) { + e := exp{sync.Mutex{}, r} + // this would cause a panic: + // panic: http: multiple registrations for /debug/vars + // http.HandleFunc("/debug/vars", e.expHandler) + // haven't found an elegant way, so just use a different endpoint + http.HandleFunc("/debug/metrics", e.expHandler) +} + +func (exp *exp) getInt(name string) *expvar.Int { + var v *expvar.Int + exp.expvarLock.Lock() + p := expvar.Get(name) + if p != nil { + v = p.(*expvar.Int) + } else { + v = new(expvar.Int) + expvar.Publish(name, v) + } + exp.expvarLock.Unlock() + return v +} + +func (exp *exp) getFloat(name string) *expvar.Float { + var v *expvar.Float + exp.expvarLock.Lock() + p := expvar.Get(name) + if p != nil { + v = p.(*expvar.Float) + } else { + v = new(expvar.Float) + expvar.Publish(name, v) + } + exp.expvarLock.Unlock() + return v +} + +func (exp *exp) publishCounter(name string, metric metrics.Counter) { + v := exp.getInt(name) + v.Set(metric.Count()) +} + +func (exp *exp) publishGauge(name string, metric metrics.Gauge) { + v := exp.getInt(name) + v.Set(metric.Value()) +} +func (exp *exp) publishGaugeFloat64(name string, metric metrics.GaugeFloat64) { + exp.getFloat(name).Set(metric.Value()) +} + +func (exp *exp) publishHistogram(name string, metric metrics.Histogram) { + h := metric.Snapshot() + ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) + exp.getInt(name + ".count").Set(h.Count()) + exp.getFloat(name + ".min").Set(float64(h.Min())) + exp.getFloat(name + ".max").Set(float64(h.Max())) + exp.getFloat(name + ".mean").Set(float64(h.Mean())) + exp.getFloat(name + ".std-dev").Set(float64(h.StdDev())) + exp.getFloat(name + ".50-percentile").Set(float64(ps[0])) + exp.getFloat(name + ".75-percentile").Set(float64(ps[1])) + exp.getFloat(name + ".95-percentile").Set(float64(ps[2])) + exp.getFloat(name + ".99-percentile").Set(float64(ps[3])) + exp.getFloat(name + ".999-percentile").Set(float64(ps[4])) +} + +func (exp *exp) publishMeter(name string, metric metrics.Meter) { + m := metric.Snapshot() + exp.getInt(name + ".count").Set(m.Count()) + exp.getFloat(name + ".one-minute").Set(float64(m.Rate1())) + exp.getFloat(name + ".five-minute").Set(float64(m.Rate5())) + exp.getFloat(name + ".fifteen-minute").Set(float64((m.Rate15()))) + exp.getFloat(name + ".mean").Set(float64(m.RateMean())) +} + +func (exp *exp) publishTimer(name string, metric metrics.Timer) { + t := metric.Snapshot() + ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) + exp.getInt(name + ".count").Set(t.Count()) + exp.getFloat(name + ".min").Set(float64(t.Min())) + exp.getFloat(name + ".max").Set(float64(t.Max())) + exp.getFloat(name + ".mean").Set(float64(t.Mean())) + exp.getFloat(name + ".std-dev").Set(float64(t.StdDev())) + exp.getFloat(name + ".50-percentile").Set(float64(ps[0])) + exp.getFloat(name + ".75-percentile").Set(float64(ps[1])) + exp.getFloat(name + ".95-percentile").Set(float64(ps[2])) + exp.getFloat(name + ".99-percentile").Set(float64(ps[3])) + exp.getFloat(name + ".999-percentile").Set(float64(ps[4])) + exp.getFloat(name + ".one-minute").Set(float64(t.Rate1())) + exp.getFloat(name + ".five-minute").Set(float64(t.Rate5())) + exp.getFloat(name + ".fifteen-minute").Set(float64((t.Rate15()))) + exp.getFloat(name + ".mean-rate").Set(float64(t.RateMean())) +} + +func (exp *exp) syncToExpvar() { + exp.registry.Each(func(name string, i interface{}) { + switch i.(type) { + case metrics.Counter: + exp.publishCounter(name, i.(metrics.Counter)) + case metrics.Gauge: + exp.publishGauge(name, i.(metrics.Gauge)) + case metrics.GaugeFloat64: + exp.publishGaugeFloat64(name, i.(metrics.GaugeFloat64)) + case metrics.Histogram: + exp.publishHistogram(name, i.(metrics.Histogram)) + case metrics.Meter: + exp.publishMeter(name, i.(metrics.Meter)) + case metrics.Timer: + exp.publishTimer(name, i.(metrics.Timer)) + default: + panic(fmt.Sprintf("unsupported type for '%s': %T", name, i)) + } + }) +} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/gauge_float64_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/gauge_float64_test.go deleted file mode 100644 index 5d0aae271..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/gauge_float64_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package metrics - -import "testing" - -func BenchmarkGuageFloat64(b *testing.B) { - g := NewGaugeFloat64() - b.ResetTimer() - for i := 0; i < b.N; i++ { - g.Update(float64(i)) - } -} - -func TestGaugeFloat64(t *testing.T) { - g := NewGaugeFloat64() - g.Update(float64(47.0)) - if v := g.Value(); float64(47.0) != v { - t.Errorf("g.Value(): 47.0 != %v\n", v) - } -} - -func TestGaugeFloat64Snapshot(t *testing.T) { - g := NewGaugeFloat64() - g.Update(float64(47.0)) - snapshot := g.Snapshot() - g.Update(float64(0)) - if v := snapshot.Value(); float64(47.0) != v { - t.Errorf("g.Value(): 47.0 != %v\n", v) - } -} - -func TestGetOrRegisterGaugeFloat64(t *testing.T) { - r := NewRegistry() - NewRegisteredGaugeFloat64("foo", r).Update(float64(47.0)) - t.Logf("registry: %v", r) - if g := GetOrRegisterGaugeFloat64("foo", r); float64(47.0) != g.Value() { - t.Fatal(g) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/gauge_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/gauge_test.go deleted file mode 100644 index 508496291..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/gauge_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package metrics - -import "testing" - -func BenchmarkGuage(b *testing.B) { - g := NewGauge() - b.ResetTimer() - for i := 0; i < b.N; i++ { - g.Update(int64(i)) - } -} - -func TestGauge(t *testing.T) { - g := NewGauge() - g.Update(int64(47)) - if v := g.Value(); 47 != v { - t.Errorf("g.Value(): 47 != %v\n", v) - } -} - -func TestGaugeSnapshot(t *testing.T) { - g := NewGauge() - g.Update(int64(47)) - snapshot := g.Snapshot() - g.Update(int64(0)) - if v := snapshot.Value(); 47 != v { - t.Errorf("g.Value(): 47 != %v\n", v) - } -} - -func TestGetOrRegisterGauge(t *testing.T) { - r := NewRegistry() - NewRegisteredGauge("foo", r).Update(47) - if g := GetOrRegisterGauge("foo", r); 47 != g.Value() { - t.Fatal(g) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite.go index 604b26da0..abd0a7d29 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite.go @@ -38,6 +38,7 @@ func Graphite(r Registry, d time.Duration, prefix string, addr *net.TCPAddr) { // GraphiteWithConfig is a blocking exporter function just like Graphite, // but it takes a GraphiteConfig instead. func GraphiteWithConfig(c GraphiteConfig) { + log.Printf("WARNING: This go-metrics client has been DEPRECATED! It has been moved to https://github.com/cyberdelia/go-metrics-graphite and will be removed from rcrowley/go-metrics on August 12th 2015") for _ = range time.Tick(c.FlushInterval) { if err := graphite(&c); nil != err { log.Println(err) @@ -49,6 +50,7 @@ func GraphiteWithConfig(c GraphiteConfig) { // non-nil error on failed connections. This can be used in a loop // similar to GraphiteWithConfig for custom error handling. func GraphiteOnce(c GraphiteConfig) error { + log.Printf("WARNING: This go-metrics client has been DEPRECATED! It has been moved to https://github.com/cyberdelia/go-metrics-graphite and will be removed from rcrowley/go-metrics on August 12th 2015") return graphite(&c) } diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite_test.go deleted file mode 100644 index b49dc4bb5..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/graphite_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package metrics - -import ( - "net" - "time" -) - -func ExampleGraphite() { - addr, _ := net.ResolveTCPAddr("net", ":2003") - go Graphite(DefaultRegistry, 1*time.Second, "some.prefix", addr) -} - -func ExampleGraphiteWithConfig() { - addr, _ := net.ResolveTCPAddr("net", ":2003") - go GraphiteWithConfig(GraphiteConfig{ - Addr: addr, - Registry: DefaultRegistry, - FlushInterval: 1 * time.Second, - DurationUnit: time.Millisecond, - Percentiles: []float64{ 0.5, 0.75, 0.99, 0.999 }, - }) -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/histogram_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/histogram_test.go deleted file mode 100644 index d7f4f0171..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/histogram_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package metrics - -import "testing" - -func BenchmarkHistogram(b *testing.B) { - h := NewHistogram(NewUniformSample(100)) - b.ResetTimer() - for i := 0; i < b.N; i++ { - h.Update(int64(i)) - } -} - -func TestGetOrRegisterHistogram(t *testing.T) { - r := NewRegistry() - s := NewUniformSample(100) - NewRegisteredHistogram("foo", r, s).Update(47) - if h := GetOrRegisterHistogram("foo", r, s); 1 != h.Count() { - t.Fatal(h) - } -} - -func TestHistogram10000(t *testing.T) { - h := NewHistogram(NewUniformSample(100000)) - for i := 1; i <= 10000; i++ { - h.Update(int64(i)) - } - testHistogram10000(t, h) -} - -func TestHistogramEmpty(t *testing.T) { - h := NewHistogram(NewUniformSample(100)) - if count := h.Count(); 0 != count { - t.Errorf("h.Count(): 0 != %v\n", count) - } - if min := h.Min(); 0 != min { - t.Errorf("h.Min(): 0 != %v\n", min) - } - if max := h.Max(); 0 != max { - t.Errorf("h.Max(): 0 != %v\n", max) - } - if mean := h.Mean(); 0.0 != mean { - t.Errorf("h.Mean(): 0.0 != %v\n", mean) - } - if stdDev := h.StdDev(); 0.0 != stdDev { - t.Errorf("h.StdDev(): 0.0 != %v\n", stdDev) - } - ps := h.Percentiles([]float64{0.5, 0.75, 0.99}) - if 0.0 != ps[0] { - t.Errorf("median: 0.0 != %v\n", ps[0]) - } - if 0.0 != ps[1] { - t.Errorf("75th percentile: 0.0 != %v\n", ps[1]) - } - if 0.0 != ps[2] { - t.Errorf("99th percentile: 0.0 != %v\n", ps[2]) - } -} - -func TestHistogramSnapshot(t *testing.T) { - h := NewHistogram(NewUniformSample(100000)) - for i := 1; i <= 10000; i++ { - h.Update(int64(i)) - } - snapshot := h.Snapshot() - h.Update(0) - testHistogram10000(t, snapshot) -} - -func testHistogram10000(t *testing.T, h Histogram) { - if count := h.Count(); 10000 != count { - t.Errorf("h.Count(): 10000 != %v\n", count) - } - if min := h.Min(); 1 != min { - t.Errorf("h.Min(): 1 != %v\n", min) - } - if max := h.Max(); 10000 != max { - t.Errorf("h.Max(): 10000 != %v\n", max) - } - if mean := h.Mean(); 5000.5 != mean { - t.Errorf("h.Mean(): 5000.5 != %v\n", mean) - } - if stdDev := h.StdDev(); 2886.751331514372 != stdDev { - t.Errorf("h.StdDev(): 2886.751331514372 != %v\n", stdDev) - } - ps := h.Percentiles([]float64{0.5, 0.75, 0.99}) - if 5000.5 != ps[0] { - t.Errorf("median: 5000.5 != %v\n", ps[0]) - } - if 7500.75 != ps[1] { - t.Errorf("75th percentile: 7500.75 != %v\n", ps[1]) - } - if 9900.99 != ps[2] { - t.Errorf("99th percentile: 9900.99 != %v\n", ps[2]) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/influxdb/influxdb.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/influxdb/influxdb.go deleted file mode 100644 index 0163c9b42..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/influxdb/influxdb.go +++ /dev/null @@ -1,114 +0,0 @@ -package influxdb - -import ( - "fmt" - influxClient "github.com/influxdb/influxdb/client" - "github.com/rcrowley/go-metrics" - "log" - "time" -) - -type Config struct { - Host string - Database string - Username string - Password string -} - -func Influxdb(r metrics.Registry, d time.Duration, config *Config) { - client, err := influxClient.NewClient(&influxClient.ClientConfig{ - Host: config.Host, - Database: config.Database, - Username: config.Username, - Password: config.Password, - }) - if err != nil { - log.Println(err) - return - } - - for _ = range time.Tick(d) { - if err := send(r, client); err != nil { - log.Println(err) - } - } -} - -func send(r metrics.Registry, client *influxClient.Client) error { - series := []*influxClient.Series{} - - r.Each(func(name string, i interface{}) { - now := getCurrentTime() - switch metric := i.(type) { - case metrics.Counter: - series = append(series, &influxClient.Series{ - Name: fmt.Sprintf("%s.count", name), - Columns: []string{"time", "count"}, - Points: [][]interface{}{ - {now, metric.Count()}, - }, - }) - case metrics.Gauge: - series = append(series, &influxClient.Series{ - Name: fmt.Sprintf("%s.value", name), - Columns: []string{"time", "value"}, - Points: [][]interface{}{ - {now, metric.Value()}, - }, - }) - case metrics.GaugeFloat64: - series = append(series, &influxClient.Series{ - Name: fmt.Sprintf("%s.value", name), - Columns: []string{"time", "value"}, - Points: [][]interface{}{ - {now, metric.Value()}, - }, - }) - case metrics.Histogram: - h := metric.Snapshot() - ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) - series = append(series, &influxClient.Series{ - Name: fmt.Sprintf("%s.histogram", name), - Columns: []string{"time", "count", "min", "max", "mean", "std-dev", - "50-percentile", "75-percentile", "95-percentile", - "99-percentile", "999-percentile"}, - Points: [][]interface{}{ - {now, h.Count(), h.Min(), h.Max(), h.Mean(), h.StdDev(), - ps[0], ps[1], ps[2], ps[3], ps[4]}, - }, - }) - case metrics.Meter: - m := metric.Snapshot() - series = append(series, &influxClient.Series{ - Name: fmt.Sprintf("%s.meter", name), - Columns: []string{"count", "one-minute", - "five-minute", "fifteen-minute", "mean"}, - Points: [][]interface{}{ - {m.Count(), m.Rate1(), m.Rate5(), m.Rate15(), m.RateMean()}, - }, - }) - case metrics.Timer: - h := metric.Snapshot() - ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) - series = append(series, &influxClient.Series{ - Name: fmt.Sprintf("%s.timer", name), - Columns: []string{"count", "min", "max", "mean", "std-dev", - "50-percentile", "75-percentile", "95-percentile", - "99-percentile", "999-percentile", "one-minute", "five-minute", "fifteen-minute", "mean-rate"}, - Points: [][]interface{}{ - {h.Count(), h.Min(), h.Max(), h.Mean(), h.StdDev(), - ps[0], ps[1], ps[2], ps[3], ps[4], - h.Rate1(), h.Rate5(), h.Rate15(), h.RateMean()}, - }, - }) - } - }) - if err := client.WriteSeries(series); err != nil { - log.Println(err) - } - return nil -} - -func getCurrentTime() int64 { - return time.Now().UnixNano() / 1000000 -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json.go index 04a9c9198..2676aeea5 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json.go @@ -8,7 +8,7 @@ import ( // MarshalJSON returns a byte slice containing a JSON representation of all // the metrics in the Registry. -func (r StandardRegistry) MarshalJSON() ([]byte, error) { +func (r *StandardRegistry) MarshalJSON() ([]byte, error) { data := make(map[string]map[string]interface{}) r.Each(func(name string, i interface{}) { values := make(map[string]interface{}) diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json_test.go deleted file mode 100644 index cf70051f7..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/json_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package metrics - -import ( - "bytes" - "encoding/json" - "testing" -) - -func TestRegistryMarshallJSON(t *testing.T) { - b := &bytes.Buffer{} - enc := json.NewEncoder(b) - r := NewRegistry() - r.Register("counter", NewCounter()) - enc.Encode(r) - if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s { - t.Fatalf(s) - } -} - -func TestRegistryWriteJSONOnce(t *testing.T) { - r := NewRegistry() - r.Register("counter", NewCounter()) - b := &bytes.Buffer{} - WriteJSONOnce(r, b) - if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" { - t.Fail() - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/librato/librato.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/librato/librato.go index dfaae2f28..d7c057468 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/librato/librato.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/librato/librato.go @@ -23,6 +23,7 @@ func translateTimerAttributes(d time.Duration) (attrs map[string]interface{}) { type Reporter struct { Email, Token string + Namespace string Source string Interval time.Duration Registry metrics.Registry @@ -32,7 +33,7 @@ type Reporter struct { } func NewReporter(r metrics.Registry, d time.Duration, e string, t string, s string, p []float64, u time.Duration) *Reporter { - return &Reporter{e, t, s, d, r, p, translateTimerAttributes(u), int64(d / time.Second)} + return &Reporter{e, t, "", s, d, r, p, translateTimerAttributes(u), int64(d / time.Second)} } func Librato(r metrics.Registry, d time.Duration, e string, t string, s string, p []float64, u time.Duration) { @@ -40,6 +41,7 @@ func Librato(r metrics.Registry, d time.Duration, e string, t string, s string, } func (self *Reporter) Run() { + log.Printf("WARNING: This client has been DEPRECATED! It has been moved to https://github.com/mihasya/go-metrics-librato and will be removed from rcrowley/go-metrics on August 5th 2015") ticker := time.Tick(self.Interval) metricsApi := &LibratoClient{self.Email, self.Token} for now := range ticker { @@ -87,6 +89,9 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot snapshot.Counters = make([]Measurement, 0) histogramGaugeCount := 1 + len(self.Percentiles) r.Each(func(name string, metric interface{}) { + if self.Namespace != "" { + name = fmt.Sprintf("%s.%s", self.Namespace, name) + } measurement := Measurement{} measurement[Period] = self.Interval.Seconds() switch m := metric.(type) { diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go index 278a8a441..f074eb03d 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go @@ -5,10 +5,17 @@ import ( "time" ) +func Log(r Registry, freq time.Duration, l *log.Logger) { + LogScaled(r, freq, time.Nanosecond, l) +} + // Output each metric in the given registry periodically using the given -// logger. -func Log(r Registry, d time.Duration, l *log.Logger) { - for _ = range time.Tick(d) { +// logger. Print timings in `scale` units (eg time.Millisecond) rather than nanos. +func LogScaled(r Registry, freq time.Duration, scale time.Duration, l *log.Logger) { + du := float64(scale) + duSuffix := scale.String()[1:] + + for _ = range time.Tick(freq) { r.Each(func(name string, i interface{}) { switch metric := i.(type) { case Counter: @@ -51,15 +58,15 @@ func Log(r Registry, d time.Duration, l *log.Logger) { ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) l.Printf("timer %s\n", name) l.Printf(" count: %9d\n", t.Count()) - l.Printf(" min: %9d\n", t.Min()) - l.Printf(" max: %9d\n", t.Max()) - l.Printf(" mean: %12.2f\n", t.Mean()) - l.Printf(" stddev: %12.2f\n", t.StdDev()) - l.Printf(" median: %12.2f\n", ps[0]) - l.Printf(" 75%%: %12.2f\n", ps[1]) - l.Printf(" 95%%: %12.2f\n", ps[2]) - l.Printf(" 99%%: %12.2f\n", ps[3]) - l.Printf(" 99.9%%: %12.2f\n", ps[4]) + l.Printf(" min: %12.2f%s\n", float64(t.Min())/du, duSuffix) + l.Printf(" max: %12.2f%s\n", float64(t.Max())/du, duSuffix) + l.Printf(" mean: %12.2f%s\n", t.Mean()/du, duSuffix) + l.Printf(" stddev: %12.2f%s\n", t.StdDev()/du, duSuffix) + l.Printf(" median: %12.2f%s\n", ps[0]/du, duSuffix) + l.Printf(" 75%%: %12.2f%s\n", ps[1]/du, duSuffix) + l.Printf(" 95%%: %12.2f%s\n", ps[2]/du, duSuffix) + l.Printf(" 99%%: %12.2f%s\n", ps[3]/du, duSuffix) + l.Printf(" 99.9%%: %12.2f%s\n", ps[4]/du, duSuffix) l.Printf(" 1-min rate: %12.2f\n", t.Rate1()) l.Printf(" 5-min rate: %12.2f\n", t.Rate5()) l.Printf(" 15-min rate: %12.2f\n", t.Rate15()) diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/meter_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/meter_test.go deleted file mode 100644 index 26ce1398a..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/meter_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package metrics - -import ( - "testing" - "time" -) - -func BenchmarkMeter(b *testing.B) { - m := NewMeter() - b.ResetTimer() - for i := 0; i < b.N; i++ { - m.Mark(1) - } -} - -func TestGetOrRegisterMeter(t *testing.T) { - r := NewRegistry() - NewRegisteredMeter("foo", r).Mark(47) - if m := GetOrRegisterMeter("foo", r); 47 != m.Count() { - t.Fatal(m) - } -} - -func TestMeterDecay(t *testing.T) { - ma := meterArbiter{ - ticker: time.NewTicker(1), - } - m := newStandardMeter() - ma.meters = append(ma.meters, m) - go ma.tick() - m.Mark(1) - rateMean := m.RateMean() - time.Sleep(1) - if m.RateMean() >= rateMean { - t.Error("m.RateMean() didn't decrease") - } -} - -func TestMeterNonzero(t *testing.T) { - m := NewMeter() - m.Mark(3) - if count := m.Count(); 3 != count { - t.Errorf("m.Count(): 3 != %v\n", count) - } -} - -func TestMeterSnapshot(t *testing.T) { - m := NewMeter() - m.Mark(1) - if snapshot := m.Snapshot(); m.RateMean() != snapshot.RateMean() { - t.Fatal(snapshot) - } -} - -func TestMeterZero(t *testing.T) { - m := NewMeter() - if count := m.Count(); 0 != count { - t.Errorf("m.Count(): 0 != %v\n", count) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/metrics_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/metrics_test.go deleted file mode 100644 index 083f9676f..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/metrics_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package metrics - -import ( - "io/ioutil" - "log" - "sync" - "testing" -) - -const FANOUT = 128 - -// Stop the compiler from complaining during debugging. -var ( - _ = ioutil.Discard - _ = log.LstdFlags -) - -func BenchmarkMetrics(b *testing.B) { - r := NewRegistry() - c := NewRegisteredCounter("counter", r) - g := NewRegisteredGauge("gauge", r) - gf := NewRegisteredGaugeFloat64("gaugefloat64", r) - h := NewRegisteredHistogram("histogram", r, NewUniformSample(100)) - m := NewRegisteredMeter("meter", r) - t := NewRegisteredTimer("timer", r) - RegisterDebugGCStats(r) - RegisterRuntimeMemStats(r) - b.ResetTimer() - ch := make(chan bool) - - wgD := &sync.WaitGroup{} - /* - wgD.Add(1) - go func() { - defer wgD.Done() - //log.Println("go CaptureDebugGCStats") - for { - select { - case <-ch: - //log.Println("done CaptureDebugGCStats") - return - default: - CaptureDebugGCStatsOnce(r) - } - } - }() - //*/ - - wgR := &sync.WaitGroup{} - //* - wgR.Add(1) - go func() { - defer wgR.Done() - //log.Println("go CaptureRuntimeMemStats") - for { - select { - case <-ch: - //log.Println("done CaptureRuntimeMemStats") - return - default: - CaptureRuntimeMemStatsOnce(r) - } - } - }() - //*/ - - wgW := &sync.WaitGroup{} - /* - wgW.Add(1) - go func() { - defer wgW.Done() - //log.Println("go Write") - for { - select { - case <-ch: - //log.Println("done Write") - return - default: - WriteOnce(r, ioutil.Discard) - } - } - }() - //*/ - - wg := &sync.WaitGroup{} - wg.Add(FANOUT) - for i := 0; i < FANOUT; i++ { - go func(i int) { - defer wg.Done() - //log.Println("go", i) - for i := 0; i < b.N; i++ { - c.Inc(1) - g.Update(int64(i)) - gf.Update(float64(i)) - h.Update(int64(i)) - m.Mark(1) - t.Update(1) - } - //log.Println("done", i) - }(i) - } - wg.Wait() - close(ch) - wgD.Wait() - wgR.Wait() - wgW.Wait() -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/opentsdb_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/opentsdb_test.go deleted file mode 100644 index 6173d61ab..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/opentsdb_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package metrics - -import ( - "net" - "time" -) - -func ExampleOpenTSDB() { - addr, _ := net.ResolveTCPAddr("net", ":2003") - go OpenTSDB(DefaultRegistry, 1*time.Second, "some.prefix", addr) -} - -func ExampleOpenTSDBWithConfig() { - addr, _ := net.ResolveTCPAddr("net", ":2003") - go OpenTSDBWithConfig(OpenTSDBConfig{ - Addr: addr, - Registry: DefaultRegistry, - FlushInterval: 1 * time.Second, - DurationUnit: time.Millisecond, - }) -} - diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry.go index 1f9d82c2a..e1f68a5dc 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry.go @@ -145,6 +145,65 @@ func (r *StandardRegistry) registered() map[string]interface{} { return metrics } +type PrefixedRegistry struct { + underlying Registry + prefix string +} + +func NewPrefixedRegistry(prefix string) Registry { + return &PrefixedRegistry{ + underlying: NewRegistry(), + prefix: prefix, + } +} + +func NewPrefixedChildRegistry(parent Registry, prefix string) Registry { + return &PrefixedRegistry{ + underlying: parent, + prefix: prefix, + } +} + +// Call the given function for each registered metric. +func (r *PrefixedRegistry) Each(fn func(string, interface{})) { + r.underlying.Each(fn) +} + +// Get the metric by the given name or nil if none is registered. +func (r *PrefixedRegistry) Get(name string) interface{} { + return r.underlying.Get(name) +} + +// Gets an existing metric or registers the given one. +// The interface can be the metric to register if not found in registry, +// or a function returning the metric for lazy instantiation. +func (r *PrefixedRegistry) GetOrRegister(name string, metric interface{}) interface{} { + realName := r.prefix + name + return r.underlying.GetOrRegister(realName, metric) +} + +// Register the given metric under the given name. The name will be prefixed. +func (r *PrefixedRegistry) Register(name string, metric interface{}) error { + realName := r.prefix + name + return r.underlying.Register(realName, metric) +} + +// Run all registered healthchecks. +func (r *PrefixedRegistry) RunHealthchecks() { + r.underlying.RunHealthchecks() +} + +// Unregister the metric with the given name. The name will be prefixed. +func (r *PrefixedRegistry) Unregister(name string) { + realName := r.prefix + name + r.underlying.Unregister(realName) +} + +// Unregister all metrics. (Mostly for testing.) +func (r *PrefixedRegistry) UnregisterAll() { + r.underlying.UnregisterAll() +} + var DefaultRegistry Registry = NewRegistry() // Call the given function for each registered metric. @@ -169,6 +228,14 @@ func Register(name string, i interface{}) error { return DefaultRegistry.Register(name, i) } +// Register the given metric under the given name. Panics if a metric by the +// given name is already registered. +func MustRegister(name string, i interface{}) { + if err := Register(name, i); err != nil { + panic(err) + } +} + // Run all registered healthchecks. func RunHealthchecks() { DefaultRegistry.RunHealthchecks() diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry_test.go deleted file mode 100644 index 9ba0a0205..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/registry_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package metrics - -import "testing" - -func BenchmarkRegistry(b *testing.B) { - r := NewRegistry() - r.Register("foo", NewCounter()) - b.ResetTimer() - for i := 0; i < b.N; i++ { - r.Each(func(string, interface{}) {}) - } -} - -func TestRegistry(t *testing.T) { - r := NewRegistry() - r.Register("foo", NewCounter()) - i := 0 - r.Each(func(name string, iface interface{}) { - i++ - if "foo" != name { - t.Fatal(name) - } - if _, ok := iface.(Counter); !ok { - t.Fatal(iface) - } - }) - if 1 != i { - t.Fatal(i) - } - r.Unregister("foo") - i = 0 - r.Each(func(string, interface{}) { i++ }) - if 0 != i { - t.Fatal(i) - } -} - -func TestRegistryDuplicate(t *testing.T) { - r := NewRegistry() - if err := r.Register("foo", NewCounter()); nil != err { - t.Fatal(err) - } - if err := r.Register("foo", NewGauge()); nil == err { - t.Fatal(err) - } - i := 0 - r.Each(func(name string, iface interface{}) { - i++ - if _, ok := iface.(Counter); !ok { - t.Fatal(iface) - } - }) - if 1 != i { - t.Fatal(i) - } -} - -func TestRegistryGet(t *testing.T) { - r := NewRegistry() - r.Register("foo", NewCounter()) - if count := r.Get("foo").(Counter).Count(); 0 != count { - t.Fatal(count) - } - r.Get("foo").(Counter).Inc(1) - if count := r.Get("foo").(Counter).Count(); 1 != count { - t.Fatal(count) - } -} - -func TestRegistryGetOrRegister(t *testing.T) { - r := NewRegistry() - - // First metric wins with GetOrRegister - _ = r.GetOrRegister("foo", NewCounter()) - m := r.GetOrRegister("foo", NewGauge()) - if _, ok := m.(Counter); !ok { - t.Fatal(m) - } - - i := 0 - r.Each(func(name string, iface interface{}) { - i++ - if name != "foo" { - t.Fatal(name) - } - if _, ok := iface.(Counter); !ok { - t.Fatal(iface) - } - }) - if i != 1 { - t.Fatal(i) - } -} - -func TestRegistryGetOrRegisterWithLazyInstantiation(t *testing.T) { - r := NewRegistry() - - // First metric wins with GetOrRegister - _ = r.GetOrRegister("foo", NewCounter) - m := r.GetOrRegister("foo", NewGauge) - if _, ok := m.(Counter); !ok { - t.Fatal(m) - } - - i := 0 - r.Each(func(name string, iface interface{}) { - i++ - if name != "foo" { - t.Fatal(name) - } - if _, ok := iface.(Counter); !ok { - t.Fatal(iface) - } - }) - if i != 1 { - t.Fatal(i) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime.go index 82574bf25..e8c8d1568 100644 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime.go +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime.go @@ -9,32 +9,33 @@ var ( memStats runtime.MemStats runtimeMetrics struct { MemStats struct { - Alloc Gauge - BuckHashSys Gauge - DebugGC Gauge - EnableGC Gauge - Frees Gauge - HeapAlloc Gauge - HeapIdle Gauge - HeapInuse Gauge - HeapObjects Gauge - HeapReleased Gauge - HeapSys Gauge - LastGC Gauge - Lookups Gauge - Mallocs Gauge - MCacheInuse Gauge - MCacheSys Gauge - MSpanInuse Gauge - MSpanSys Gauge - NextGC Gauge - NumGC Gauge - PauseNs Histogram - PauseTotalNs Gauge - StackInuse Gauge - StackSys Gauge - Sys Gauge - TotalAlloc Gauge + Alloc Gauge + BuckHashSys Gauge + DebugGC Gauge + EnableGC Gauge + Frees Gauge + HeapAlloc Gauge + HeapIdle Gauge + HeapInuse Gauge + HeapObjects Gauge + HeapReleased Gauge + HeapSys Gauge + LastGC Gauge + Lookups Gauge + Mallocs Gauge + MCacheInuse Gauge + MCacheSys Gauge + MSpanInuse Gauge + MSpanSys Gauge + NextGC Gauge + NumGC Gauge + GCCPUFraction GaugeFloat64 + PauseNs Histogram + PauseTotalNs Gauge + StackInuse Gauge + StackSys Gauge + Sys Gauge + TotalAlloc Gauge } NumCgoCall Gauge NumGoroutine Gauge @@ -97,6 +98,7 @@ func CaptureRuntimeMemStatsOnce(r Registry) { runtimeMetrics.MemStats.MSpanSys.Update(int64(memStats.MSpanSys)) runtimeMetrics.MemStats.NextGC.Update(int64(memStats.NextGC)) runtimeMetrics.MemStats.NumGC.Update(int64(memStats.NumGC - numGC)) + runtimeMetrics.MemStats.GCCPUFraction.Update(gcCPUFraction(&memStats)) // <https://code.google.com/p/go/source/browse/src/pkg/runtime/mgc0.c> i := numGC % uint32(len(memStats.PauseNs)) @@ -158,6 +160,7 @@ func RegisterRuntimeMemStats(r Registry) { runtimeMetrics.MemStats.MSpanSys = NewGauge() runtimeMetrics.MemStats.NextGC = NewGauge() runtimeMetrics.MemStats.NumGC = NewGauge() + runtimeMetrics.MemStats.GCCPUFraction = NewGaugeFloat64() runtimeMetrics.MemStats.PauseNs = NewHistogram(NewExpDecaySample(1028, 0.015)) runtimeMetrics.MemStats.PauseTotalNs = NewGauge() runtimeMetrics.MemStats.StackInuse = NewGauge() @@ -188,6 +191,7 @@ func RegisterRuntimeMemStats(r Registry) { r.Register("runtime.MemStats.MSpanSys", runtimeMetrics.MemStats.MSpanSys) r.Register("runtime.MemStats.NextGC", runtimeMetrics.MemStats.NextGC) r.Register("runtime.MemStats.NumGC", runtimeMetrics.MemStats.NumGC) + r.Register("runtime.MemStats.GCCPUFraction", runtimeMetrics.MemStats.GCCPUFraction) r.Register("runtime.MemStats.PauseNs", runtimeMetrics.MemStats.PauseNs) r.Register("runtime.MemStats.PauseTotalNs", runtimeMetrics.MemStats.PauseTotalNs) r.Register("runtime.MemStats.StackInuse", runtimeMetrics.MemStats.StackInuse) diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_gccpufraction.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_gccpufraction.go new file mode 100644 index 000000000..ca12c05ba --- /dev/null +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_gccpufraction.go @@ -0,0 +1,9 @@ +// +build go1.5 + +package metrics + +import "runtime" + +func gcCPUFraction(memStats *runtime.MemStats) float64 { + return memStats.GCCPUFraction +} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_no_gccpufraction.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_no_gccpufraction.go new file mode 100644 index 000000000..be96aa6f1 --- /dev/null +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_no_gccpufraction.go @@ -0,0 +1,9 @@ +// +build !go1.5 + +package metrics + +import "runtime" + +func gcCPUFraction(memStats *runtime.MemStats) float64 { + return 0 +} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_test.go deleted file mode 100644 index a0ca89479..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/runtime_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package metrics - -import ( - "runtime" - "testing" - "time" -) - -func BenchmarkRuntimeMemStats(b *testing.B) { - r := NewRegistry() - RegisterRuntimeMemStats(r) - b.ResetTimer() - for i := 0; i < b.N; i++ { - CaptureRuntimeMemStatsOnce(r) - } -} - -func TestRuntimeMemStats(t *testing.T) { - r := NewRegistry() - RegisterRuntimeMemStats(r) - CaptureRuntimeMemStatsOnce(r) - zero := runtimeMetrics.MemStats.PauseNs.Count() // Get a "zero" since GC may have run before these tests. - runtime.GC() - CaptureRuntimeMemStatsOnce(r) - if count := runtimeMetrics.MemStats.PauseNs.Count(); 1 != count-zero { - t.Fatal(count - zero) - } - runtime.GC() - runtime.GC() - CaptureRuntimeMemStatsOnce(r) - if count := runtimeMetrics.MemStats.PauseNs.Count(); 3 != count-zero { - t.Fatal(count - zero) - } - for i := 0; i < 256; i++ { - runtime.GC() - } - CaptureRuntimeMemStatsOnce(r) - if count := runtimeMetrics.MemStats.PauseNs.Count(); 259 != count-zero { - t.Fatal(count - zero) - } - for i := 0; i < 257; i++ { - runtime.GC() - } - CaptureRuntimeMemStatsOnce(r) - if count := runtimeMetrics.MemStats.PauseNs.Count(); 515 != count-zero { // We lost one because there were too many GCs between captures. - t.Fatal(count - zero) - } -} - -func TestRuntimeMemStatsBlocking(t *testing.T) { - if g := runtime.GOMAXPROCS(0); g < 2 { - t.Skipf("skipping TestRuntimeMemStatsBlocking with GOMAXPROCS=%d\n", g) - } - ch := make(chan int) - go testRuntimeMemStatsBlocking(ch) - var memStats runtime.MemStats - t0 := time.Now() - runtime.ReadMemStats(&memStats) - t1 := time.Now() - t.Log("i++ during runtime.ReadMemStats:", <-ch) - go testRuntimeMemStatsBlocking(ch) - d := t1.Sub(t0) - t.Log(d) - time.Sleep(d) - t.Log("i++ during time.Sleep:", <-ch) -} - -func testRuntimeMemStatsBlocking(ch chan int) { - i := 0 - for { - select { - case ch <- i: - return - default: - i++ - } - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/sample_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/sample_test.go deleted file mode 100644 index d60e99c5b..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/sample_test.go +++ /dev/null @@ -1,363 +0,0 @@ -package metrics - -import ( - "math/rand" - "runtime" - "testing" - "time" -) - -// Benchmark{Compute,Copy}{1000,1000000} demonstrate that, even for relatively -// expensive computations like Variance, the cost of copying the Sample, as -// approximated by a make and copy, is much greater than the cost of the -// computation for small samples and only slightly less for large samples. -func BenchmarkCompute1000(b *testing.B) { - s := make([]int64, 1000) - for i := 0; i < len(s); i++ { - s[i] = int64(i) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - SampleVariance(s) - } -} -func BenchmarkCompute1000000(b *testing.B) { - s := make([]int64, 1000000) - for i := 0; i < len(s); i++ { - s[i] = int64(i) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - SampleVariance(s) - } -} -func BenchmarkCopy1000(b *testing.B) { - s := make([]int64, 1000) - for i := 0; i < len(s); i++ { - s[i] = int64(i) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - sCopy := make([]int64, len(s)) - copy(sCopy, s) - } -} -func BenchmarkCopy1000000(b *testing.B) { - s := make([]int64, 1000000) - for i := 0; i < len(s); i++ { - s[i] = int64(i) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - sCopy := make([]int64, len(s)) - copy(sCopy, s) - } -} - -func BenchmarkExpDecaySample257(b *testing.B) { - benchmarkSample(b, NewExpDecaySample(257, 0.015)) -} - -func BenchmarkExpDecaySample514(b *testing.B) { - benchmarkSample(b, NewExpDecaySample(514, 0.015)) -} - -func BenchmarkExpDecaySample1028(b *testing.B) { - benchmarkSample(b, NewExpDecaySample(1028, 0.015)) -} - -func BenchmarkUniformSample257(b *testing.B) { - benchmarkSample(b, NewUniformSample(257)) -} - -func BenchmarkUniformSample514(b *testing.B) { - benchmarkSample(b, NewUniformSample(514)) -} - -func BenchmarkUniformSample1028(b *testing.B) { - benchmarkSample(b, NewUniformSample(1028)) -} - -func TestExpDecaySample10(t *testing.T) { - rand.Seed(1) - s := NewExpDecaySample(100, 0.99) - for i := 0; i < 10; i++ { - s.Update(int64(i)) - } - if size := s.Count(); 10 != size { - t.Errorf("s.Count(): 10 != %v\n", size) - } - if size := s.Size(); 10 != size { - t.Errorf("s.Size(): 10 != %v\n", size) - } - if l := len(s.Values()); 10 != l { - t.Errorf("len(s.Values()): 10 != %v\n", l) - } - for _, v := range s.Values() { - if v > 10 || v < 0 { - t.Errorf("out of range [0, 10): %v\n", v) - } - } -} - -func TestExpDecaySample100(t *testing.T) { - rand.Seed(1) - s := NewExpDecaySample(1000, 0.01) - for i := 0; i < 100; i++ { - s.Update(int64(i)) - } - if size := s.Count(); 100 != size { - t.Errorf("s.Count(): 100 != %v\n", size) - } - if size := s.Size(); 100 != size { - t.Errorf("s.Size(): 100 != %v\n", size) - } - if l := len(s.Values()); 100 != l { - t.Errorf("len(s.Values()): 100 != %v\n", l) - } - for _, v := range s.Values() { - if v > 100 || v < 0 { - t.Errorf("out of range [0, 100): %v\n", v) - } - } -} - -func TestExpDecaySample1000(t *testing.T) { - rand.Seed(1) - s := NewExpDecaySample(100, 0.99) - for i := 0; i < 1000; i++ { - s.Update(int64(i)) - } - if size := s.Count(); 1000 != size { - t.Errorf("s.Count(): 1000 != %v\n", size) - } - if size := s.Size(); 100 != size { - t.Errorf("s.Size(): 100 != %v\n", size) - } - if l := len(s.Values()); 100 != l { - t.Errorf("len(s.Values()): 100 != %v\n", l) - } - for _, v := range s.Values() { - if v > 1000 || v < 0 { - t.Errorf("out of range [0, 1000): %v\n", v) - } - } -} - -// This test makes sure that the sample's priority is not amplified by using -// nanosecond duration since start rather than second duration since start. -// The priority becomes +Inf quickly after starting if this is done, -// effectively freezing the set of samples until a rescale step happens. -func TestExpDecaySampleNanosecondRegression(t *testing.T) { - rand.Seed(1) - s := NewExpDecaySample(100, 0.99) - for i := 0; i < 100; i++ { - s.Update(10) - } - time.Sleep(1 * time.Millisecond) - for i := 0; i < 100; i++ { - s.Update(20) - } - v := s.Values() - avg := float64(0) - for i := 0; i < len(v); i++ { - avg += float64(v[i]) - } - avg /= float64(len(v)) - if avg > 16 || avg < 14 { - t.Errorf("out of range [14, 16]: %v\n", avg) - } -} - -func TestExpDecaySampleRescale(t *testing.T) { - s := NewExpDecaySample(2, 0.001).(*ExpDecaySample) - s.update(time.Now(), 1) - s.update(time.Now().Add(time.Hour+time.Microsecond), 1) - for _, v := range s.values.Values() { - if v.k == 0.0 { - t.Fatal("v.k == 0.0") - } - } -} - -func TestExpDecaySampleSnapshot(t *testing.T) { - now := time.Now() - rand.Seed(1) - s := NewExpDecaySample(100, 0.99) - for i := 1; i <= 10000; i++ { - s.(*ExpDecaySample).update(now.Add(time.Duration(i)), int64(i)) - } - snapshot := s.Snapshot() - s.Update(1) - testExpDecaySampleStatistics(t, snapshot) -} - -func TestExpDecaySampleStatistics(t *testing.T) { - now := time.Now() - rand.Seed(1) - s := NewExpDecaySample(100, 0.99) - for i := 1; i <= 10000; i++ { - s.(*ExpDecaySample).update(now.Add(time.Duration(i)), int64(i)) - } - testExpDecaySampleStatistics(t, s) -} - -func TestUniformSample(t *testing.T) { - rand.Seed(1) - s := NewUniformSample(100) - for i := 0; i < 1000; i++ { - s.Update(int64(i)) - } - if size := s.Count(); 1000 != size { - t.Errorf("s.Count(): 1000 != %v\n", size) - } - if size := s.Size(); 100 != size { - t.Errorf("s.Size(): 100 != %v\n", size) - } - if l := len(s.Values()); 100 != l { - t.Errorf("len(s.Values()): 100 != %v\n", l) - } - for _, v := range s.Values() { - if v > 1000 || v < 0 { - t.Errorf("out of range [0, 100): %v\n", v) - } - } -} - -func TestUniformSampleIncludesTail(t *testing.T) { - rand.Seed(1) - s := NewUniformSample(100) - max := 100 - for i := 0; i < max; i++ { - s.Update(int64(i)) - } - v := s.Values() - sum := 0 - exp := (max - 1) * max / 2 - for i := 0; i < len(v); i++ { - sum += int(v[i]) - } - if exp != sum { - t.Errorf("sum: %v != %v\n", exp, sum) - } -} - -func TestUniformSampleSnapshot(t *testing.T) { - s := NewUniformSample(100) - for i := 1; i <= 10000; i++ { - s.Update(int64(i)) - } - snapshot := s.Snapshot() - s.Update(1) - testUniformSampleStatistics(t, snapshot) -} - -func TestUniformSampleStatistics(t *testing.T) { - rand.Seed(1) - s := NewUniformSample(100) - for i := 1; i <= 10000; i++ { - s.Update(int64(i)) - } - testUniformSampleStatistics(t, s) -} - -func benchmarkSample(b *testing.B, s Sample) { - var memStats runtime.MemStats - runtime.ReadMemStats(&memStats) - pauseTotalNs := memStats.PauseTotalNs - b.ResetTimer() - for i := 0; i < b.N; i++ { - s.Update(1) - } - b.StopTimer() - runtime.GC() - runtime.ReadMemStats(&memStats) - b.Logf("GC cost: %d ns/op", int(memStats.PauseTotalNs-pauseTotalNs)/b.N) -} - -func testExpDecaySampleStatistics(t *testing.T, s Sample) { - if count := s.Count(); 10000 != count { - t.Errorf("s.Count(): 10000 != %v\n", count) - } - if min := s.Min(); 107 != min { - t.Errorf("s.Min(): 107 != %v\n", min) - } - if max := s.Max(); 10000 != max { - t.Errorf("s.Max(): 10000 != %v\n", max) - } - if mean := s.Mean(); 4965.98 != mean { - t.Errorf("s.Mean(): 4965.98 != %v\n", mean) - } - if stdDev := s.StdDev(); 2959.825156930727 != stdDev { - t.Errorf("s.StdDev(): 2959.825156930727 != %v\n", stdDev) - } - ps := s.Percentiles([]float64{0.5, 0.75, 0.99}) - if 4615 != ps[0] { - t.Errorf("median: 4615 != %v\n", ps[0]) - } - if 7672 != ps[1] { - t.Errorf("75th percentile: 7672 != %v\n", ps[1]) - } - if 9998.99 != ps[2] { - t.Errorf("99th percentile: 9998.99 != %v\n", ps[2]) - } -} - -func testUniformSampleStatistics(t *testing.T, s Sample) { - if count := s.Count(); 10000 != count { - t.Errorf("s.Count(): 10000 != %v\n", count) - } - if min := s.Min(); 37 != min { - t.Errorf("s.Min(): 37 != %v\n", min) - } - if max := s.Max(); 9989 != max { - t.Errorf("s.Max(): 9989 != %v\n", max) - } - if mean := s.Mean(); 4748.14 != mean { - t.Errorf("s.Mean(): 4748.14 != %v\n", mean) - } - if stdDev := s.StdDev(); 2826.684117548333 != stdDev { - t.Errorf("s.StdDev(): 2826.684117548333 != %v\n", stdDev) - } - ps := s.Percentiles([]float64{0.5, 0.75, 0.99}) - if 4599 != ps[0] { - t.Errorf("median: 4599 != %v\n", ps[0]) - } - if 7380.5 != ps[1] { - t.Errorf("75th percentile: 7380.5 != %v\n", ps[1]) - } - if 9986.429999999998 != ps[2] { - t.Errorf("99th percentile: 9986.429999999998 != %v\n", ps[2]) - } -} - -// TestUniformSampleConcurrentUpdateCount would expose data race problems with -// concurrent Update and Count calls on Sample when test is called with -race -// argument -func TestUniformSampleConcurrentUpdateCount(t *testing.T) { - if testing.Short() { - t.Skip("skipping in short mode") - } - s := NewUniformSample(100) - for i := 0; i < 100; i++ { - s.Update(int64(i)) - } - quit := make(chan struct{}) - go func() { - t := time.NewTicker(10 * time.Millisecond) - for { - select { - case <-t.C: - s.Update(rand.Int63()) - case <-quit: - t.Stop() - return - } - } - }() - for i := 0; i < 1000; i++ { - s.Count() - time.Sleep(5 * time.Millisecond) - } - quit <- struct{}{} -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/timer_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/timer_test.go deleted file mode 100644 index 2fa415d40..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/timer_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package metrics - -import ( - "math" - "testing" - "time" -) - -func BenchmarkTimer(b *testing.B) { - tm := NewTimer() - b.ResetTimer() - for i := 0; i < b.N; i++ { - tm.Update(1) - } -} - -func TestGetOrRegisterTimer(t *testing.T) { - r := NewRegistry() - NewRegisteredTimer("foo", r).Update(47) - if tm := GetOrRegisterTimer("foo", r); 1 != tm.Count() { - t.Fatal(tm) - } -} - -func TestTimerExtremes(t *testing.T) { - tm := NewTimer() - tm.Update(math.MaxInt64) - tm.Update(0) - if stdDev := tm.StdDev(); 4.611686018427388e+18 != stdDev { - t.Errorf("tm.StdDev(): 4.611686018427388e+18 != %v\n", stdDev) - } -} - -func TestTimerFunc(t *testing.T) { - tm := NewTimer() - tm.Time(func() { time.Sleep(50e6) }) - if max := tm.Max(); 45e6 > max || max > 55e6 { - t.Errorf("tm.Max(): 45e6 > %v || %v > 55e6\n", max, max) - } -} - -func TestTimerZero(t *testing.T) { - tm := NewTimer() - if count := tm.Count(); 0 != count { - t.Errorf("tm.Count(): 0 != %v\n", count) - } - if min := tm.Min(); 0 != min { - t.Errorf("tm.Min(): 0 != %v\n", min) - } - if max := tm.Max(); 0 != max { - t.Errorf("tm.Max(): 0 != %v\n", max) - } - if mean := tm.Mean(); 0.0 != mean { - t.Errorf("tm.Mean(): 0.0 != %v\n", mean) - } - if stdDev := tm.StdDev(); 0.0 != stdDev { - t.Errorf("tm.StdDev(): 0.0 != %v\n", stdDev) - } - ps := tm.Percentiles([]float64{0.5, 0.75, 0.99}) - if 0.0 != ps[0] { - t.Errorf("median: 0.0 != %v\n", ps[0]) - } - if 0.0 != ps[1] { - t.Errorf("75th percentile: 0.0 != %v\n", ps[1]) - } - if 0.0 != ps[2] { - t.Errorf("99th percentile: 0.0 != %v\n", ps[2]) - } - if rate1 := tm.Rate1(); 0.0 != rate1 { - t.Errorf("tm.Rate1(): 0.0 != %v\n", rate1) - } - if rate5 := tm.Rate5(); 0.0 != rate5 { - t.Errorf("tm.Rate5(): 0.0 != %v\n", rate5) - } - if rate15 := tm.Rate15(); 0.0 != rate15 { - t.Errorf("tm.Rate15(): 0.0 != %v\n", rate15) - } - if rateMean := tm.RateMean(); 0.0 != rateMean { - t.Errorf("tm.RateMean(): 0.0 != %v\n", rateMean) - } -} diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/validate.sh b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/validate.sh new file mode 100644 index 000000000..f6499982e --- /dev/null +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/validate.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +# check there are no formatting issues +GOFMT_LINES=`gofmt -l . | wc -l | xargs` +test $GOFMT_LINES -eq 0 || echo "gofmt needs to be run, ${GOFMT_LINES} files have issues" + +# run the tests for the root package +go test . diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/writer_test.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/writer_test.go deleted file mode 100644 index 1aacc2871..000000000 --- a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/writer_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package metrics - -import ( - "sort" - "testing" -) - -func TestMetricsSorting(t *testing.T) { - var namedMetrics = namedMetricSlice{ - {name: "zzz"}, - {name: "bbb"}, - {name: "fff"}, - {name: "ggg"}, - } - - sort.Sort(namedMetrics) - for i, name := range []string{"bbb", "fff", "ggg", "zzz"} { - if namedMetrics[i].name != name { - t.Fail() - } - } -} |