sufehmi icon

pingmon.sh

sufehmi | PRO | 02/08/22 12:41:21 PM UTC | 0 ⭐ | 1638 👁️ | Never ⏰ | []
Bash |

1.14 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
# pingmon.sh
#
# will enable you to not just monitor availability of a network target, but also 
# its network (ping) performance
#
# using this guide, I was able to keep a Google Sheet up-to-date automatically: 
# https://academy.datawrapper.de/article/288-how-to-set-up-automatic-updates-on-a-google-sheet
#
# then I use that google sheet as the datasource for a Google Data Studio dashboard, see here:
# https://datastudio.google.com/reporting/95d8823c-2c9c-4a09-beee-4004207025e2
# 
 
target=10.10.22.1
logfile=/root/scripts/pingmon.log
 
today=$(date '+%Y-%m-%d')
currtime=$(date '+%H:%M:%S')
 
msg=`ping -c 1 $target`
 
# if ping successful, then find out the result
#if [[ "$msg" =~ "100% packet loss" ]] ; then
if echo $msg | grep -q "100% packet loss" ; then 
 
    # device is unreachable
    # set speed to zero
    speed=0
    
else
 
    # get the milisecond number
    speed=`echo $msg | grep icmp_seq | cut -d "=" -f 4 | cut -d " " -f 1`
 
fi
 
# write to log in CSV format
echo $today,$currtime,$speed >> $logfile
 
exit
 
# just for debugging
#if echo $msg | grep -q "100% packet loss" ; then echo LOSS ; else echo FINE ; fi
 

Comments