A Simple Monitor Script

#!/bin/bash
#monitor network
#kim

#影响linux性能的主要因素
#CPU
#内存
#磁盘I/O带宽
#网络I/O带宽

while : ; do
    time=`date +%m"-"%d" "%k":"%M`
    day=`date +%m"-"%d`
    rx_before=`/sbin/ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`
    tx_before=`/sbin/ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`
    sleep 1.5
    rx_after=`/sbin/ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`
    tx_after=`/sbin/ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`
    rx_result=$[(rx_after-rx_before)/256]
    tx_result=$[(tx_after-tx_before)/256]
    mem=`free -m | grep "Mem"`
    cpu=`top -n 1 | grep "Cpu"`
    load=`awk '{print $1,$2,$3}' /proc/loadavg`

    echo $time
    echo "In:\t" $rx_result"kbps\tOut: "$tx_result"kbps"
    echo "Mem:\t" $mem
    echo "Cpu:\t" $cpu
    echo "Load:\t" $load
    echo -e "\n"
done
Posted in Linux | Tagged , | Leave a comment