-
-
Save bitbonsai/4862fa4c141b6195343d7c8646315881 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# hapee_tracing.sh | |
KILL_FILE="/tmp/kill_hapee_tracing" | |
BASE_DIR="/var/log/pidstats/" | |
SOCKET_DIR="/run/lb_engine/" | |
PROCESS_NUMBER="$1" | |
PIDS=( $(cat /run/hapee-lb.pid) ) | |
PID_INDEX=$(($PROCESS_NUMBER-1)) | |
PID=${PIDS[${PID_INDEX}]} | |
mkdir -p "${BASE_DIR}" | |
while true ; do | |
if [ -f "${KILL_FILE}" ] ; then | |
exit 0 | |
fi | |
timeout 60 pidstat -u -p "${PID}" 1 | stdbuf -i0 -o0 -e0 egrep 'hapee-lb' | stdbuf -i0 -o0 -e0 awk '{print $6}' | while read line | |
do | |
if [ -f "${KILL_FILE}" ] ; then | |
exit 0 | |
fi | |
system_cpu=$(echo "${line}" | awk -F. '{print $1}') | |
if [ "${system_cpu}" -gt 30 ] ; then | |
echo 'show sess all' | socat ${SOCKET_DIR}process-${PROCESS_NUMBER}.sock stdio > ${BASE_DIR}sessions_$(date +%F:%H:%M:%S)_${PROCESS_NUMBER}_${PID} & | |
timeout 5 strace -ttvs200 -p "${PID}" -o ${BASE_DIR}strace_$(date +%F:%H:%M:%S)_${PROCESS_NUMBER}_${PID} | |
fi | |
done | |
PIDS=( $(cat /run/hapee-lb.pid) ) | |
PID=${PIDS[${PID_INDEX}]} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment