#!/bin/sh
DATE=`date +"%Y-%m-%d %T"`
if [ ! -d /home/monitor ];then
mkdir -p /home/monitor
fi
connect=`lsof -i :1521|wc -l`
conn2=`ps -ef|grep LOCAL=NO|wc -l`
echo "$connect---$DATE---" >>/home/monitor/connect.out
echo "$conn2---$DATE---" >>/home/monitor/conn2.out
############CPU###############
cpu=`iostat -c |grep -v Linux | grep -v %user | grep -v '^$' | awk '{print $1+$2+$3}'`
echo "$cpu ---$DATE---" >>/home/monitor/cpu-used.out
##########MEMORY##############
mem_used=`free -m | grep "buffers/cache" | awk '{print $3}'`
mem_total=`free -m | grep "Mem:" | awk '{print $2}'`
mem_used_percent=`echo "scale=2;100*$mem_used/$mem_total" | bc`
echo "$mem_used_percent ---$DATE---" >> /home/monitor/mem-used.out
###########DISK###############
disk_used=`df -l | grep -v Filesystem | awk 'BEGIN {SUM=0} {SUM+=$3} END {print SUM}'`
disk_total=`df -l | grep -v Filesystem | awk 'BEGIN {SUM=0} {SUM+=$2} END {print SUM}'`
disk_percent=`echo "scale=2;100*$disk_used/$disk_total" | bc`
echo "$disk_percent ---$DATE---" >> /home/monitor/disk-used.out
#############SWAP#############
swap_percent=`free -m | grep "Swap:" | awk '{print $3/$2*100}'`
echo "$swap_percent ---$DATE---" >>/home/monitor/swap-used.out
#############I/O##############
for type in cciss sda sdb sdc sdd sde sdf sdg sdh sdi
do
Blk_read=`iostat |grep $type |sed -n '1p'|awk '{print $3}'`
Blk_wrtn=`iostat |grep $type |sed -n '1p'|awk '{print $4}'`
if [ "$Blk_read" != "" ];then
echo "$type $Blk_read k/s ---$DATE---" >> /home/monitor/Blk_read.out
echo "$type $Blk_wrtn k/s ---$DATE---" >> /home/monitor/Blk_wrtn.out
fi
done
阅读(853) | 评论(0) | 转发(0) |