Skip to content

Instantly share code, notes, and snippets.

@russelldavies
Last active October 13, 2016 16:28
Show Gist options
  • Save russelldavies/708046adf65ca3b9d89f7b724e4afff7 to your computer and use it in GitHub Desktop.
Save russelldavies/708046adf65ca3b9d89f7b724e4afff7 to your computer and use it in GitHub Desktop.
Connection Health
set terminal png enhanced size 1200,675 linewidth 2
set output 'dsl_stats.png'
set title 'DSL Stats'
set autoscale fix
set grid
set datafile separator ','
set key autotitle columnhead
set xlabel 'Timestamp (UTC)'
set xdata time
set x2data time
set timefmt '%Y-%m-%dT%H:%M:%SZ'
set format x "%d/%m %H:%M"
set ylabel 'Kbit/s'
set y2label 'dB'
set y2tics 5
set style line 1 linecolor rgb '#c2a5cf' linetype 1 linewidth 2
set style line 2 linecolor rgb '#7b3294' linetype 1 linewidth 2
set style line 3 linecolor rgb '#008837' linetype 1 linewidth 1
set style line 4 linecolor rgb '#a6dba0' linetype 1 linewidth 1
plot 'dsl_stats.csv' using 1:5 smooth csplines title 'Tx Rate (kbps)' ls 1, \
'' using 1:6 smooth csplines title 'Rx Rate (kbps)' ls 2, \
'' using 1:($7 / 10.0) smooth csplines title 'Tx Noise Margin (dB)' ls 3 axes x2y2, \
'' using 1:($8 / 10.0) smooth csplines title 'Rx Noise Margin (dB)' ls 4 axes x2y2, \
#'' using 1:12 smooth csplines title 'Tx Attenuation (dB)', \
#'' using 1:13 smooth csplines title 'Rx Attenuation (dB)', \
#'' using 1:14 smooth csplines title 'Tx Power (dBm)', \
#'' using 1:15 smooth csplines title 'Rx Power (dBm)', \
#'' using 1:17 smooth csplines title 'Rx CRC' , \
#'' using 1:18 smooth csplines title 'Tx CRC' , \
#'' using 1:19 smooth csplines title 'Rx FEC' , \
#'' using 1:20 smooth csplines title 'Tx FEC' , \
#!/bin/sh
# This is to get stats for the Orange HG532s ADSL gateway router.
filename="dsl_stats.csv"
header="timestamp,domain,Modulation,status,UpCurrRate,DownCurrRate,UpMargin,DownMargin,UpDepth,DownDepth,Encoding,UpAttenuation,DownAttenuation,UpPower,DownPower,DataPath,dnCrc,upCrc,dnFec,upFec"
# Write header if doesn't exist
touch $filename
[[ ! -s $filename ]] && echo $header > $filename
[[ ! $(head -n1 $filename | grep $header) ]] && sed -i "1i$header" $filename
login () {
curl 'http://192.168.0.1/index/login.cgi' -H 'Cookie: Language=sp' --data Username=admin --data Password='OGM2OTc2ZTViNTQxMDQxNWJkZTkwOGJkNGRlZTE1ZGZiMTY3YTljODczZmM0YmI4YTgxZjZmMmFiNDQ4YTkxOA==' -s --cookie-jar cookie.jar > /dev/null
}
login
while :; do
stats=$(curl http://192.168.0.1/html/status/dslinfo.asp -s -b cookie.jar | grep 'var DSLCfg' | awk 'BEGIN { FS = "[()]" } ; { print $3 }' | sed 's/"//g')
if [[ $stats ]]; then
echo $(date -u +"%Y-%m-%dT%H:%M:%SZ"),$stats >> $filename
else
login
fi
sleep 60
done
#!/bin/sh
while :; do
echo $(date -u +"%Y-%m-%dT%H:%M:%SZ") $(ping -w 1 8.8.8.8 | tail -n1 | grep -oE '[0-9]+\.[0-9]+ ms') >> ping_times.dat
done
#!/usr/bin/env python
from functools import partial
from datetime import datetime
import sys
to_datetime = partial(lambda format, date_string:
datetime.strptime(date_string, format), '%Y-%m-%dT%H:%M:%SZ')
def outage_times(timestamps, margin=5, threshold=60):
"""margin is the number of seconds that can occur between clusters,
threshold is how many timestamps need to have occured for it to be
counted as an outage.
"""
times = []
for i, current in enumerate(timestamps):
if i == 0:
start = current
end = None
continue
previous = timestamps[i - 1]
if (current - previous).seconds > margin:
if (previous - start).seconds >= threshold:
times += [(start, previous)]
start = current
if i == len(timestamps) - 1:
if (current - start).seconds >= threshold:
times += [(start, current)]
return times
def plot_outage_times(filename, timestamps):
with open(filename, 'w') as f:
for group in timestamps:
for timestamp in group:
f.write(timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') + ' 0 ms\n')
f.write('\n')
if __name__ == '__main__':
file_in = sys.argv[1]
file_out = sys.argv[2]
with open(file_in) as f:
timestamps = [to_datetime(line.strip().split(' ')[0]) for line in f if
'ms' not in line]
timestamps = outage_times(timestamps)
plot_outage_times(file_out, timestamps)
set terminal png size 1200,675
set output "ping_times.png"
# Line width of the axes
set border linewidth 1.5
# Line styles
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2
set title 'Ping Times'
set key off
set autoscale fix
set xlabel 'Timestamp'
set ylabel 'Ping Time (ms)'
set grid
set xdata time
set timefmt '%Y-%m-%dT%H:%M:%SZ'
set format x "%d/%m %H:%M"
set yrange [-10:]
#set xrange [:]
plot 'ping_times.dat' using 1:($2 > 0 ? $2 : 1/0) every 300 smooth bezier with lines ls 1, \
'outages.dat' using 1:($2) with linespoints ls 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment