- 论坛徽章:
- 0
|
#!/bin/sh
#This is the network Traffic monitoring
if [ -n "$1" ]; then
eth_name=$1
else
eth_name="eth0"
fi
send_first=`cat /tmp/send_first`
recv_first=`cat /tmp/recv_first`
send_o=`ifconfig $eth_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}'`
recv_o=`ifconfig $eth_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}'`
send_r=`expr $send_o - $send_first`
recv_r=`expr $recv_o - $recv_first`
total_sr=`expr \( $send_r + $recv_r \) / 1024`
ifconfig $eth_name | grep bytes | awk '{print $6}' | awk -F : '{print $2}' > /tmp/send_first
ifconfig $eth_name | grep bytes | awk '{print $2}' | awk -F : '{print $2}' > /tmp/recv_first
#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 inode http java oracle app_procnumber Packet_flow">>$file
echo "">>$file
fi
time=$(date '+%Y%m%d_%H:%M:%S')
load=$(uptime | sed 's/\,//g' | awk -F"average:" '{print $2}')
inode=$(df -i | awk 'NR==2{print $5}')
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} ${total_sr}KB" >>$file |
|