轻量级监控平台之线程监控脚本
#!/bin/bash
#进程监控脚本
#功能需求: 上报机器Java进程的进程ID,线程数--线程状态分布
. /etc/profile
. ~/.bash_profile
pushurl="https://lightmonitorapi.test.cn/push/thread"
proNum=$(jps | grep -v Jps | cut -d' ' -f1)
cd /opt/web/
webDir=$( ls )
msg=""
for pid in $proNum
do
pro=$(ps -ef | grep "$pid" | grep -v grep)
threadPro=$( jstack -l "$pid" | grep "java.lang.Thread.State" | awk '{print $2 $3 $4 $5}' | sort | uniq -c)
threadNum=$(ps -T -p "$pid" | wc -l)
gcInfo=$(jstat -gcutil "$pid")
msg=$msg"$pid-$threadNum-$threadPro
"
done
ip=$(ip addr | grep 'BROADCAST' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/')
ticket=$(cat /opt/shell/ticket.txt)
curl $pushurl
-H "Accept: application/json"
-H 'Content-Type: application/json'
-d '{"ip": "'"${ip}"'", "ticket": "'"${ticket}"'", "data": "'"${msg}"'"}'
架构设计@工程设计@服务稳定性之路