致梦想

压测相关数据收集

collectPressInfo.sh

#! /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.sh

#!/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.sh

#!/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 &

  

posted on 2019-11-02 10:13  致梦想  阅读(222)  评论(0编辑  收藏  举报

导航