#!/usr/bin/ksh
PATH=/usr/bin:/bin:/usr/sbin
export PATH
time=$(date +%F)
rq=$(perl -e "use POSIX qw(strftime); print strftime '%F' , localtime( time()-3600*24*7) ")
cd /tmp/monitor
#内存监控
vmstat 3 20 > vm_cpu_cal.txt
cat vm_cpu_cal.txt | awk -F ' ' '{print $4}' | grep -v fre | grep -v faults | grep -v - | grep -v mem | sed -e '/^$/d' >> vm_mnr_$time.txt
date >> vm_cal_$time.txt
cat vm_mnr_$time.txt | awk '{sum+=$1} END {print "Average = ", 22912-sum/NR/1024*4}' >> vm_cal_$time.txt
cat vm_mnr_$time.txt | awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Min=",22912-max/1024*4}' >> vm_cal_$time.txt
cat vm_mnr_$time.txt | awk 'BEGIN {min = 9999999} {if ($1<min) min=$1 fi} END {print "Max=",22912-min/1024*4}' >> vm_cal_$time.txt
#IO监控
iostat -T 3 20 | grep hdisk3 | awk -F ' ' '{print $3}' >> io_mnr_$time.txt
date >> io_cal_$time.txt
cat io_mnr_$time.txt | awk '{sum+=$1} END {print "Average = ", sum/NR}' >> io_cal_$time.txt
cat io_mnr_$time.txt | awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}' >> io_cal_$time.txt
cat io_mnr_$time.txt | awk 'BEGIN {min = 9999999} {if ($1<min) min=$1 fi} END {print "Min=", min}' >> io_cal_$time.txt
#CPU监控
cat vm_cpu_cal.txt | awk -F ' ' '{print $16}' | grep -v id | sed -e '/^$/d' >> cpu_mnr_$time.txt
date >> cpu_cal_$time.txt
cat cpu_mnr_$time.txt | awk '{sum+=$1} END {print "Average = ",100-sum/NR,"%"}' >> cpu_cal_$time.txt
cat cpu_mnr_$time.txt | awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Min=", 100-max,"%"}' >> cpu_cal_$time.txt
cat cpu_mnr_$time.txt | awk 'BEGIN {min = 9999999} {if ($1<min) min=$1 fi} END {print "Max=", 100-min,"%"}' >> cpu_cal_$time.txt
#清理7天以前历史数据
if [ -f *$rq*.txt ]
then
cd /tmp/monitor/
rm /tmp/monitor/*$rq*
fi
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28371090/viewspace-1780699/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28371090/viewspace-1780699/