linux_系統資源監控指令碼_system_monitor

wangzhensheng發表於2007-08-12

#!/bin/sh
#. /.profile
day=`date +%m%d%Y`
file="/var/log/system/sysinfo$day"
if [ -f $file ]; then
echo "ok">/dev/null
else
echo " date cpu mem swap load average sessions">>$file
echo " user system idle free free 1 5 15 httpdT+httpdPjavaT+javaP">>$file
echo "">>$file
fi
time=`date '+%m%d %H:%M:%S '`
load=`uptime |grep load|sed s/,//g|awk '{printf"%10s %6s %6s", $(NF-2),$(NF-1),$NF}'`
#cpu=`vmstat |grep -v [cpu][swap]|awk '{printf "%8s %6s %9s", $20,$21,$22}'`
cpu=`vmstat 1 2 | sed -n '$p' |awk '{printf "%8s %6s %9s", $13,$14,$15}'`
real=`free | grep buffers | tail +2 | awk '{print $4}'`
real2=`cat /proc/meminfo |grep "MemTotal:"|awk '{print $2}'`
#real=`vmstat |grep -v [cpu][swap]|awk '{printf "%12s %10s",$5,$4}'`
javaT=`ps -ef H|grep 'Djava.awt.headless'|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
javaP=`ps -ef |grep java|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
httpdT=`ps -ef H|grep httpd|grep -v grep|wc -l|awk '{printf "%6d",$1}'`
httpdP=`ps -ef |grep httpd|grep -v grep|wc -l|awk '{printf "%6d",$1}'`
oracle_number=`ps -ef|grep "LOCAL="|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
echo "$time $cpu $real $real2$load$httpdT$httpdP$javaT$javaP" >>$file

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8806316/viewspace-949585/,如需轉載,請註明出處,否則將追究法律責任。

相關文章