Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorjohmathe <johmathe@google.com>2008-08-17 02:25:11 +0400
committerjohmathe <johmathe@google.com>2008-08-17 02:25:11 +0400
commit57a08fc40c891c5670bfbeb331f49d9aaf86e5a3 (patch)
tree8ad131e112222229fd720f533b459a3aa53cc9d5 /misc
parent7db5a547e541f47e3ea0839beb7f244546ccee51 (diff)
Adds the python log player (beta).
git-svn-id: http://dev.piwik.org/svn/trunk@611 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'misc')
-rw-r--r--misc/log_player.py.script91
1 files changed, 91 insertions, 0 deletions
diff --git a/misc/log_player.py.script b/misc/log_player.py.script
new file mode 100644
index 0000000000..c32fd97da3
--- /dev/null
+++ b/misc/log_player.py.script
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+# This script is part of the piwik project
+# author : Johan Mathe <johan.mathe@tremplin-utc.net>
+# Licence : GPL
+# works with the following apache log config :
+# LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\"" combinedcookie-stressme
+
+#TODO
+#cookie
+#headers IP;browser etc
+#+ expliquer quels params changer pour duree visite
+
+import getopt
+import sys
+import os
+import time
+import urllib2
+
+class player:
+ def __init__(self, logFile, hostName, delay = 0, verbose = False):
+ self.logFile = logFile;
+ self.hostName = hostName;
+ self.delay = delay
+ self.verbose = verbose
+ def play(self):
+ fd = open(self.logFile)
+ for line in fd.readlines():
+ fields = line.split(' ')
+ uri = fields[6]
+ url = "http://%(w)s/%(u)s" % {'w' : self.hostName, 'u' : uri};
+ if self.verbose:
+ print url
+ try:
+ req = urllib2.Request(url)
+ handle = urllib2.urlopen(req)
+ the_page = handle.read()
+ except IOError, e:
+ if e.code == 404:
+ print "404 error : %s" % url
+ else:
+ print "Unknown error while opening URL %s" % url
+ except KeyboardInterrupt:
+ print "Keyboard interrupt"
+ sys.exit()
+ time.sleep(self.delay)
+
+class Usage(Exception):
+ def __init__(self, msg):
+ self.msg = msg
+
+def usage():
+ print "--help : show this help\n--log : logfile\n--host : host name\n--delay : delay in sec"
+
+def main(argv=None):
+ hostName = ""
+ logFile = ""
+ verbose = False
+ delay = 0
+ if argv is None:
+ argv = sys.argv
+ try:
+ try:
+ opts, args = getopt.getopt(argv[1:], "vhf:h:d:", ["help","log=","host=","delay="])
+ except getopt.error, msg:
+ raise Usage(msg)
+ for o, a in opts:
+ if o == "-v":
+ verbose = True
+ elif o in ("f", "--log"):
+ logFile = a
+ elif o in ("h", "--host"):
+ hostName = a
+ elif o in ("-h", "--help"):
+ usage()
+ sys.exit()
+ elif o in ("-d", "--delay"):
+ delay = float(a)
+ else:
+ assert False, "unhandled option"
+ if not hostName or not logFile:
+ raise Usage("Plase specify the host name and the log file.")
+
+ p = player(logFile, hostName, delay, verbose)
+ p.play()
+ except Usage, err:
+ print >>sys.stderr, err.msg
+ print >>sys.stderr, "for help use --help"
+ return 2
+
+if __name__ == "__main__":
+ sys.exit(main())