Esempio n. 1
0
// New wraps the datastore, providing metrics on the operations. The
// metrics are registered with names starting with prefix and a dot.
//
// If prefix is not unique, New will panic. Call Close to release the
// prefix.
func New(prefix string, ds datastore.Datastore) *measure {
	m := &measure{
		backend: ds,

		putNum:     metrics.Counter(prefix + ".Put.num"),
		putErr:     metrics.Counter(prefix + ".Put.err"),
		putLatency: metrics.NewHistogram(prefix+".Put.latency", 0, maxLatency, 3),
		putSize:    metrics.NewHistogram(prefix+".Put.size", 0, maxSize, 3),

		getNum:     metrics.Counter(prefix + ".Get.num"),
		getErr:     metrics.Counter(prefix + ".Get.err"),
		getLatency: metrics.NewHistogram(prefix+".Get.latency", 0, maxLatency, 3),
		getSize:    metrics.NewHistogram(prefix+".Get.size", 0, maxSize, 3),

		hasNum:     metrics.Counter(prefix + ".Has.num"),
		hasErr:     metrics.Counter(prefix + ".Has.err"),
		hasLatency: metrics.NewHistogram(prefix+".Has.latency", 0, maxLatency, 3),

		deleteNum:     metrics.Counter(prefix + ".Delete.num"),
		deleteErr:     metrics.Counter(prefix + ".Delete.err"),
		deleteLatency: metrics.NewHistogram(prefix+".Delete.latency", 0, maxLatency, 3),

		queryNum:     metrics.Counter(prefix + ".Query.num"),
		queryErr:     metrics.Counter(prefix + ".Query.err"),
		queryLatency: metrics.NewHistogram(prefix+".Query.latency", 0, maxLatency, 3),
	}
	return m
}
Esempio n. 2
0
func TestHistogramRemove(t *testing.T) {
	metrics.Reset()

	h := metrics.NewHistogram("heyo", 1, 1000, 3)
	h.Remove()

	_, gauges := metrics.Snapshot()
	if v, ok := gauges["heyo.P50"]; ok {
		t.Errorf("Gauge was %v, but expected nothing", v)
	}
}
Esempio n. 3
0
func BenchmarkHistogramRecordValue(b *testing.B) {
	metrics.Reset()
	h := metrics.NewHistogram("hist", 1, 1000, 3)

	b.ReportAllocs()
	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			h.RecordValue(100)
		}
	})
}
Esempio n. 4
0
func TestHistogram(t *testing.T) {
	metrics.Reset()

	h := metrics.NewHistogram("heyo", 1, 1000, 3)
	for i := 100; i > 0; i-- {
		for j := 0; j < i; j++ {
			h.RecordValue(int64(i))
		}
	}

	_, gauges := metrics.Snapshot()

	if v, want := gauges["heyo.P50"], int64(71); v != want {
		t.Errorf("P50 was %v, but expected %v", v, want)
	}

	if v, want := gauges["heyo.P75"], int64(87); v != want {
		t.Errorf("P75 was %v, but expected %v", v, want)
	}

	if v, want := gauges["heyo.P90"], int64(95); v != want {
		t.Errorf("P90 was %v, but expected %v", v, want)
	}

	if v, want := gauges["heyo.P95"], int64(98); v != want {
		t.Errorf("P95 was %v, but expected %v", v, want)
	}

	if v, want := gauges["heyo.P99"], int64(100); v != want {
		t.Errorf("P99 was %v, but expected %v", v, want)
	}

	if v, want := gauges["heyo.P999"], int64(100); v != want {
		t.Errorf("P999 was %v, but expected %v", v, want)
	}
}