Przeglądaj źródła

HUE-2731 [core] Hue collect data script didn't validate that Hue was running before trying to collect

Chris Conner 10 lat temu
rodzic
commit
fc52eac
1 zmienionych plików z 21 dodań i 17 usunięć
  1. 21 17
      tools/troubleshooting/hue_collect_data.sh

+ 21 - 17
tools/troubleshooting/hue_collect_data.sh

@@ -16,8 +16,8 @@
 # limitations under the License.
 # limitations under the License.
 
 
 #NOTE: This script requires curl, strace and lsof to be installed. It
 #NOTE: This script requires curl, strace and lsof to be installed. It
-# must be run on the Hue server. Set HUE_USER to a user in Hue with
-# Superuser access to get thread dumps.  Set HUE_PASSWORD to HUE_USER's
+# must be run on the Hue server. Set HUE_USER to a user in Hue with 
+# Superuser access to get thread dumps.  Set HUE_PASSWORD to HUE_USER's 
 # password.
 # password.
 
 
 # Location for output files
 # Location for output files
@@ -88,17 +88,14 @@ COOKIE_JAR=${OUTPUT_DIR}/${USER}_cookie.jar
 echo "Making ${OUTPUT_DIR} if it does not exist"
 echo "Making ${OUTPUT_DIR} if it does not exist"
 mkdir -p ${OUTPUT_DIR}
 mkdir -p ${OUTPUT_DIR}
 
 
+do_ps
+
 hue_login
 hue_login
 echo "Gathering info:"
 echo "Gathering info:"
 for (( x=1; x<=${RUNS}; x++ ))
 for (( x=1; x<=${RUNS}; x++ ))
 do
 do
    DATE=$(date '+%Y%m%d-%H%M%S')
    DATE=$(date '+%Y%m%d-%H%M%S')
    echo "DATE: ${DATE}"
    echo "DATE: ${DATE}"
-   echo "Getting a thread dump:"
-   do_curl \
-	GET \
-	"${HUE_THREADS_URL}" \
-	-L -o ${HUE_THREADS_FILE}_${DATE}
 
 
    echo "Getting CPU and Memory usage"
    echo "Getting CPU and Memory usage"
    do_ps
    do_ps
@@ -112,16 +109,23 @@ do
         ${PID} \
         ${PID} \
         ${STRACE_WAIT} \
         ${STRACE_WAIT} \
         -o ${HUE_STRACE_FILE}_${DATE} -T -t
         -o ${HUE_STRACE_FILE}_${DATE} -T -t
+
    echo "Getting open connections"
    echo "Getting open connections"
    do_lsof \
    do_lsof \
         ${PID} \
         ${PID} \
         ${HUE_LSOF_FILE}_${DATE}
         ${HUE_LSOF_FILE}_${DATE}
 
 
+   echo "Getting a thread dump:"
+   do_curl \
+	GET \
+	"${HUE_THREADS_URL}" \
+	-L -o ${HUE_THREADS_FILE}_${DATE}
+
    sleep ${RUN_WAIT}
    sleep ${RUN_WAIT}
 done
 done
 
 
 mkdir ${OUTPUT_DIR}/logs
 mkdir ${OUTPUT_DIR}/logs
-cp -pr ${HUE_LOG_DIR}/* ${OUTPUT_DIR}/logs
+cp -pr ${HUE_LOG_DIR}/* ${OUTPUT_DIR}/logs 
 
 
 echo "Collecting done, please zip ${OUTPUT_DIR} and upload to the ticket"
 echo "Collecting done, please zip ${OUTPUT_DIR} and upload to the ticket"
 }
 }
@@ -184,19 +188,12 @@ function do_strace()
    shift
    shift
    ARGS=$@
    ARGS=$@
 
 
-   if [ -z ${LOG_FILE} ]
-   then
-      LOG_FILE=/tmp/lsof.log
-   fi
-
    STRACE=$(which strace)
    STRACE=$(which strace)
    if [ ! -f ${STRACE} ]
    if [ ! -f ${STRACE} ]
    then
    then
       echo "strace not found, unable to collect strace info"
       echo "strace not found, unable to collect strace info"
    else
    else
-      ${STRACE} -o ${LOG_FILE} -p ${SPID} ${ARGS} &
-      sleep ${WAIT}
-      kill $!
+      timeout ${WAIT}s ${STRACE} -p ${SPID} ${ARGS} &
    fi
    fi
 }
 }
 
 
@@ -226,10 +223,17 @@ function do_ps()
 {
 {
    PS_COMMAND=$(ps aux | grep [r]uncherrypyserver | awk '{print $6" "$2" "$3" "$12}')
    PS_COMMAND=$(ps aux | grep [r]uncherrypyserver | awk '{print $6" "$2" "$3" "$12}')
    MEM=$(echo ${PS_COMMAND} | awk '{print $1}')
    MEM=$(echo ${PS_COMMAND} | awk '{print $1}')
-   MEM_MB=$(expr ${MEM} / 1024)
    PID=$(echo ${PS_COMMAND} | awk '{print $2}')
    PID=$(echo ${PS_COMMAND} | awk '{print $2}')
    CPU=$(echo ${PS_COMMAND} | awk '{print $3}')
    CPU=$(echo ${PS_COMMAND} | awk '{print $3}')
    PROC=$(echo ${PS_COMMAND} | awk '{print $4}')
    PROC=$(echo ${PS_COMMAND} | awk '{print $4}')
+
+   if [[ ! ${PID} == ?(-)+([0-9]) ]]
+   then
+     echo "Unable to get PID from Process, either Hue is not running on this host or Hue is not using CherryPy server"
+     exit 1
+   fi
+
+   MEM_MB=$(expr ${MEM} / 1024)
 }
 }
 
 
 function get_cm_process_dir()
 function get_cm_process_dir()