标签:网络丢包监控脚本
前段搞了一个根据丢包权重判断是否发送报警通知的一个脚本,相互学习学习:
脚本文件如下:
# cat checkUser.sh #!/bin/bash export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin log_time=`date +"%Y-%m-%d-%H-%M-%S"` for i in `cat /root/bin/country.txt | grep -v ‘^$‘ | awk -F ‘:‘ ‘{print $1}‘`;do #echo $i surecountry=`cat /tmp/checkUserLag.txt | grep $i` if [ "$?" -eq 0 ];then #echo $surecountry Weightnum=`cat /root/bin/country.txt | grep $i | awk -F‘#‘ ‘{print $1}‘ | awk -F ‘:‘ ‘{print $2}‘` Weightloss=`cat /root/bin/country.txt | grep CN | awk -F‘#‘ ‘{print $1}‘ | awk -F ‘:‘ ‘{print $3}‘` Content=`cat /tmp/checkUserLag.txt | grep $i` #echo $Content Numpre=`cat /tmp/checkUserLag.txt | grep $i | awk -F ‘,‘ ‘{print $3}‘ | awk -F "[()]" ‘{print $2}‘ | cut -d % -f 1 | cut -d . -f 1` Losspre=`cat /tmp/checkUserLag.txt | grep $i | awk -F ‘,‘ ‘{print $4}‘ | awk -F ‘:‘ ‘{print $2}‘ | cut -d % -f 1 | cut -d . -f 1` echo $i weight: $Weightnum $Weightloss waring : $Numpre $Losspre if [ "${Numpre}" -ne "0" -o "${Losspre}" -ne "0" ];then #echo $i $Weightnum $Weightloss $Numpre $Losspre if [ "${Numpre}" -ge "${Weightnum}" -o "${Losspre}" -ge "${Weightloss}" ];then echo "server3 ${Content} .Contact CQ or Jacky" | skypealarm -c res=$? echo ${res} >> /tmp/UserLag.log echo "${log_time} ${Content}" >> /tmp/UserLag.log #echo "$Numpre > $Weightnum or ${Losspre} > ${Weightloss}" else echo "server3 ${Content}" | skypealarm -w res=$? echo ${res} >> /tmp/UserLag.log echo "${log_time} ${Content}" >> /tmp/UserLag.log #echo "$Numpre < $Weightnum or ${Losspre} < ${Weightloss}" fi fi fi done
权重设置的文件:
# cat country.txt KR:10:10 HK:10:10 CN:10:15 JP:10:10 TW:10:10
丢包统计和访问有延迟的用户比例:
# cat checkUserLag.txt CN,total:1572,num:92(5.852%),lost:9.732% VN,total:518,num:73(14.092%),lost:9.266%
本文出自 “蚂蚁” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1946139
标签:网络丢包监控脚本
原文地址:http://215687833.blog.51cto.com/6724358/1946139