#!/bin/bash
echo -e resin集群巡检"\n" >> /opt/xunjian/xunjian.txt
echo -e wap集群"\n" >> /opt/xunjian/xunjian.txt
a=`cat /opt/xunjian/wap.txt`
t=`cat /opt/xunjian/touch.txt`
w=`cat /opt/xunjian/webkit.txt`
b=`date +%Y-%m-%d-%H:%M`
f=$(date +%d'\'\ %H:%M|awk -F "" '{OFS=""}{$NF="";print}')
for i in $a
do
c=`ssh $i "w|grep -oP '(?<=load average: )\d...(?=, )'"`
d=`ssh $i "df -h|grep -w /|awk '{print $4}'"`
total=`ssh $i "free -m|grep -w Mem"|awk '{print $2}'`
userd=`ssh $i "free -m|grep -w Mem"|awk '{print $3}'`
mem=`echo "scale=2;$userd/$total"|bc`
mount=`ssh $i "mount|grep -w 192.168.0.70|wc -l"`
resin=`ssh $i "ps -ef|grep resin|grep -v grep|wc -l"`
rooterror=`ssh $i "grep $f /www/youyuan.com.1/logs/root-error.log|egrep '(500error|500错误)'|wc -l"`
if [ $mount -lt 5 ]; then
hangshu=error
else
hangshu=good
fi
if [ $resin -lt 2 ]; then
jincheng=error
else
jincheng=good
fi
echo -e $i"\t"yanchao"\t"$b"\t"$c"\t"$d"\t"$mem"\t"$hangshu"\t"$jincheng"\t"$rooterror"\n" >> /opt/xunjian/xunjian.txt

done
echo -e touch集群"\n" >> /opt/xunjian/xunjian.txt
for tt in $t
do
c=`ssh $tt "w|grep -oP '(?<=load average: )\d...(?=, )'"`
d=`ssh $tt "df -h|grep -w /|awk '{print $4}'"`
total=`ssh $tt "free -m|grep -w Mem"|awk '{print $2}'`
userd=`ssh $tt "free -m|grep -w Mem"|awk '{print $3}'`
mem=`echo "scale=2;$userd/$total"|bc`
mount=`ssh $tt "mount|grep -w 192.168.0.70|wc -l"`
resin=`ssh $tt "ps -ef|grep resin|grep -v grep|wc -l"`
rooterror=`ssh $tt "grep $f /www/youyuan.com.1/logs/root-error.log|egrep '(500error|500错误)'|wc -l"`
if [ $mount -lt 5 ]; then
hangshu=error
else
hangshu=good
fi
if [ $resin -lt 2 ]; then
jincheng=error
else
jincheng=good
fi
echo -e $tt"\t"yanchao"\t"$b"\t"$c"\t"$d"\t"$mem"\t"$hangshu"\t"$jincheng"\t"$rooterror"\n" >> /opt/xunjian/xunjian.txt

done
echo -e webkit集群"\n" >> /opt/xunjian/xunjian.txt
for ww in $w
do
c=`ssh $ww "w|grep -oP '(?<=load average: )\d...(?=, )'"`
d=`ssh $ww "df -h|grep -w /|awk '{print $4}'"`
total=`ssh $ww "free -m|grep -w Mem"|awk '{print $2}'`
userd=`ssh $ww "free -m|grep -w Mem"|awk '{print $3}'`
mem=`echo "scale=2;$userd/$total"|bc`
mount=`ssh $ww "mount|grep -w 192.168.0.70|wc -l"`
resin=`ssh $ww "ps -ef|grep resin|grep -v grep|wc -l"`
rooterror=`ssh $ww "grep $f /www/youyuan.com.1/logs/root-error.log|egrep '(500error|500错误)'|wc -l"`
if [ $mount -lt 5 ]; then
hangshu=error
else
hangshu=good
fi
if [ $resin -lt 2 ]; then
jincheng=error
else
jincheng=good
fi
echo -e $ww"\t"yanchao"\t"$b"\t"$c"\t"$d"\t"$mem"\t"$hangshu"\t"$jincheng"\t"$rooterror"\n" >> /opt/xunjian/xunjian.txt

done



结果

resin集群巡检

服务器ip 巡检人 巡检日期 负载 磁盘空间 io使用率 内存使用率 图片挂载是否正常 resin进程是否正常 root-error.log日志500错

wap集群

192.168.0.132 yanchao 2013-09-22-16:23 0.27 /dev/sda1 531G 35G 470G 7% / .59 good good 4

192.168.0.41 yanchao 2013-09-22-16:23 0.09 /dev/sda3 381G 39G 324G 11% / .72 good good 1

192.168.0.43 yanchao 2013-09-22-16:23 0.21 /dev/sda3 381G 81G 281G 23% / .64 good good 7

192.168.0.42 yanchao 2013-09-22-16:23 0.29 /dev/sda3 381G 44G 318G 13% / .58 good good 4

192.168.0.51 yanchao 2013-09-22-16:23 0.57 /dev/sda3 381G 34G 329G 10% / .60 good good 5

192.168.0.126 yanchao 2013-09-22-16:23 0.13 /dev/sda1 531G 13G 491G 3% / .37 good good 0

192.168.0.127 yanchao 2013-09-22-16:23 0.00 /dev/sda1 531G 11G 494G 3% / .41 good good 0

touch集群

192.168.0.211 yanchao 2013-09-22-16:23 0.08 /dev/sda1 531G 18G 486G 4% / .50 good good 0

192.168.0.44 yanchao 2013-09-22-16:23 0.26 /dev/sda3 381G 66G 296G 19% / .65 good good 0

192.168.0.130 yanchao 2013-09-22-16:23 0.09 /dev/sda1 531G 22G 483G 5% / .66 good good 0

192.168.0.131 yanchao 2013-09-22-16:23 0.05 /dev/sda1 531G 17G 487G 4% / .48 good good 0

webkit集群

192.168.0.23 yanchao 2013-09-22-16:23 1.45 1.6T 1011G 505G 67% / .55 good good 1

192.168.0.53 yanchao 2013-09-22-16:23 0.04 /dev/sda3 366G 46G 302G 13% / .82 good good 0

192.168.0.123 yanchao 2013-09-22-16:23 0.00 /dev/sda1 531G 31G 474G 7% / .54 good good 1

192.168.0.128 yanchao 2013-09-22-16:23 0.01 /dev/sda1 531G 24G 480G 5% / .51 good good 0