Created
May 18, 2015 17:53
-
-
Save miguelcnf/6290522dbc5f447caad1 to your computer and use it in GitHub Desktop.
Measure packet loss between hosts and push it as a gauge to statsd every 5 seconds.
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
#!/usr/bin/env bash | |
DST_IP=XXX.XXX.XXX.XXX | |
SRC_IP=$(/sbin/ip -f inet addr | grep inet | grep -v 127.0.0.1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}') | |
PACKET_LOSS=$(/bin/ping -w 4 -q $DST_IP | tail -2 | awk -F ' ' '{print $6}' | awk -F '%' '{print $1}' | grep -v '^$') | |
SANITIZED_DST_IP="${DST_IP//./_}" | |
SANITIZED_SRC_IP="${SRC_IP//./_}" | |
METRIC_PREFIX="" | |
METRIC_SUFFIX="" | |
STATSD_HOST=127.0.0.1 | |
STATSD_PORT=8125 | |
echo $METRIC_PREFIX"network.packetloss.from.$SANITIZED_SRC_IP.to.$SANITIZED_DST_IP"$METRIC_SUFFIX":$PACKET_LOSS|g" | nc -w 1 -u $STATSD_HOST $STATSD_PORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment