Skip to content

Instantly share code, notes, and snippets.

@dstokes
Last active December 19, 2019 03:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstokes/dd85e11b9676f6b9ab65 to your computer and use it in GitHub Desktop.
Save dstokes/dd85e11b9676f6b9ab65 to your computer and use it in GitHub Desktop.
StatsD Redis Monitor in 10LOC
#!/bin/bash
#
# Report redis usage data to statsd
# Metric Format: <env>.<hostname>.<redis>.<metric>
#
# Add to crontab for periodic monitoring
#
STATSD_HOST=<host>
STATSD_PORT=8125
ENV=${ENV:-dev}
HOST=$(hostname -s)
COMMAND='
/(uptime_in_days|connected_clients|used_memory):/ {
printf "%s.%s.redis.%s:%d|g\n", ENV, HOST, $1, $2
}
'
for STAT in $(redis-cli INFO | awk -F ':' -v HOST=$HOST -v ENV=$ENV "$COMMAND"); do
echo "$STAT" | nc -u -w0 "$STATSD_HOST" $STATSD_PORT;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment