r19808 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19807‎ | r19808 | r19809 >
Date:00:57, 7 February 2007
Author:brion
Status:old
Tags:
Comment:
quickie tool to break down bandwidth usage from squid logs
Modified paths:
  • /trunk/tools/bandbreakdown (added) (history)
  • /trunk/tools/bandbreakdown/bandbreakdown.py (added) (history)

Diff [purge]

Index: trunk/tools/bandbreakdown/bandbreakdown.py
@@ -0,0 +1,53 @@
 2+#!/usr/bin/python
 3+
 4+import re
 5+import sys
 6+
 7+lineSplit = re.compile(r"^[\w.]+ \d+ [0-9.]+ \d+ [\d.]+ \w+/\d+ (\d+) \w+ (\S+)")
 8+
 9+matchTypes = [
 10+ ("upload", re.compile(r"^http://upload.wikimedia.org/")),
 11+ ("article", re.compile(r"^http://[^/]+/wiki/")),
 12+ ("wikifiles", re.compile(r"^http://[^/]+/w/")),
 13+ ("skins-css", re.compile(r"^http://[^/]+/skins-1.5/.*\.css")),
 14+ ("skins-js", re.compile(r"^http://[^/]+/skins-1.5/.*\.js")),
 15+ ("skins-image", re.compile(r"^http://[^/]+/skins-1.5/.*\.(?:png|gif|jpg)"))]
 16+groups = [group for (group, regex) in matchTypes]
 17+groups.append("other")
 18+
 19+totalHits = 0
 20+totalBytes = 0
 21+hits = {}
 22+bytes = {}
 23+for group in groups:
 24+ hits[group] = 0
 25+ bytes[group] = 0
 26+
 27+for line in sys.stdin:
 28+ matches = lineSplit.match(line)
 29+ if matches:
 30+ size = int(matches.group(1))
 31+ url = matches.group(2)
 32+ totalHits += 1
 33+ totalBytes += size
 34+ for (group, regex) in matchTypes:
 35+ if regex.match(url):
 36+ hits[group] += 1
 37+ bytes[group] += size
 38+ break
 39+ else:
 40+ hits["other"] += 1
 41+ bytes["other"] += size
 42+
 43+if totalHits == 0 or totalBytes == 0:
 44+ print "no hits detected :("
 45+
 46+for group in groups:
 47+ if hits[group] > 0:
 48+ print "%12s %8d hits (%6.2f%%) %16d bytes (%6.2f%%) %10.1f bytes/hit" % (
 49+ group,
 50+ hits[group],
 51+ 100.0 * float(hits[group]) / float(totalHits),
 52+ bytes[group],
 53+ 100.0 * float(bytes[group]) / float(totalBytes),
 54+ float(bytes[group]) / float(hits[group]))
Property changes on: trunk/tools/bandbreakdown/bandbreakdown.py
___________________________________________________________________
Added: svn:eol-style
155 + native