Advertisement
MonteVonB

Untitled

Aug 1st, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.70 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################
  3. # Program:      checkThreadpool.sh
  4. # Date Created: 20 July 2012
  5. # Date Updated: 1 Aug 2012
  6. #               |_updated alert logic to combined value of 10K
  7. #               |_Updated getValue function to work with both 2.7.0.5 && 2.8.0.4
  8. #               |_Added log class to logging function, could probably be prettier though
  9. # Developer:    @MonteVonB (Support Engineer)
  10. # Description:  Checks the manager threadpool (private and public).
  11. #               |_If either rises above 1000 for 5 consecutive passes, an alert is triggered
  12. ######################################################
  13.  
  14. #Variable definitions
  15.  
  16. #Array which contains managers to check. Format is (last octet of VIP|Short description of manager)
  17. managerInfo=("6|Man1" "11|Man2" "21|Man3")
  18. #Directory to place logs
  19. logDir="/opt/Redacted/utils/alertScripts/alertLogs"
  20. #name for logs
  21. logName="thread.pool.log"
  22. #Threshold for triggering
  23. threshSize=10000
  24.  
  25. #Simple logging function. TODO: make this better
  26. #First argument is text to print to log (must be wrapped in quotes"
  27. #Second argument used to name log file
  28. #Third argument is for log class (info,warning,error)
  29. logGener ()
  30.   {
  31.     printf "$(date "+%m/%d/%y %H:%M.%S")\t$3\t$1\n" >> ${logDir}/${2}.${logName}
  32.   }
  33.  
  34. #Function that uses curl to grab values from manager API
  35. getValues ()
  36.   {
  37.     curl --silent "http://10.265.19.${1}:5929/command/monitor_service?id=THREAD_POOL"|grep -A3 "<pool_name>A_COMP</pool_name>"|awk -F"[><]" '/queue/{print $2,$3 }'
  38.   }
  39.  
  40.  
  41. #Function that contains the main processing
  42. #Loops through all defined managers in the managerInfo variable
  43. #If either threadpool exceeds defined threshSize, iterate up dot file
  44. #If neither threadpool exceeds defined threshSize, clear out dot file
  45. #If dot file value equals 5, trigger alert, and clear dot file
  46. #Alert that is generated is specific to system which caused it, and contains relevant log lines
  47. #TODO: seperate alert triggering into separate function
  48. doWork ()
  49.   {
  50.     for manInfo in "${managerInfo[@]}";do
  51.       rawData=($(getValues ${manInfo%%|*}))
  52.       publicQueuesize="${rawData[1]}"
  53.       privateQueuesize="${rawData[3]}"
  54.         logGener "Public Queue Size is ${publicQueuesize}" "${manInfo##*|}" "Info"
  55.         logGener "Private Queue Size is ${privateQueuesize}" "${manInfo##*|}" "Info"
  56.           if (( "$((${privateQueuesize} +  ${publicQueuesize}))" > "${threshSize}" ));then
  57.             if [[ ! -s "${logDir}/.${manInfo##*|}" ]];then
  58.                 logGener "Combined Threadpool size has exceeded ${threshSize}" "${manInfo##*|}" "Warning"
  59.                 echo "1" > "${logDir}/.${manInfo##*|}"
  60.             else
  61.                 let numCount=$(cat "${logDir}/.${manInfo##*|}")+1
  62.                   if (( ${numCount} >= 5 ));then
  63.                     printf "The threadpool in ${manInfo##*|} has exceeded ${threshSize} 5 times in the last 5 minutes.\n\n$(tail -15 ${logDir}/${manInfo##*|}.${logName})\n"|ssh redacted@172.265.129.36 "mail -s \"Threadpool alert in ${manInfo##*|}\" example@redacted.com"
  64.                     > "${logDir}/.${manInfo##*|}"
  65.                     logGener "Combined Threadpool size has exceeded ${threshSize} 5 times in 5 minutes. Sending Email alert" "${manInfo##*|}" "Error"
  66.                   else
  67.                     echo ${numCount} > "${logDir}/.${manInfo##*|}"
  68.                     logGener "Combined Threadpool size has exceeded ${threshSize} ${numCount} times." "${manInfo##*|}" "Warning"
  69.                   fi
  70.             fi
  71.           else
  72.             if [[  -s "${logDir}/.${manInfo##*|}" ]];then
  73.                 > "${logDir}/.${manInfo##*|}"
  74.             fi
  75.           fi
  76.     done
  77.   }
  78.  
  79.  
  80. #Call function to do work
  81. doWork
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement