#! /bin/bash
#############
#CPU_use    #
#############
IP=`ifconfig eth3 | grep 'inet addr' | cut -f2 -d: | cut -f1 -d " "`
cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d .`
time=`date +%Y-%m-%d/%H-%M-%S`
if [ $cpu_idle -lt 20 ]
then
  echo "$IP服务器cpu剩余$cpu_idle,使用超过80%,请注意. $time"
else
  echo "$IP服务器cpu当前空闲值为:$cpu_idle"
fi


############
#System load#
############
IP=`ifconfig eth3 | grep 'inet addr' | cut -f2 -d: | cut -f1 -d " "`
cpu_num=`grep -c "model name" /proc/cpuinfo`
load_15=`uptime | awk '{print $12}'`
load_warn=1.0
time=`date +%Y-%m-%d/%H-%M-%S`
if [[ "$load_15" > 1.0 ]]
then
   echo "$IP服务器15分钟的平均负载超过警戒值1.0,请注意!!! $time"
else
   echo "$IP服务器15分钟的平均负载为: $load_15"
fi

############
#traffic   #
############
time=`date +%Y-%m-%d/%H:%M:%S`
R1=`cat /sys/class/net/eth3/statistics/rx_bytes`
T1=`cat /sys/class/net/eth3/statistics/tx_bytes`
sleep 2
R2=`cat /sys/class/net/eth3/statistics/rx_bytes`
T2=`cat /sys/class/net/eth3/statistics/tx_bytes`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`

TKBPS=`expr $TBPS / 1024`
BKBPS=`expr $RBPS / 1024`

echo "上传速率 eth3: $TKBPS KB/s ,下载速率 eth3:$BKBPS KB/s at $timeo"

###########
#swap     #
###########
swap_total=`free -m | grep Swap | awk '{print $2}'`
swap_free=`free -m | grep Swap | awk '{print $4}'`
swap_use=`free -m | grep Swap | awk '{print $3}'`
echo "Swap分区的总大小为: ${swap_total}M, 当前使用了${swap_use}M。"