Guest User

Untitled

a guest
Oct 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #!/bin/sh
  2. # Monitor a RedisToGo instance on Heroku with redis-faina
  3. #
  4. # Usage: heroku-redistogo-faina.sh -n <LINES OF MONITORING> -a <HEROKU APPLICAION>
  5. # Author: @ssaunier
  6.  
  7. # Default values: 1000 line of monitoring, and heroku app of current folder.
  8. LINES=1000
  9. APP=""
  10.  
  11. # Parse -a and -n options
  12. while getopts "a:n:" opt; do
  13. case $opt in
  14. n)
  15. LINES=$OPTARG
  16. ;;
  17. a)
  18. APP=$OPTARG
  19. ;;
  20. \?)
  21. echo "Invalid option: -$OPTARG" >&2
  22. ;;
  23. esac
  24. done
  25.  
  26. # Try to figure out if we are in an heroku application folder
  27. INFO=""
  28. if [ -z $APP ]; then
  29. INFO=`heroku info 2>&1`
  30. if [ $? -ne 0 ]; then
  31. echo 'Please provide an heroku app with the -a option';
  32. exit 1;
  33. else
  34. tokens=(`echo "$INFO" | awk '{print $2}'`)
  35. APP=${tokens[0]}
  36. fi
  37. fi
  38.  
  39. # Retrieve info about the heroku app
  40. if [ -z "$INFO" ]; then
  41. INFO=`heroku info --app $APP 2>&1`
  42. fi
  43.  
  44. if [ "$INFO" == "${INFO/Redis To Go/}" ]; then
  45. echo "The heroku app \033[0;31m$APP\033[0;0m does not seem to have a Redis To Go addon enabled.";
  46. echo "Here are the addons installed for this application:"
  47. heroku addons --app $APP
  48. exit 1;
  49. fi
  50.  
  51. # Parse Redis To Go url
  52. REDISTOGO_URL=`heroku config --app $APP | grep REDISTOGO_URL`
  53. PASSWORD_HOST_PORT_RAW=`echo $REDISTOGO_URL | cut -d " " -f 3 | sed -e "s/redis:\/\/redistogo://"`
  54. tokens=(`echo "$PASSWORD_HOST_PORT_RAW" | awk -F'@|:|/' '{print $1 " " $2 " " $3 }'`)
  55. PASSWORD=${tokens[0]}
  56. HOST=${tokens[1]}
  57. PORT=${tokens[2]}
  58.  
  59. # Actually launch redis-faina command
  60. 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"
  61. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  62. redis-cli -a $PASSWORD -h $HOST -p $PORT MONITOR | head -n $LINES | $DIR/redis-faina.py
Add Comment
Please, Sign In to add comment