- 论坛徽章:
- 0
|
#!/bin/sh
#system_monitor
day=$(date +%m%d%Y)
file="/var/log/system/sysinfo$day"
memtotal=`awk '$1 ~ /MemTotal/{print $2}' /proc/meminfo`
if [ -f $file ]; then
echo "ok">/dev/null
else
echo "date cpu/avg mem/avg load average http java oracle" app_procnumber>>$file
echo "">>$file
fi
time=$(date '+%Y%m%d_%H:%M:%S')
load=$(uptime | sed 's/\,//g' | awk -F"average:" '{print $2}')
cpu=$(vmstat 1 2| awk '{NR==$NR}END{printf "%.1f%\n", $15/100}')
mem=$(vmstat | awk 'BEGIN{i=0}{NR==$NR}{i="'$memtotal'"-$4}END{printf "%.2f%\n", "'$memtotal'"/i}')
httpd_number=$(ps -ef | grep "httpd"| grep -v grep|wc -l)
app_number=$(ps -ef |grep "java"|grep -v grep | wc -l)
oracle_number=$(ps -ef|grep "LOCAL=NO"|grep -v grep|wc -l)
java_pid=$(ps -ef | grep java|grep -v grep |grep -v jdk|awk '{print $2}')
if [[ $java_pid"yhxx" != "yhxx" ]]
then
app_procnumber=$(lsof -p $java_pid)
else
app_procnumber=none
fi
echo "$time $cpu $mem $load $inode ${httpd_number} ${app_number} ${oracle_number} $app_procnumber" >>$file
######负责监控系统负载 |
|