Skip to content

Instantly share code, notes, and snippets.

@ehayon
Created August 23, 2013 19:13
Show Gist options
  • Save ehayon/6322926 to your computer and use it in GitHub Desktop.
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)
#!/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