背景,博主所负责的项目最近老是mongo报open socket excepiton;因为项目刚刚重构完,大家都认为是重构引起的问题。于是代码翻了无数次,参数配置也都看没问题。由于报这个错误都是间隙性的报错,博主由此推测很可能是网络抖动所致,可是这抖动也太频繁了,且需要具体证据;于是博主就用了一个脚本来监控应用服务器之间的网络情况。果然第二天就发现了其中一台数据库服务器副本,网络一直出现间隙性丢包。总算问题解决,今天做个记录。
此处生产服务器都使用了zabbix监控系统--不过完全未发现这种间隙性丢包问题; 网络情况一直都正常!
脚本内容:
(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(需要数据库监控的IP地址)
1x2.xx.x0.104
1x2.xx.x0.100
1x2.xx.x0.159
1x2.xx.x0.160
1x2.xx.x0.161
将以上三个文件都放在/home/app目录下即可;
配置crontab任务:
1.crontab -e
2.任务配置最后添加以后内容如下:* * * * * /bin/bash /home/app/start_ping.sh
添加脚本执行权限:
chmod +x ping.sh
chmod +x start_ping.sh
整个监控到此就完成了!看看效果:
最后寄语,以上是博主本次文章的全部内容,如果大家觉得博主的文章还不错,请点赞;如果您对博主其它服务器大数据技术或者博主本人感兴趣,请关注博主博客,并且欢迎随时跟博主沟通交流。