壓測相關數據收集

collectPressInfo.shjava

#! /bin/bash
# 間隔時間
SLEEP_TIME=30
export JAVA_HOME=/app/nearby-server/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH


project=nearby-server
PID=$(ps -ef | grep $project | grep -v grep |grep java| awk '{print $2}')

PROCESS_NAME=$(ps -ef | grep ${PID} | grep -v ${FILTER} | awk '{print $8}' | awk -F '[/]' '{print $NF}')
LOG="${PROCESS_NAME}_${PID}_stress_monitoring_record.log"

thread_num=0
vmem=0
mem=0
cpu_info=""
while true
do
    # 判斷被監控的進程是否啓動
    PRO_NOW=`ps aux | grep $PID | wc -l`
    if [ $PRO_NOW -eq 0 ]
    then 
        echo "`date +"%Y-%m-%d %H:%M:%S"`, $PID is not running!!!!!!!!!!!!!" >> ./$LOG
    else
        #線程數
        thread_num=$(pstree -p $PID | wc -l)
        #打開文件數
        open_files=$(lsof -p $PID | wc -l)
        #cpu佔用率
        cpu_info=`top -bn 1 -p $PID | awk 'NR==8 {print $9}'`
        #虛擬內存使用量
        vmem=`ps aux | grep $PID | grep -v ${FILTER} | awk '{print $5}'`
        #內存使用量
        mem=`ps aux | grep $PID | grep -v ${FILTER} | awk '{print $6}'`
        #輸出到日誌文件
        echo -e "`date +"%Y-%m-%d\t%H:%M:%S"`\t${vmem}\t${mem}\t${cpu_info}\t${open_files}\t${thread_num}" >> ./${LOG}
    fi
    sleep $SLEEP_TIME
done

stopCollect.shbash

#!/bin/bash
export JAVA_HOME=/app/nearby-server/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH

PROCESS_NUM=$(ps -ef | grep collectl | grep -v grep | wc -l)
echo $PROCESS_NUM
PID=$(ps -ef |grep collectl|grep -v grep| awk '{print $2}')
echo $PID
if [ $PROCESS_NUM -eq 1 ]; then
  echo 'kill '${PID}
  kill $PID
else
  echo 'no process to kill'
fi

cd /app/nearby-server

mv performance.log  `date +%y%m%d%H%M%S`_performance.txt

getCollect.shapp

#!/bin/bash
export JAVA_HOME=/app/nearby-server/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH
cd /app/nearby-server
nohup collectl -scmd -oT >performance.log &
相關文章
相關標籤/搜索