Last active
August 29, 2015 13:56
-
-
Save austinhappel/8910564 to your computer and use it in GitHub Desktop.
pipe `ping` command into this and get csv-friendly data for graphing. Usage: `ping -D | ./ping2csv.py > file.csv`. Note: the `-D` might not be supported on your implementation of `ping`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import datetime | |
import re | |
# usage: `ping -D google.com | ./ping2csv.py > file.csv` | |
try: | |
buff = '' | |
while True: | |
buff += sys.stdin.read(1) | |
if len(buff) == 0: | |
exit(1) | |
if buff.endswith('\n'): | |
temp = buff[:-1] | |
matches = re.search('\[([0-9\.]+)\].*time\=([0-9\.]+)', temp) | |
if hasattr(matches, 'group'): | |
timestamp = datetime.datetime.fromtimestamp(float(matches.group(1))) | |
ping = matches.group(2) | |
print("%s,%s" % (timestamp, ping)) | |
buff = '' | |
except KeyboardInterrupt: | |
sys.stdout.flush() | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment