轻量级监控平台之java进程GC监控脚本
#!/bin/bash
#进程监控脚本
#功能需求: 上报机器Java进程的GC情况数据
. /etc/profile
. ~/.bash_profile
pushurl="https://lightmonitorapi.test.cn/push/gcinfo"
proNum=$(jps | grep -v Jps | cut -d' ' -f1)
i=1
cd /opt/web/
webDir=$( ls )
msg=""
for pid in $proNum
do
gcinfo=$(jstat -gcutil $pid | tail -n1 | awk '{print $1"(S0)-" $2"(S1)-" $3"(E)-" $4"(O)-" $5"(M)-" $6"(CCS)-" $7"(YGC)-" $8"(YGCT)-" $9"(FGC)-" $10"(FGCT)-" $11"(GCT)"}')
msg=$msg$pid"-"$gcinfo"\n"
done
ticket=$(cat /opt/shell/ticket.txt)
ip=$(ip addr | grep 'BROADCAST' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/')
curl $pushurl \
-H "Accept: application/json" \
-H 'Content-Type: application/json' \
-d \ '{"ip": "'"${ip}"'", "ticket": "'"${ticket}"'", "data": "'"${msg}"'"}'
架构设计@工程设计@服务稳定性之路