• Linux——统计分析日志文件并发送钉钉消息


    脚本:

    #!/bin/bash
    declare -i totalCount
    totalCount=0
    longCount=0
    apnsCount=0
    successCount=0
    oneCount=0
    twoCount=0
    threeCount=0
    fourCount=0
    fiveCount=0
    eightCount=0
    nineCount=0
    
    totalCount2=0
    longCount2=0
    apnsCount2=0
    successCount2=0
    oneCount2=0
    twoCount2=0
    threeCount2=0
    fourCount2=0
    fiveCount2=0
    eightCount2=0
    nineCount2=0
    
    echo "---------------------------------------------------开始解压删除----------------------------------------------------"
    for file in `ls $1/ftp/192.168.10.78/tomcat_pushc/logs/*.log.*`
    do
      if [ "bz2" = "${file##*.}" ]; then
        tar -xvf $file -C $1/ftp/192.168.10.78/tomcat_pushc/logs/
        rm -rf $file
      fi
    done
    echo "---------------------------------------------------结束解压删除----------------------------------------------------"
    
    for file in `ls $1/ftp/192.168.10.78/tomcat_pushc/logs/*.log.*`
    do
      total=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:" $file|wc -l)
      long=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0000".*长连接推送成功" $file|wc -l)
      apns=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0000".*APNS推送成功" $file|wc -l)
      success=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0000"" $file|wc -l)
      one=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0001"" $file|wc -l)
      two=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0002"" $file|wc -l)
      three=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0003"" $file|wc -l)
      four=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0004"" $file|wc -l)
      five=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0005"" $file|wc -l)
      eight=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0008"" $file|wc -l)
      nine=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0009"" $file|wc -l)
    
      echo "$file total=$total,long=$long,apns=$apns,success=$success,0001=$one,0002=$two,0003=$three,0004=$four,0005=$five,0008=$eight,0009=$nine"
    
      totalCount=$(($totalCount+$total))
      longCount=$(($longCount+$long))
      apnsCount=$(($apnsCount+$apns))
      successCount=$(($successCount+$success))
      oneCount=$(($oneCount+$one))
      twoCount=$(($twoCount+$two))
      threeCount=$(($threeCount+$three))
      fourCount=$(($fourCount+$four))
      five5Count=$(($fiveCount+$five))
      eightCount=$(($eightCount+$eight))
      nineCount=$(($nineCount+$nine))
    done
    echo "$1/78_pushc:totalCount=$totalCount,longCount=$longCount,apnsCount=$apnsCount,successCount=$successCount,0001Count=$oneCount,0002Count=$twoCount,0003Count=$threeCount,0004Count=$fourCount,0005Count=$fiveCount,0008Count=$eightCount,0009Count=$nineCount"
    
    
    echo "---------------------------------------------------这是分割线----------------------------------------------------"
    
    echo "---------------------------------------------------开始解压删除----------------------------------------------------"
    for file in `ls $1/ftp/192.168.10.79/tomcat_pushc/logs/*.log.*`
    do
      if [ "bz2" = "${file##*.}" ]; then
        tar -xvf $file -C $1/ftp/192.168.10.79/tomcat_pushc/logs/
        rm -rf $file
      fi
    done
    echo "---------------------------------------------------结束解压删除----------------------------------------------------"
    
    for file in `ls $1/ftp/192.168.10.79/tomcat_pushc/logs/*.log.*`
    do
      total=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:" $file|wc -l)
      long=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0000".*长连接推送成功" $file|wc -l)
      apns=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0000".*APNS推送成功" $file|wc -l)
      success=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0000"" $file|wc -l)
      one=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0001"" $file|wc -l)
      two=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0002"" $file|wc -l)
      three=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0003"" $file|wc -l)
      four=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0004"" $file|wc -l)
      five=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0005"" $file|wc -l)
      eight=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0008"" $file|wc -l)
      nine=$(grep -r "pushhandler push message:.*"clientType":"1".*,resp:.*"0009"" $file|wc -l)
    
      echo "$file total=$total,long=$long,apns=$apns,success=$success,0001=$one,0002=$two,0003=$three,0004=$four,0005=$five,0008=$eight,0009=$nine"
    
      totalCount2=$(($totalCount2+$total))
      longCount2=$(($longCount2+$long))
      apnsCount2=$(($apnsCount2+$apns))
      successCount2=$(($successCount2+$success))
      oneCount2=$(($oneCount2+$one))
      twoCount2=$(($twoCount2+$two))
      threeCount2=$(($threeCount2+$three))
      fourCount2=$(($fourCount2+$four))
      five5Count2=$(($fiveCount2+$five))
      eightCount2=$(($eightCount2+$eight))
      nineCount2=$(($nineCount2+$nine))
    done
    echo "$1/79_pushc:totalCount=$totalCount2,longCount=$longCount2,apnsCount=$apnsCount2,successCount=$successCount2,0001Count=$oneCount2,0002Count=$twoCount2,0003Count=$threeCount2,0004Count=$fourCount2,0005Count=$fiveCount2,0008Count=$eightCount2,0009Count=$nineCount2"
    
    echo "---------------------------------------------------下面是合计----------------------------------------------------"
    message="【统计时间】:$1 
    【请求总数】:$(($totalCount+$totalCount2)) 
    【成功数-长连接】:$(($longCount+$longCount2)) 
    【成功数-apns】:$(($apnsCount+$apnsCount2)) 
    【成功数-合计】:$(($successCount+$successCount2)) 
    【失败数-推送失败】:$(($oneCount+$oneCount2)) 
    【失败数-超时】:$(($eightCount+$eightCount2)) 
    【失败数-系统异常】:$(($nineCount+$nineCount2)) 
    【失败数-appId非法】:$(($fiveCount+$fiveCount2)) 
    【失败数-服务器太忙】:$(($fourCount+$fourCount2)) 
    【失败数-请求数据不合法】:$(($threeCount+$threeCount2)) 
    【失败数-连接不在当前服务器】:$(($twoCount+$twoCount2)) 
    【失败数-合计】:$(($oneCount+$oneCount2+$eightCount+$eightCount2+$nineCount+$nineCount2+$fiveCount+$fiveCount2+$fourCount+$fourCount2+$threeCount+$threeCount2+$twoCount+$twoCount2))"
    echo $message
    
    echo "---------------------------------------------------开始发送钉钉消息----------------------------------------------------"
    curl 'https://oapi.dingtalk.com/robot/send?access_token=e9c0389f7a998844fd05c7ce3b50b674ec4c2e095510f59f36c7aa2fa66fb83a' 
       -H 'Content-Type: application/json' 
       -d "
      {'msgtype': 'text', 
        'text': {
            'content': '【预警标题】:IOS每日推送统计 
    $message'
         }
      }"
    #echo "---------------------------------------------------结束发送钉钉消息----------------------------------------------------"

    存放结构:

    执行命令:

    ./count.sh 20201102

    钉钉提示:

  • 相关阅读:
    容器小结
    STL之Map和multimap容器
    STL之Set和multiset容器
    STL之优先级队列priority_queue
    STL之List容器
    STL之Queue容器
    STL之stack容器
    应用安全-提权/降权相关整理
    安卓监听工具整理
    Linux命令整理-Kali
  • 原文地址:https://www.cnblogs.com/caoweixiong/p/13949005.html
Copyright © 2020-2023  润新知