Skip to content

Instantly share code, notes, and snippets.

@ernestom
Last active December 16, 2015 03:18
Show Gist options
  • Save ernestom/5368510 to your computer and use it in GitHub Desktop.
Save ernestom/5368510 to your computer and use it in GitHub Desktop.
USAGE: $ bash simpletest.sh 1> test_results.txt
#!/bin/bash
#
# USAGE: bash simpletest.sh 1> test_results.txt
#
URL="http://ss2.clarovideo.com/multimediav81/plataforma_vod/ISM/WMP4H00890MTDP_full/WMP4H00890MTDP_full.ism/QualityLevels(2524000)/Fragments(video=60060000)"
# How many times should we request the URL?
TOTAL_REQUESTS=20
# How much time to wait between requests? in seconds
INTERVAL=60
###### Do not modify below this point #######
IP=`curl -fs http://ip.42.pl/raw 2> /dev/null`
DNS=`dig google.com | grep SERVER | awk '{print $3}' | cut -d '#' -f1`
PRAGMA="akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no"
IX=0
while [ $IX -lt $TOTAL_REQUESTS ]; do
let IX=$IX+1
echo -n "TEST $IX in progress... " >&2
echo "**** $IX"
echo `date "+%Y-%m-%dT%H:%M:%S-%Z"` "$IP-$DNS-$URL"
echo
curl -s -w "Downloaded %{size_download} bytes in %{time_total} seconds at %{speed_download} bytes/s.\n" -H "Pragma: $PRAGMA" -D - "$URL" -o /dev/null
echo
echo "done." >&2
echo " waiting $INTERVAL seconds" >&2
sleep $INTERVAL
done
from csv import writer
from pprint import pformat
import glob
paths = [glob.glob('%s/*.txt' % p) for p in glob.glob('*')
if p.startswith('brss') and not p.endswith('zip')]
raw_reports = []
for ip_dir in paths:
for f in ip_dir:
ip = ip_dir[0].split('/')[0][11:]
for r in open(f).read().split('****'):
edge_host = f.split('/')[1].split('_')[0]
r = r.strip()
if r:
raw_reports.append((ip, edge_host, r))
final_report = []
get_header = lambda name, headers: [v for h, v in headers if h.lower() == name]
stats = []
cache_hits = []
for ip, edge_host, raw_report in raw_reports:
lines = raw_report.split('\n')
test_number_per_ip = lines[0]
timestamp, url = lines[1].split(' ')
http_status = lines[3]
headers = [map(lambda x: x.strip(), h.split(': ', 1))
for h in [h.replace('\r', '\n') for h in lines[4:-2]]]
formatted_headers = pformat(headers)
cache_code, _, cache_ip = get_header('x-cache', headers)[0].split(' ', 2) # only the first one
cache_ip = cache_ip.split(' ')[0]
#print cache_code, cache_ip
parent_map = [h.split(' ')[1].split('=')[1]
for h in get_header('x-akamai-session-info', headers)
if h.startswith('name=PARENT_MAP')][0]
performance = lines[-1].split(' ')
downloaded_bytes = '%i' % (int(performance[1]) / 1024)
time_taken = '%0.3f' % float(performance[4])
throughput = '%0.f' % (float(performance[7]) / 1024)
csv_file_name = 'clarotests.csv'
cache_hits.append(cache_code)
stats.append([
timestamp,
ip,
edge_host,
test_number_per_ip,
downloaded_bytes,
time_taken,
throughput,
cache_code,
cache_ip,
parent_map
])
with open(csv_file_name, 'wb') as csv_file:
w = writer(csv_file)
w.writerows(stats)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment