Exemple #1
0
//measure the time
func (proxy *Metrics) measure(startTime time.Time, query string) {
	elapsedTime := time.Now().Sub(startTime)
	if Summary {
		if proxy.timers[query] == nil {
			mutex.Lock()
			if proxy.timers[query] == nil {
				proxy.timers[query] = metrics.NewTimer()
			}
			mutex.Unlock()
		}
		proxy.timers[query].Update(elapsedTime)
	}
	if Verbose {
		proxy.printVerbose(elapsedTime, query)
	}
}
Exemple #2
0
func (proxy *Metrics) printMetrics(duration int) {
	for query, timer := range proxy.timers {
		count := timer.Count()
		if count > 0 {
			fmt.Printf(
				"time:%v\tdb:%s\tquery:%s\tcount:%d\tmax:%f\tmean:%f\tmin:%f\tpercentile95:%f\tsum:%f\tduration:%d\n",
				time.Now(),
				proxy.name,
				query,
				timer.Count(),
				float64(timer.Max())/float64(time.Second),
				timer.Mean()/float64(time.Second),
				float64(timer.Min())/float64(time.Second),
				timer.Percentile(0.95)/float64(time.Second),
				float64(timer.Sum())/float64(time.Second),
				duration,
			)
			proxy.timers[query] = metrics.NewTimer()
		}
	}
}