aix_system_monitor

wangzhensheng發表於2009-02-02

1.

# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/log/system/system_monitor&
file="/var/log/system/sysinfo`date +%Y%m%d`"
time="`date +%H:%M`"
cpu=`vmstat 1 2 | sed -n '$p' |awk '{printf "%4s %4s %5s", $14,$15,$16}'`
mem_block="`vmstat 1 2 | sed -n '$p'| awk '{print $4}'`"
mem_free="`expr ${mem_block} * 4`"
load="`uptime | sed s/,/ /g|sed s/:/ /g| awk '{printf "%5s %5s %5s", $12,$13,$14}'`"
db2="`netstat -an | grep 1521 | grep -v '*.*' |wc -l`"

if [ -f $file ]; then
echo "ok">/dev/null
else
echo "time | cpu | mem | load | db2">>${file}
echo " | us sys idle | app_used | 5m 10m 15m | ">>${file}
fi
echo "${time} |${cpu} | ${mem_free} |${load} | ${db2}">>${file}

2:

#!/bin/sh
# /var/log/system/system_monitor
# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/log/system/system_monitor&
file="/var/log/system/sysinfo`date +%Y%m%d`"
time="`date +%H:%M`"
cpu=`vmstat 1 2 | sed -n '$p' |awk '{printf "%4s %4s %5s", $14,$15,$16}'`
mem_block="`svmon -P | grep `ps -ef | grep java| grep tomcat | grep -v grep | awk '{print $2}'`| awk '{print $3}'`"
mem_free="`expr ${mem_block} * 4`"
load="`uptime | sed s/,//g|sed s/://g| awk '{printf "%5s %5s %5s", $10,$11,$12}'"
web1="`netstat -an | grep '7009' | grep '10.185.17.20' |wc -l`"
web2="`netstat -an | grep '7009' | grep '10.185.17.21' |wc -l`"
db2_40="`netstat -an | grep 10.185.17.40.60008 |wc -l`"

if [ -f $file ]; then
echo "ok">/dev/null
else
echo "time | cpu | mem | load | web1_num | web2_num | db2-40">>${file}
echo " | us sys idle | app_used | 5 10 15 | ">>${file}
fi
echo "${time} |${cpu} | ${mem_free} |${load} | ${web1} | ${web2} | ${db2_40}">>${file}

[@more@]

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