This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
/
heroku-redistogo-faina.sh
executable file
·62 lines (55 loc) · 1.74 KB
/
heroku-redistogo-faina.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
# Monitor a RedisToGo instance on Heroku with redis-faina
#
# Usage: heroku-redistogo-faina.sh -n <LINES OF MONITORING> -a <HEROKU APPLICAION>
# Author: @ssaunier
# Default values: 1000 line of monitoring, and heroku app of current folder.
LINES=1000
APP=""
# Parse -a and -n options
while getopts "a:n:" opt; do
case $opt in
n)
LINES=$OPTARG
;;
a)
APP=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# Try to figure out if we are in an heroku application folder
INFO=""
if [ -z $APP ]; then
INFO=`heroku info 2>&1`
if [ $? -ne 0 ]; then
echo 'Please provide an heroku app with the -a option';
exit 1;
else
tokens=(`echo "$INFO" | awk '{print $2}'`)
APP=${tokens[0]}
fi
fi
# Retrieve info about the heroku app
if [ -z "$INFO" ]; then
INFO=`heroku info --app $APP 2>&1`
fi
if [ "$INFO" == "${INFO/redistogo/}" ]; then
echo "The heroku app \033[0;31m$APP\033[0;0m does not seem to have a Redis To Go addon enabled.";
echo "Here are the addons installed for this application:"
heroku addons --app $APP
exit 1;
fi
# Parse Redis To Go url
REDISTOGO_URL=`heroku config --app $APP | grep REDISTOGO_URL`
PASSWORD_HOST_PORT_RAW=`echo $REDISTOGO_URL | cut -d " " -f 2 | sed -e "s/redis:\/\/redistogo://"`
tokens=(`echo "$PASSWORD_HOST_PORT_RAW" | awk -F'@|:|/' '{print $1 " " $2 " " $3 }'`)
PASSWORD=${tokens[0]}
HOST=${tokens[1]}
PORT=${tokens[2]}
# Actually launch redis-faina command
echo "Parsing \033[0;32m$LINES\033[0;0m lines of redis MONITOR on \033[0;32m$HOST:$PORT\033[0;0m for heroku app \033[0;32m$APP\033[0;0m.\n"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
redis-cli -a $PASSWORD -h $HOST -p $PORT MONITOR | head -n $LINES | $DIR/redis-faina.py