mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Log once a day how many connections had client_ip.
This is a sanity check against any catastrophic failure of our parsing code.
This commit is contained in:
parent
c84e1a2e03
commit
d9e8f8f647
2 changed files with 44 additions and 0 deletions
|
@ -269,6 +269,8 @@ func main() {
|
|||
log.Fatalf("error in setup: %s", err)
|
||||
}
|
||||
|
||||
go statsThread()
|
||||
|
||||
var certManager *autocert.Manager
|
||||
if !disableTLS {
|
||||
log.Printf("ACME hostnames: %q", acmeHostnames)
|
||||
|
|
42
server/stats.go
Normal file
42
server/stats.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package main
|
||||
|
||||
// This code handled 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()
|
||||
for {
|
||||
select {
|
||||
case v := <-statsChannel:
|
||||
if v {
|
||||
numClientIP += 1
|
||||
}
|
||||
numConnections += 1
|
||||
case <-time.After(statsInterval):
|
||||
now := time.Now()
|
||||
log.Printf("in the past %.g s, %d/%d connections had client_ip",
|
||||
(now.Sub(prevTime)).Seconds(),
|
||||
numClientIP, numConnections)
|
||||
numClientIP = 0
|
||||
numConnections = 0
|
||||
prevTime = now
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue