admin | f73f051 | 2013-12-17 16:33:37 -0800 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import sys |
| 3 | import time |
| 4 | import os |
| 5 | import re |
| 6 | import json |
| 7 | |
| 8 | |
| 9 | CONFIG_FILE="/home/admin/ping.h10" |
| 10 | |
| 11 | |
| 12 | |
| 13 | def get_times(pingfile): |
| 14 | icmp_reqs = [] |
| 15 | times = [] |
| 16 | f = open(pingfile) |
| 17 | for line in f.readlines(): |
| 18 | if re.search('64\sbytes', line): |
| 19 | icmp_reqs.append( (line.split()[4]).split('=')[1] ) |
| 20 | f.close() |
| 21 | #print icmp_reqs |
| 22 | lastnum = int(icmp_reqs[0]) - 1 |
| 23 | for num in icmp_reqs: |
| 24 | if int(num) != (lastnum + 1): |
| 25 | times.append(int(num) - lastnum) |
| 26 | lastnum = int(num) |
| 27 | |
| 28 | return times |
| 29 | |
| 30 | if __name__ == "__main__": |
| 31 | total = 0 |
| 32 | count = 0 |
| 33 | flow = 1 |
| 34 | for i in os.popen("ls /tmp/ping.*"): |
| 35 | print "Flow %d " % flow |
| 36 | for time in get_times(i.strip("\n")): |
| 37 | total = total + time |
| 38 | count = count + 1 |
| 39 | print " %d" % time |
| 40 | flow = flow + 1 |
| 41 | print "Average: %d" % (total / count ) |
| 42 | |