¿ù°£ Àα⠰Խù°

°Ô½Ã¹° 56°Ç
   
½Ã½ºÅÛ ½Ç½Ã°£ ¸ð´ÏÅ͸µ (Æ®·¡ÇÈ, ¸Þ¸ð¸®, SWAP)
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2011-04-01 (±Ý) 15:13 Á¶È¸ : 6420
±ÛÁÖ¼Ò :
                          

#!/bin/sh
#
data_file=/proc/net/dev
meminfo=/proc/meminfo
if_dev1=eth1
if_dev2=eth2
if_ipaddr1=`ifconfig $if_dev1 | grep "inet addr" | cut -d: -f2 | awk '{print $1}'`
if_ipaddr2=`ifconfig $if_dev1 | grep "inet addr" | cut -d: -f2 | awk '{print $1}'`
interval=$1
 
# check to system resources
cpu_each=`grep 'processor' /proc/cpuinfo  | wc -l`
mem_total=`grep "MemTotal" $meminfo | cut -d: -f2 | awk '{print $1}'`
mem_t=$(echo "scale=0;$mem_total/1000" | bc)
mem_dt="$mem_t MB"
mem_free=`grep "MemFree" $meminfo | cut -d: -f2 | awk '{print $1}'`
mem_usage=$(echo "scale=1;$mem_total-$mem_free" | bc)
mem_u=$(echo "scale=0;$mem_usage/1000" | bc)
mem_du="$mem_u MB"
 
swap_total=`grep "SwapTotal" $meminfo | cut -d: -f2 | awk '{print $1}'`
swap_free=`grep "SwapFree" $meminfo | cut -d: -f2 | awk '{print $1}'`
swap_usage=$(echo "scale=1;$swap_total-$swap_free" | bc)
swap_u=$(echo "scale=0;$swap_usage/1000" | bc)
swap_du="$swap_u MB"
swap_t=$(echo "scale=0;$swap_total/1000" | bc)
swap_dt="$swap_t MB"

if [ ! "$1" ]; then
    interval=1
fi
 
while :
do
    clear
 
    # Received
    bps_r_1=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $1}'`
    pkt_r_1=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $2}'`
 
    # Trans
    bps_t_1=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $9}'`
    pkt_t_1=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $10}'`
 
    sleep $interval
 
    # Received
    bps_r_2=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $1}'`
    pkt_r_2=`grep $if_dev1 $data_file | cut -d: -f2| awk '{print $2}'`
 
    # Trans
    bps_t_2=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $9}'`
    pkt_t_2=`grep $if_dev1 $data_file | cut -d: -f2 | awk '{print $10}'`
    bps_r_3=$(echo "scale=3; $bps_r_2-$bps_r_1" | bc)
    bps_t_3=$(echo "scale=3; $bps_t_2-$bps_t_1" | bc)
    pkt_r_3=$(echo "scale=3; $pkt_r_2-$pkt_r_1" | bc)
    pkt_t_3=$(echo "scale=3; $pkt_t_2-$pkt_t_1" | bc)
 
    # BPS
    if [ $bps_r_3 -lt "1000" ]; then
        bps_r_4=$(echo $bps_r_3)
    # Kbps
    elif [ $bps_r_3 -gt "1000" -o $bps_r_3 -lt "1000000" ]; then
        bps_r_4=$(echo "scale=3; $bps_r_3 / 1000" | bc)
    # Mbsp
    elif [ $bps_r_3 -gt "1000000" -o $bps_r_3 -lt "1000000000" ]; then
        bps_r_4=$(echo "scale=3; $bps_r_3 / 1000000" | bc)
    else
    # Gbsp
        bps_r_4=$(echo "scale=3; $bps_r_3 / 1000000000" | bc)
    fi
 
    # bps
    if [ $bps_t_3 -lt "1000" ]; then
        bps_t_4=$(echo $bps_t_3)
    # kbps
    elif [ $bps_t_3 -gt "1000" -o $bps_t_3 -lt "1000000" ]; then
        bps_t_4=$(echo "scale=3; $bps_t_3 / 1000" | bc)
    # mbsp
    elif [ $bps_t_3 -gt "1000000" -o $bps_t_3 -lt "1000000000" ]; then
        bps_t_4=$(echo "scale=3; $bps_t_3 / 1000000" | bc)
    else
    # gbsp
        bps_t_4=$(echo "scale=3; $bps_t_3 / 1000000000" | bc)
    fi

    echo IP Addr : $if_ipaddr1
    echo Mem Usage : $mem_du / $mem_dt , Swap Usage : $swap_du / $swap_dt
    echo RX bps : $bps_r_4 bps , RX pps : $pkt_r_3  pps
    echo TX bps : $bps_t_4 bps , TX pps : $pkt_t_3 pps
    sleep 1
done
 
 
½ÇÇàÈ­¸é


À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.