Fix periodic stats reporting.

The time interval was being reset every time a new connection came in.
This commit is contained in:
David Fifield 2017-10-19 00:00:26 -07:00
parent 99604ff15a
commit 085f253757

View file

@ -22,6 +22,7 @@ var (
func statsThread() { func statsThread() {
var numClientIP, numConnections uint64 var numClientIP, numConnections uint64
prevTime := time.Now() prevTime := time.Now()
deadline := time.After(statsInterval)
for { for {
select { select {
case v := <-statsChannel: case v := <-statsChannel:
@ -29,7 +30,7 @@ func statsThread() {
numClientIP += 1 numClientIP += 1
} }
numConnections += 1 numConnections += 1
case <-time.After(statsInterval): case <-deadline:
now := time.Now() now := time.Now()
log.Printf("in the past %.g s, %d/%d connections had client_ip", log.Printf("in the past %.g s, %d/%d connections had client_ip",
(now.Sub(prevTime)).Seconds(), (now.Sub(prevTime)).Seconds(),
@ -37,6 +38,7 @@ func statsThread() {
numClientIP = 0 numClientIP = 0
numConnections = 0 numConnections = 0
prevTime = now prevTime = now
deadline = time.After(statsInterval)
} }
} }
} }