[tor-commits] [flashproxy/master] Extract client requests for graphing with R.

dcf at torproject.org dcf at torproject.org
Wed Feb 20 17:30:39 UTC 2013


commit eea5ed742bcc4399f7262aeea9ba7db94da7fded
Author: David Fifield <david at bamsoftware.com>
Date:   Wed Feb 20 04:07:31 2013 -0800

    Extract client requests for graphing with R.
---
 experiments/client-extract.py |   50 +++++++++++++++++++++++++++++++++++++++++
 experiments/client-graph.r    |    5 ++++
 2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/experiments/client-extract.py b/experiments/client-extract.py
new file mode 100755
index 0000000..4df242c
--- /dev/null
+++ b/experiments/client-extract.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+import datetime
+import getopt
+import re
+import sys
+
+def usage(f = sys.stdout):
+    print >> f, """\
+Usage: %s [INPUTFILE]
+Extract client connections from a facilitator log. Each output line is
+    date\tcount\n
+where count is the number of client requests in that hour.
+
+  -h, --help           show this help.
+""" % sys.argv[0]
+
+opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help"])
+for o, a in opts:
+    if o == "-h" or o == "--help":
+        usage()
+        sys.exit()
+
+if len(args) == 0:
+    input_file = sys.stdin
+elif len(args) == 1:
+    input_file = open(args[0])
+else:
+    usage()
+    sys.exit()
+
+prev_output = None
+count = 0.0
+
+for line in input_file:
+    m = re.match(r'^(\d+-\d+-\d+ \d+:\d+:\d+) client', line)
+    if not m:
+        continue
+    date_str, = m.groups()
+    date = datetime.datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
+
+    count += 1
+
+    rounded_date = date.replace(minute=0, second=0, microsecond=0)
+    prev_output = prev_output or rounded_date
+    if prev_output is None or rounded_date != prev_output:
+        avg = float(count)
+        print date.strftime("%Y-%m-%d %H:%M:%S") + "\t" + "%.2f" % avg
+        prev_output = rounded_date
+        count = 0.0
diff --git a/experiments/client-graph.r b/experiments/client-graph.r
new file mode 100644
index 0000000..a17647f
--- /dev/null
+++ b/experiments/client-graph.r
@@ -0,0 +1,5 @@
+library(ggplot2)
+x <- read.delim("client.dat", header=FALSE, col.names=c("date", "count"), colClasses=c("POSIXct", "numeric"))
+
+png("client-count.png", width=720, height=480)
+qplot(date, data=x, geom="bar", weight=count, binwidth=86400, ylab="client requests per day")



More information about the tor-commits mailing list