Esempio n. 1
0
func populateNormalHistogram(t *testing.T, h metrics.Histogram, seed int64, mean, stdev int64) {
	rand.Seed(seed)
	for i := 0; i < 1234; i++ {
		sample := int64(rand.NormFloat64()*float64(stdev) + float64(mean))
		h.Observe(sample)
	}
}
Esempio n. 2
0
func httpInstrument(requests metrics.Counter, duration metrics.Histogram) func(http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			requests.Add(1)
			defer func(begin time.Time) { duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now())
			next.ServeHTTP(w, r)
		})
	}
}
Esempio n. 3
0
// PopulateNormalHistogram makes a series of normal random observations into the
// histogram. The number of observations is determined by Count. The randomness
// is determined by Mean, Stdev, and the seed parameter.
//
// This is a low-level function, exported only for metrics that don't perform
// dynamic quantile computation, like a Prometheus Histogram (c.f. Summary). In
// most cases, you don't need to use this function, and can use TestHistogram
// instead.
func PopulateNormalHistogram(h metrics.Histogram, seed int) {
	r := rand.New(rand.NewSource(int64(seed)))
	for i := 0; i < Count; i++ {
		sample := r.NormFloat64()*float64(Stdev) + float64(Mean)
		if sample < 0 {
			sample = 0
		}
		h.Observe(sample)
	}
}
Esempio n. 4
0
File: common.go Progetto: qband/down
// PopulateNormalHistogram populates the Histogram with a normal distribution
// of observations.
func PopulateNormalHistogram(t *testing.T, h metrics.Histogram, seed int64, mean, stdev int64) {
	r := rand.New(rand.NewSource(seed))
	for i := 0; i < population; i++ {
		sample := int64(r.NormFloat64()*float64(stdev) + float64(mean))
		if sample < 0 {
			sample = 0
		}
		h.Observe(sample)
	}
}
Esempio n. 5
0
func Measure(h metrics.Histogram, d time.Duration) {
	if h != nil && archaius.Conf.Collect {
		if d > maxHistObservable {
			h.Observe(int64(maxHistObservable))
		} else {
			h.Observe(int64(d))
		}
		s := sampleMap[h]
		if s != nil && len(s) < sampleCount {
			sampleMap[h] = append(s, int64(d))
		}
	}
}