轻量级监控平台之慢日志监控脚本
#!/bin/bash
#进程监控脚本
#功能需求: 上报机器内rcp,web服务的慢接口数据
. /etc/profile
. ~/.bash_profile
pushurl="https://lightmonitorapi.test.cn/push/serviceslow"
proNum=$(jps | grep -v Jps | cut -d' ' -f1)
cd /opt/web/
webDir=$( ls )
msg=""
for pid in $proNum
do
serviceName=$(serivce list | grep "$pid" | cut -d' ' -f1)
if [ -n "$serviceName" ];then
logdir=$(find "/opt/serivce/log/"$serviceName -name "serivce_trace.log" -mmin -360)
if [ -n "$logdir" ];then
ctime=$(date " %m-%d %H:%M")
slowinfo=$( grep "$ctime" "$logdir" | grep ExecuteTimeFilter | grep -E ",time:[2-9]{2,}|,time:[0-9]{4,}" | awk -F',' '{print $1","$4","$5}')
msg=$msg$pid"-"$serviceName"-"$slowinfo"||"
fi
else
for fileName in $webDir
do
fileDir=$(ps -ef | grep -v grep | grep "$pid" | grep "$fileName" )
if [ -n "$fileDir" ];then
logdir=$(find "/opt/web/"$fileName"/logs/" -name "test.com_access.log.*" -mmin -360)
if [ -n "$logdir" ];then
ctime=$(date " %m-%d %H:%M")
slowinfo=$(grep "$ctime" "$logdir" | awk -F' ' '{print $6",time="$7 }' | grep -E ",time=[0-9].[2-9]{2,}")
msg=$msg$pid"-"$fileName"-"$slowinfo"||"
fi
fi
done
fi
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}"'"}'
架构设计@工程设计@服务稳定性之路