Last active
December 19, 2019 03:25
-
-
Save dstokes/dd85e11b9676f6b9ab65 to your computer and use it in GitHub Desktop.
StatsD Redis Monitor in 10LOC
This file contains 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
#!/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