Fixup of previous commit.

This commit is contained in:
Eugene Bujak 2018-10-15 19:34:31 +03:00
parent 1ed9faa0c2
commit f0823f1195
2 changed files with 15 additions and 3 deletions

View file

@ -228,7 +228,8 @@ func (h *histogram) Collect(ch chan<- prometheus.Metric) {
// stats
// -----
func handleStats(w http.ResponseWriter, r *http.Request) {
histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
const numHours = 24
histrical := generateMapFromStats(&statistics.PerHour, 0, numHours)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
@ -245,7 +246,7 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
// don't forget to divide by number of elements in returned slice
if val, ok := summed["avg_processing_time"]; ok {
if flval, flok := val.(float64); flok {
flval /= float64(len(histrical))
flval /= numHours
summed["avg_processing_time"] = flval
}
}

View file

@ -206,6 +206,9 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti
}
i := 0
over := 0
max := 10000 * time.Second
var sum time.Duration
// entries on file are in oldest->newest order
// we want maxLen newest
for d.More() {
@ -225,6 +228,12 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti
continue
}
if entry.Elapsed > max {
over++
} else {
sum += entry.Elapsed
}
i++
err = onEntry(&entry)
if err != nil {
@ -233,10 +242,12 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti
}
elapsed := time.Since(now)
var perunit time.Duration
var avg time.Duration
if i > 0 {
perunit = elapsed / time.Duration(i)
avg = sum / time.Duration(i)
}
log.Printf("file \"%s\": read %d entries in %v, %v/entry", file, i, elapsed, perunit)
log.Printf("file \"%s\": read %d entries in %v, %v/entry, %v over %v, %v avg", file, i, elapsed, perunit, over, max, avg)
}
return nil
}