Between production servers -- network monitoring

       In the background, the project in charge of the blogger is always reporting open socket excepiton by mongo recently; because the project has just been refactored, everyone thinks that the problem is caused by the refactoring. So the code has been turned over countless times, and the parameter configuration is also fine. Since this error is reported intermittently, the blogger speculates that it is probably caused by network jitter, but the jitter is too frequent and requires specific evidence; so the blogger uses a script to monitor the application server. between network conditions. Sure enough, one of the database server replicas was discovered the next day, and the network has been experiencing intermittent packet loss. Finally, the problem is solved, make a record today.

       The production servers here all use the zabbix monitoring system - but this intermittent packet loss problem was not found at all; the network situation has always been normal!

 

  Script content:

 (1).ping.sh

#! /bin/bash

for i in `cat /home/app/IPList.txt`
do
ping=`ping -c 1 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
datestr=`date '+%Y-%m-%d %H:%M:%S'`
datem=`date '+%Y%m'`
dates=`date '+%Y%m%d'`
if [ ! -d "/home/app/log/$datem" ]; then
  mkdir -p /home/app/log/$datem
fi

file="/home/app/log/"$datem"/"$dates"_"$i".csv"
if [ ! -f "$file" ]; then
  touch "$file"
  echo Time,Type,Host,Status >> $file
fi

#t=`grep -c "" $file`
#if [ $t -ge 100 ];then  #如果大于100行记录
#sed -i '1,10d' $file  #删除开始的1-10行记录
#fi

if [ $ping -eq 100  ];then
echo $datestr,ping,$i,fail >> $file
else
echo $datestr,ping,$i,ok >> $file
fi
done

 (2).start_ping.sh

#!/bin/bash
step=1  #间隔的秒数,不能大于60
for ((i=0;i<60;i=(i+step)));do
    sh /home/app/ping.sh
    sleep $step
done
exit 0

(3).IPList.txt (the IP address that needs to be monitored by the database)

1x2.xx.x0.104
1x2.xx.x0.100
1x2.xx.x0.159
1x2.xx.x0.160
1x2.xx.x0.161

Put the above three files in the /home/app directory;

Configure crontab tasks:

1.crontab -e

2.任务配置最后添加以后内容如下:* * * * * /bin/bash /home/app/start_ping.sh

Add script execution permission:

chmod +x ping.sh
chmod +x start_ping.sh

The whole monitoring is now complete! Take a look at the effect:

       The last message, the above is the entire content of the blogger's article. If you think the blogger's article is not bad, please like it; if you are interested in the blogger's other server big data technology or the blogger himself, please pay attention to the blogger's blog , and welcome to communicate with bloggers at any time.

 

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324123024&siteId=291194637