• 轻量级监控平台之慢日志监控


    轻量级监控平台之慢日志监控脚本

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

    架构设计@工程设计@服务稳定性之路

  • 相关阅读:
    二进制流 最后一段数据是最后一次读取的byte数组没填满造成的
    java中的匿名内部类总结
    决策树构建算法之—C4.5
    Segment公司--整合数据进行分析
    UBuntu安裝使用PIP
    undefined reference to “boost” in Qt—Ubuntu
    Ubuntu14.04引导菜单修复
    ubuntu16.04下编译安装OpenCV
    PCL:Ubuntu下安装配置PCL
    Ubuntu安装配置Python.pyDev
  • 原文地址:https://www.cnblogs.com/coderManFans/p/11911519.html
Copyright © 2020-2023  润新知