blob: 80e9e49903c1c73aae4c26c5c6b722bf6fb3768c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package main
// This code handles periodic statistics logging.
//
// The only thing it keeps track of is how many connections had the client_ip
// parameter. Write true to statsChannel to record a connection with client_ip;
// write false for without.
import (
"log"
"time"
)
const (
statsInterval = 24 * time.Hour
)
var (
statsChannel = make(chan bool)
)
func statsThread() {
var numClientIP, numConnections uint64
prevTime := time.Now()
deadline := time.After(statsInterval)
for {
select {
case v := <-statsChannel:
if v {
numClientIP++
}
numConnections++
case <-deadline:
now := time.Now()
log.Printf("in the past %.f s, %d/%d connections had client_ip",
(now.Sub(prevTime)).Seconds(),
numClientIP, numConnections)
numClientIP = 0
numConnections = 0
prevTime = now
deadline = time.After(statsInterval)
}
}
}
|