mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 03:02:07 +03:00
Merge pull request #84 in DNS/adguard-dns from avg_time_fix to master
* commit 'f0823f119573ac17f0bc1cacd10b527227b128c3': Fixup of previous commit.
This commit is contained in:
commit
59323b2008
@ -228,7 +228,8 @@ func (h *histogram) Collect(ch chan<- prometheus.Metric) {
|
|||||||
// stats
|
// stats
|
||||||
// -----
|
// -----
|
||||||
func handleStats(w http.ResponseWriter, r *http.Request) {
|
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
|
// sum them up
|
||||||
summed := map[string]interface{}{}
|
summed := map[string]interface{}{}
|
||||||
for key, values := range histrical {
|
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
|
// don't forget to divide by number of elements in returned slice
|
||||||
if val, ok := summed["avg_processing_time"]; ok {
|
if val, ok := summed["avg_processing_time"]; ok {
|
||||||
if flval, flok := val.(float64); flok {
|
if flval, flok := val.(float64); flok {
|
||||||
flval /= float64(len(histrical))
|
flval /= numHours
|
||||||
summed["avg_processing_time"] = flval
|
summed["avg_processing_time"] = flval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,9 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti
|
|||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
|
over := 0
|
||||||
|
max := 10000 * time.Second
|
||||||
|
var sum time.Duration
|
||||||
// entries on file are in oldest->newest order
|
// entries on file are in oldest->newest order
|
||||||
// we want maxLen newest
|
// we want maxLen newest
|
||||||
for d.More() {
|
for d.More() {
|
||||||
@ -225,6 +228,12 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if entry.Elapsed > max {
|
||||||
|
over++
|
||||||
|
} else {
|
||||||
|
sum += entry.Elapsed
|
||||||
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
err = onEntry(&entry)
|
err = onEntry(&entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -233,10 +242,12 @@ func genericLoader(onEntry func(entry *logEntry) error, needMore func() bool, ti
|
|||||||
}
|
}
|
||||||
elapsed := time.Since(now)
|
elapsed := time.Since(now)
|
||||||
var perunit time.Duration
|
var perunit time.Duration
|
||||||
|
var avg time.Duration
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
perunit = elapsed / time.Duration(i)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user