Created
November 4, 2016 16:53
-
-
Save jozic/b772c35d739e6fbd21c219fdabf0823b to your computer and use it in GitHub Desktop.
docker-netcat-statsd: send docker stats to statsd
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
STATSD_HOST="${STATSD_HOST:-localhost}" | |
STATSD_PORT="${STATSD_PORT:-8125}" | |
STATSD_PREFIX="${STATSD_PREFIX:-"docker"}" | |
INTERVAL="${STATS_COLLECT_INTERVAL:-2}" | |
while sleep "$INTERVAL"; do | |
docker stats --no-stream $(docker ps | awk '{if(NR>1) print $NF}') | tail -n+2 | while read line; | |
do | |
echo "line: " $line; | |
echo $line | awk '{printf("'${STATSD_PREFIX}'.%s.cpu:%.2f|c", $1, substr($2, 1, length($2)-1))}' | xargs echo | nc -v -u -w 0 $STATSD_HOST $STATSD_PORT; | |
echo $line | awk '{printf("'${STATSD_PREFIX}'.%s.memory:%.2f|c", $1, substr($6, 1, length($6)-1))}' | xargs echo | nc -v -u -w 0 $STATSD_HOST $STATSD_PORT; | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment