[tor-commits] [snowflake/master] Log once a day how many connections had client_ip.
dcf at torproject.org
dcf at torproject.org
Wed Oct 18 05:14:25 UTC 2017
commit d9e8f8f6479a8b4abe31eb5bfb9023de1bbca8af
Author: David Fifield <david at bamsoftware.com>
Date: Tue Oct 17 21:45:36 2017 -0700
Log once a day how many connections had client_ip.
This is a sanity check against any catastrophic failure of our parsing
code.
---
server/server.go | 2 ++
server/stats.go | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/server/server.go b/server/server.go
index 3c97e06..1b33661 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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)
diff --git a/server/stats.go b/server/stats.go
new file mode 100644
index 0000000..1aeefb5
--- /dev/null
+++ b/server/stats.go
@@ -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
+ }
+ }
+}
More information about the tor-commits
mailing list