🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ [bilxf@GPRSGX4 monitor]$cat monitor.sh #!/bin/bash HOME=/home/monitor REPORT=$HOME/monitor_`hostname`_`date +%Y%m`.log TMP=$HOME/monitor.tmp ETH=bond1 if [ ! -f $REPORT ]; then touch $REPORT fi if [[ $(expr $(wc -l $REPORT | awk '{print $1}') % 26) -eq 0 ]]; then echo -e "Time\t\t Mem(MB)\tFreeMem(MB)\tuser(%)\tsys(%)\tidle(%)\tiowait(%) swap(%) load RX(KB/s) TX(KB/s)" >> $REPORT fi RX_BEF=`cat /home/monitor/rx_bef` TX_BEF=`cat /home/monitor/tx_bef` RX_AFT=$(sed -n "/$ETH/p" /proc/net/dev | tr : " " | awk '{print $2}' | tee /home/monitor/rx_bef) TX_AFT=$(sed -n "/$ETH/p" /proc/net/dev | tr : " " | awk '{print $10}' | tee /home/monitor/tx_bef) iostat -c 2 3 | sed -n 10p > $TMP TIME="`date +%Y\-%m\-%d\ %H\:%M`" MEMORY=`free -m | awk 'NR==2{print $2}'` FREEMEMORY=`free -m | awk 'NR==2{print $7}'` CPU_IO="`cat $TMP | awk '{print $1,$3,$6,$4}' OFS="\t"`" SWAPUSED=`/sbin/swapon -s | tail -n 1 | awk '{printf "%3.2f",$4*100/$3}'` LOAD=`uptime | awk -F'[ ,]' '{print $(NF-4)}'` RX_RATE=$[((${RX_AFT}-${RX_BEF}))/60/1024] TX_RATE=$[((${TX_AFT}-${TX_BEF}))/60/1024] echo -e $TIME" "$MEMORY"\t"$FREEMEMORY"\t\t""$CPU_IO""\t "$SWAPUSED "\t "$LOAD"\t"$RX_RATE"\t "$TX_RATE >> $REPORT ~~~