shell脚本检测服务器硬盘网络cpu内存使用情况
#!/bin/bash
#==================== network ==========================
DATE=`date +%Y/%m/%d`
TIME=`date +%H:%M:%S`
eth="eth1"
TX=`ifconfig eth1|sed -n "6"p|awk '{print $5}'`
MB=1024
TX=`awk 'BEGIN{printf "%.2f", '$TX'/'$MB'/'$MB'}'`
echo "$TX MB"
wget -q -O /dev/null "https://monitor.com/receive/unit_data?code=52bis450mgbe50ze&value=$TX"
#================== hard disck space ===================
used=`df|sed -n '/xvda1/ p'|gawk '{print $3}'|sed 's/%//'`
available=`df|sed -n '/xvda1/ p'|gawk '{print $4}'|sed 's/%//'`
total=`expr $used + $available`
used_percent=`awk 'BEGIN{printf "%.2f",('$used'/'$total')*100}'`
echo "($used / $total) * 100 = $used_percent"
wget -q -O /dev/null "https://monitor.com/receive/unit_data?code=kbtomc92y2agnxrk&value=$used_percent"
#==================== cpu & memory =====================
TIMEOUT='uptime'
VMOUT='vmstat 1 2'
USERS=`$TIMEOUT|gawk '{print $6}'`
LOAD=`$TIMEOUT|gawk '{print $10}'|sed 's/,//'`
FREE=`$VMOUT|sed -n '/[0-9]/p'|sed -n '2p'|gawk '{print $4} '`
FREE=`expr $FREE / 1024`
IDLE=`$VMOUT|sed -n '/[0-9]/p'|sed -n '2p'|gawk '{print $15}'`
echo "$DATE $TIME users = $USERS 1m avg.load = $LOAD free = ${FREE}MB idle = $IDLE"
#cpu
wget -q -O /dev/null "https://monitor.com/receive/unit_data?code=u2ppmrautnv51c3s&value=$LOAD"
#memory
wget -q -O /dev/null "https://monitor.com/receive/unit_data?code=tr0nb5wpvj5rgjop&value=$FREE"