diff --git a/coredns_plugin/coredns_stats.go b/coredns_plugin/coredns_stats.go index 668e6681..22ad57d0 100644 --- a/coredns_plugin/coredns_stats.go +++ b/coredns_plugin/coredns_stats.go @@ -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 } } diff --git a/coredns_plugin/querylog_file.go b/coredns_plugin/querylog_file.go index 2f23bfa5..a36812c2 100644 --- a/coredns_plugin/querylog_file.go +++ b/coredns_plugin/querylog_file.go @@ -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 }