Skip to content

Instantly share code, notes, and snippets.

@miguelcnf
Created May 18, 2015 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelcnf/6290522dbc5f447caad1 to your computer and use it in GitHub Desktop.
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.
#!/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