原文:http://blog.sina.com.cn/s/blog_6b1dfc8701012ct0.html
这是一个精简版,经测试良好,仅含CPU磁盘和镜像监控,
完事完整版含有工作流监控、镜像自动修复、接口监控,SQL监控
#vi ds.sh
#########################################
# PROGRAM NAME : dfsdw.sh #
# SHORTCUT : ./ds #
# PARAMETERS : 1 v_sleep:refresh timer#
# CREATER : ZhouHaiTao #
# CREATE DATE : 20120326 #
#########################################
if [ -n "$1" ]; then
v_sleep=$1
else
v_sleep=60
fi
limit5=5
limit8=179
limitd=1
limiti=1
limitj=1
limitr=1
limits=1
limitm=1
limitc="copy"
v_cols=`tput cols`
v_lines=`tput lines`
put sgr0
tput civis
tput clear
post=0
this_cpu=('0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0' '0|0|0|0|0|0|0|0')
while true
do
if [ $v_sleep -le 5 ]; then
v_sleep=5
fi
if [ $v_sleep -gt 9999 ]; then
v_sleep=9999
fi
tput cup 0 0;
tput el;echo -ne " -------- ";tput rev;
if [ $limitd -eq 1 ];then
echo -n "D";
else
echo -n "d";
fi;
tput sgr0;echo -n "isk cpu mem:---------";
tput cup 0 98;echo `date '+%Y-%m-%d %H:%M:%S'`;
if [ $limitd -eq 1 ]; then
for ((j=0;j<=9;j++));do
last_cpu[$j]=${this_cpu[$j]}
case "$j" in
0) echo "SEG DSK1 USE% DSK2 USE% MemId SwapId CpuId WAIT R1K/S W1K/S R2K/S W2K/S"|awk '{printf "%-7s%-5s%-6s%-5s%-7s%-7s%-9s%-9s%-5s%-6s%-6s%-6s%-6s",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}';echo " *********************************************";
df -h|grep -e sdc -e sda2|awk 'BEGIN{printf "%-6s","mdw"}{printf "%5s %4s ",$4,$5}';
free |grep -e Swap -e Mem|awk '{printf "%6.2f% ",$4/$2*100}';
this_cpu=`cat /proc/stat|grep 'cpu '|awk '{printf "%d|%d|%d\n",$5,$6,$2+$3+$4+$5+$6+$7+$8}';date +%Y%m%d%H%M%S%N|awk '{printf "|%.0f",$1}';iostat -k|grep -e sdc -e sda2|awk '{printf "|%d|%d",$5,$6}END{printf "\n"}'`;;
1) tput cup 3 0;ssh smdw df -h|grep -e sdc -e sda2|awk 'BEGIN{printf "%-6s","smdw"}{printf "%5s %4s ",$4,$5}';
ssh smdw free |grep -e Swap -e Mem|awk '{printf "%6.2f% ",$4/$2*100}';
this_cpu[j]=`ssh smdw cat /proc/stat|grep 'cpu '|awk '{printf "%d|%d|%d\n",$5,$6,$2+$3+$4+$5+$6+$7+$8}';ssh smdw date +%Y%m%d%H%M%S%N|awk '{printf "|%.0f",$1}';ssh smdw iostat -k|grep -e sdc -e sda2|awk '{printf "|%d|%d",$5,$6}END{printf "\n"}'`;;
*) ((i=j-1));
ssh sdw$i df -h|grep data|awk 'BEGIN{printf "sdw%-3d",'$i'}{printf "%5s %4s ",$4,$5}';
ssh sdw$i free |grep -e Swap -e Mem|awk '{printf "%6.2f% ",$4/$2*100}';
this_cpu[j]=`ssh sdw$i cat /proc/stat|grep 'cpu '|awk '{printf "%d|%d|%d",$5,$6,$2+$3+$4+$5+$6+$7+$8}';ssh sdw$i date +%Y%m%d%H%M%S%N|awk '{printf "|%.0f",$1}';ssh sdw$i iostat -k|grep -e sdb -e sdd|awk '{printf "|%d|%d",$5,$6}END{printf "\n"}';`
esac
# echo ${this_cpu[$j]}
idle1=`echo ${this_cpu[$j]}|cut -d '|' -f 1`;
wait1=`echo ${this_cpu[$j]}|cut -d '|' -f 2`;
total1=`echo ${this_cpu[$j]}|cut -d '|' -f 3`;
times1=`echo ${this_cpu[$j]}|cut -d '|' -f 4`;
dskcr1=`echo ${this_cpu[$j]}|cut -d '|' -f 5`;
dskcw1=`echo ${this_cpu[$j]}|cut -d '|' -f 6`;
dskdr1=`echo ${this_cpu[$j]}|cut -d '|' -f 7`;
dskdw1=`echo ${this_cpu[$j]}|cut -d '|' -f 8`;
idle2=`echo ${last_cpu[$j]}|cut -d '|' -f 1`;
wait2=`echo ${last_cpu[$j]}|cut -d '|' -f 2`;
total2=`echo ${last_cpu[$j]}|cut -d '|' -f 3`;
times2=`echo ${last_cpu[$j]}|cut -d '|' -f 4`;
dskcr2=`echo ${last_cpu[$j]}|cut -d '|' -f 5`;
dskcw2=`echo ${last_cpu[$j]}|cut -d '|' -f 6`;
dskdr2=`echo ${last_cpu[$j]}|cut -d '|' -f 7`;
dskdw2=`echo ${last_cpu[$j]}|cut -d '|' -f 8`;
echo $idle1 $idle2 $wait1 $wait2 $total1 $total2 $times1 $times2 $dskcr1 $dskcr2 $dskcw1 $dskcw2 $dskdr1 $dskdr2 $dskdw1 $dskdw2|awk '{printf "%6.2f%-2s%6.2f%s%6.0f%6.0f%6.0f%6.0f",($1-$2)/($5-$6)*100,"%",($3-$4)/($5-$6)*100,"%",($10-$9)*1000000000/($8-$7),($12-$11)*1000000000/($8-$7),($14-$13)*1000000000/($8-$7),($16-$15)*1000000000/($8-$7)}'
tput cup $[$j+2] 83;tput el;tput cup $[$j+2] 86;
case "$j" in
# 0) echo "*********************************************";;
0) echo "* GPMON V1.2 (20120326) BY HUNTER.ZHOU@BONC *";;
1) echo "* + INC refresh timer| - DEC refresh timer *";;
# 2) echo "* 5 TROUBLE LMT/ALL | 8 SQL simple/perfect *";;
2) echo "* 0 refresh per 1Min | d Disk cpu mem on/off*";;
3) echo "* q quit the program | m Mirror alert ON/OFF*";;
# 5) echo "* j WORKFLOW ON/OF | r Running JOB ON/OFF *";;
# 4) echo "* 0 refresh per 1Min | s GP can use or not? *";;
# 6) echo "* q quit the program | *";;
4) echo "* CURRENT refresh timer is "$v_sleep"Sec";tput cup $[$j+2] 130;echo "*";;
5) echo "*********************************************";;
*) echo "";;
esac
done
fi
tput el;echo -ne " --------";tput rev;
if [ $limitm -eq 1 ];then
echo -n "M";
else
echo -n "m";
fi;
tput sgr0;echo "irror alert:--------";tput el
if [ $limitm -eq 1 ] && [ $limits -eq 1 ];then
gpstate -m|grep -v :--|grep -v Synchronized|grep -v Starting|grep -v Version|grep -v Obtaining|grep -v Type|grep -v Status
fi
#******************Keybroad process & Sleep Timer**************
posb=$post
echo -ne '\e[6n';read -sdR pos
post=`echo ${pos#*[} |cut -d ';' -f 1`
if [ $posb -eq 0 ]; then
posb=$post
fi
for ((i=$post;i<$posb;i++));do
tput el;echo " ";
done
tput cup 0 98;echo `date '+%Y-%m-%d %H:%M:%S'`;
tput cup 0 0
read -t $v_sleep -n1 key
case "$key" in
+|=) ((v_sleep=v_sleep * 2));;
-) ((v_sleep=v_sleep / 2));;
q|Q) clear;exit;;
0|o) v_sleep=60;;
5) if [ $limit5 -eq 5 ]; then
limit5=9999;
else
limit5=5;
fi;;
8) if [ $limit8 -eq 179 ]; then
limit8=9999;
limit5=5;
else
limit8=179;
fi;;
j) if [ $limitj -eq 1 ]; then
limitj=0;
else
limitj=1;
fi;;
J) limitj=1;;
r) if [ $limitr -eq 1 ]; then
limitr=0;
else
limitr=1;
fi;;
R) limitr=1;;
c) if [ $limitc = "copy" ]; then
limitc="c0py";
else
limitc="copy";
fi;;
C) limitc="c0py";;
d) if [ $limitd -eq 1 ]; then
limitd=0;
else
limitd=1;
fi;;
D) limitd=1;;
s) if [ $limits -eq 1 ]; then
limits=0;
else
limits=1;
fi;;
S) limits=1;;
m) if [ $limitm -eq 1 ]; then
limitm=0;
else
limitm=1;
fi;;
M) limitm=1;;
i) if [ $limiti -eq 1 ]; then
limiti=0;
else
limiti=1;
fi;;
I) limiti=1;;
*) echo -ne '\e[6n';read -sdR pos;;
esac;
key='1'
done