Skip to content

Instantly share code, notes, and snippets.

@Kami
Created February 16, 2013 05:45
Show Gist options
  • Select an option

  • Save Kami/4965708 to your computer and use it in GitHub Desktop.

Select an option

Save Kami/4965708 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
totals = {'packets': 0, 'traffic': 0}
with open('traffic.log', 'r') as fp:
content = fp.read()
lines = content.split('\n')
for line in lines:
if 'External' not in line:
continue
matches = re.search('.*(\d+\.\d+) packets/300s.*(\d+) MBit.*', line)
if not matches:
continue
groups = matches.groups()
packets = float(groups[0])
traffic = float(groups[1])
totals['packets'] += packets
totals['traffic'] += traffic
print 'Totals'
print '%s pkts/s, %s Mb/s' % (totals['packets'], totals['traffic'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment