Created
August 23, 2013 19:13
-
-
Save ehayon/6322926 to your computer and use it in GitHub Desktop.
Monitor the latency to a server (pass IP's in as cli arguments)
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
#!/bin/bash | |
PREV_IFS=$IFS; | |
IFS=$'\n'; | |
HOSTNAME=$(hostname) | |
ERRORS=(); | |
for ip in ${*} | |
do | |
LATENCY=$(ping -c 1 $ip | grep -oEi "time=([0-9.]*)" |awk -F'=' '{print $2}') | |
COMPARISON=$(echo "$LATENCY > 125" | bc) | |
if [ $COMPARISON -eq 1 ]; then | |
ERRORS+=("\tServer $ip is experiencing high latency from $HOSTNAME ($LATENCY ms)"); | |
fi | |
done | |
if ! [ -z "$ERRORS" ]; then | |
echo -e "High Latency Warning:\n\n${ERRORS[*]}" | | |
mail -s "[$HOSTNAME] High Latency Warning" [email-address] | |
fi | |
IFS=$PREV_IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment