Commit 3d0aa346 authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Updated bash script with comments.

Updated the graph output to be a little cleaner.
parent fdf1bf08
......@@ -2,30 +2,32 @@
bandwidth_checker(){
# Run the speedtest and output it to lastresult.txt
(./speedtest-cli --secure) > ./lastresult.txt
# Use awk to read the Download and Upload values and store them in Bash variables
download_info=$(cat ./lastresult.txt | grep 'Download' | awk '{print $2}')
upload_info=$(cat ./lastresult.txt | grep 'Upload' | awk '{print $2}')
}
# Call the speed test function
bandwidth_checker
# Update the RRD database with the values from lastresult.txt
rrdtool update speedtest.rrd --template download:upload N:"$download_info:$upload_info"
# Graph for last 24 hours
rrdtool graph speed_graph_24.png \
-w 785 -h 120 -a PNG \
-w 750 -h 120 -a PNG \
--slope-mode \
--start -86400 --end now \
--font DEFAULT:7: \
--title "Internet Speed (24 Hours)" \
--watermark "`date`" \
--vertical-label "Speed (Mbps)" \
--right-axis-label "Speed (MBps)" \
--lower-limit 0 \
--right-axis 1:0 \
--x-grid MINUTE:10:HOUR:1:MINUTE:120:0:%R \
--alt-y-grid --rigid \
DEF:download=speedtest.rrd:download:MAX \
......@@ -34,26 +36,24 @@ LINE1:download#0000FF:"Download" \
GPRINT:download:LAST:"Cur\: %5.2lf" \
GPRINT:download:AVERAGE:"Avg\: %5.2lf" \
GPRINT:download:MAX:"Max\: %5.2lf" \
GPRINT:download:MIN:"Min\: %5.2lf\t\t\t" \
GPRINT:download:MIN:"Min\: %5.2lf\n" \
LINE2:upload#FF0000:"Upload" \
GPRINT:upload:LAST:"Cur\: %5.2lf" \
GPRINT:upload:AVERAGE:"Avg\: %5.2lf" \
GPRINT:upload:MAX:"Max\: %5.2lf" \
GPRINT:upload:MIN:"Min\: %5.2lf"
GPRINT:upload:MIN:"Min\: %5.2lf\n" > /dev/null
# Graph for last 72 Hours
rrdtool graph speed_graph_72.png \
-w 785 -h 120 -a PNG \
-w 750 -h 120 -a PNG \
--slope-mode \
--start -259200 --end now \
--font DEFAULT:7: \
--title "Internet Speed (72 Hours)" \
--watermark "`date`" \
--vertical-label "Speed (Mbps)" \
--right-axis-label "Speed (MBps)" \
--lower-limit 0 \
--right-axis 1:0 \
--x-grid MINUTE:10:HOUR:1:MINUTE:120:0:%R \
--x-grid MINUTE:30:HOUR:2:MINUTE:240:0:%R \
--alt-y-grid --rigid \
DEF:download=speedtest.rrd:download:MAX \
DEF:upload=speedtest.rrd:upload:MAX \
......@@ -61,13 +61,13 @@ LINE1:download#0000FF:"Download" \
GPRINT:download:LAST:"Cur\: %5.2lf" \
GPRINT:download:AVERAGE:"Avg\: %5.2lf" \
GPRINT:download:MAX:"Max\: %5.2lf" \
GPRINT:download:MIN:"Min\: %5.2lf\t\t\t" \
GPRINT:download:MIN:"Min\: %5.2lf\n" \
LINE2:upload#FF0000:"Upload" \
GPRINT:upload:LAST:"Cur\: %5.2lf" \
GPRINT:upload:AVERAGE:"Avg\: %5.2lf" \
GPRINT:upload:MAX:"Max\: %5.2lf" \
GPRINT:upload:MIN:"Min\: %5.2lf"
GPRINT:upload:MIN:"Min\: %5.2lf\n" > /dev/null
## copy to the web directory
cp speed_graph_24.png /var/www/
cp speed_graph_72.png /var/www/
\ No newline at end of file
## Copy to the web directory
cp speed_graph_24.png /your-web-folder/
cp speed_graph_72.png /your-web-folder/
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment