輕量級監控平臺之慢日誌監控

輕量級監控平臺之慢日誌監控腳本web

#!/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}"'"}'

架構設計@工程設計@服務穩定性之路shell

相關文章
相關標籤/搜索