squidTally.py
#!/usr/bin/env python
"""
$Id: squidTally.py 1259 2003-05-27 10:52:14Z david $
This python script tallies the usage per user in bytes from Squid's
access.log. It will only work for logs in native log format produced
by version 2 of Squid. We use hashes to ensure we don't throttle the
system when updating each user.
"""
import sys
userlist = {}
# Tally each user
for line in sys.stdin:
# Extract usage details
fields = line.split()
bytes = int(fields[4])
name = fields[7]
if name != '-':
# Add to the tally
if not name in userlist.keys():
userlist[name] = 0
userlist[name] = userlist[name] + bytes
# Produce the results to stdout
for user in userlist.keys():
print user, userlist[user]
|