cpu利用率、内存利用率、磁盘使用率、网卡、连接数

export LANG=en_US
rm -f /usr/evo/aims/aims/EVO_collect_info
#######cpu利用率
CPU=`vmstat 1 1 | tail -1 | awk 'BEGIN{sz=0} {sz=100-$15} {print sz"%"}'` 
echo $CPU > /usr/evo/aims/aims/EVO_collect_info
#######内存利用率
free | grep 'buffers/cache' >/dev/null
if [ $? -eq 0 ]
then
    phymem=`free | grep "Mem:"|awk '{print $2}'`
    phymemused=`free | grep 'buffers/cache'|awk '{print $3}'`
    Mem=`awk 'BEGIN{printf"%.2f%\n",('$phymemused'/'$phymem')*100}'`
else
    phymem=`free | grep "Mem:"|awk '{print $2}'`
    phymemused=`free | grep 'Mem'|awk '{print $3}'`
    Mem=`awk 'BEGIN{printf"%.2f%\n",('$phymemused'/'$phymem')*100}'`    
fi    
echo $Mem >> /usr/evo/aims/aims/EVO_collect_info
#######磁盘使用率
export LANG=en_US
df -hT | grep iso >/dev/null 
if [ $? -eq 0 ] 
then
    UP_DISK=`df -hT | grep iso | awk '{print $1}'`
    size=`df |grep -v $UP_DISK | grep -v Filesystem | awk ' {sum += $2};END {print (sum)}'`
    size_use=`df |grep -v $UP_DISK | grep -v Filesystem | awk ' {sum += $3};END {print (sum)}'`
    Use=`awk 'BEGIN{printf"%.2f%\n",('$size_use'/'$size')*100}'`
else
    size=`df | grep -v Filesystem | awk ' {sum += $2};END {print (sum)}'`
    size_use=`df | grep -v Filesystem | awk ' {sum += $3};END {print (sum)}'`
    Use=`awk 'BEGIN{printf"%.2f%\n",('$size_use'/'$size')*100}'`
fi
echo $Use >> /usr/evo/aims/aims/EVO_collect_info

#######网卡利用率
rx_before=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $2}')
tx_before=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $10}')
sleep 2
rx_after=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $2}')
tx_after=$(cat /proc/net/dev | grep 'eth' | tr : " " | awk '{print $10}')
rx_result=$[(rx_after-rx_before)/1024/1024]
tx_result=$[(tx_after-tx_before)/1024/1024]

echo "$rx_result" >> /usr/evo/aims/aims/EVO_collect_info
echo "$tx_result" >> /usr/evo/aims/aims/EVO_collect_info

#######连接数
netstat -an | grep ESTABLISHED | wc -l >> /usr/evo/aims/aims/EVO_collect_info


cat /usr/evo/aims/aims/EVO_collect_info | tr  "\n" "|" |sed 's/.$//'
rm -f /usr/evo/aims/aims/EVO_collect_info

你可能感兴趣的:(cpu利用率、内存利用率、磁盘使用率、网卡、连接数)