使用nicstat查看网卡状态

页面导航:首页 > 操作系统 > LINUX > 使用nicstat查看网卡状态

使用nicstat查看网卡状态

来源: 作者: 时间:2016-08-18 10:29 【

使用nicstat查看网卡状态我以前用脚本实现对实时网卡流量统Xml代码 #!/bin/bash NAME=nic_flow PIDFILE=/var/tmp/$NAME.pid LOGFILE=/var/tmp/$NAME.log function start(){ if [ -f $PIDFILE ]...
使用nicstat查看网卡状态
 
我以前用脚本实现对实时网卡流量统
Xml代码  
#!/bin/bash  
NAME=nic_flow  
PIDFILE=/var/tmp/$NAME.pid  
LOGFILE=/var/tmp/$NAME.log  
  
function start(){  
    if [ -f "$PIDFILE" ]; then  
        echo $PIDFILE  
        exit 2  
    fi  
    for (( ; ; ));do  
        eth=$1  
        [ -z "${eth:-}" ] && eth=eth0  
        time_range=$2  
        [ -z "${time_range:-}" ] && time_range=1        
        ifconfig  | awk '{print $1}' | grep "eth" > /dev/null   
        [ $? -gt 0 ] && echo "wrong NIC device" && exit 10  
        RX_1=$(cat /proc/net/dev | grep "$eth" | awk -F'[ |:]+'  '{print $4}')  
        TX_1=$(cat /proc/net/dev | grep "$eth" | awk '{print $9}')  
        sleep $time_range  
        RX_2=$(cat /proc/net/dev | grep "$eth" | awk -F'[ |:]+'  '{print $4}')  
        TX_2=$(cat /proc/net/dev | grep "$eth" | awk '{print $9}')  
        clear  
        echo  -e "`date +%k:%M:%S`      RX        TX" | tee -a $LOGFILE   
        RX=$((${RX_2}-${RX_1}))  
        TX=$((${TX_2}-${TX_1}))  
        if [[ $RX -lt 1024 ]];then  
            RX="${RX}B/s"  
        elif [[ $RX -gt 1048576 ]];then  
            RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')  
        else  
            RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')  
        fi  
        if [[ $TX -lt 1024 ]];then  
            TX="${TX}B/s"  
  
        elif [[ $TX -gt 1048576 ]];then  
            TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')  
        else  
            TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')  
        fi   
        echo -e " $eth       $RX        $TX " | tee -a $LOGFILE  
    done&   
    echo $! > $PIDFILE  
}   
function stop(){  
    [ -f $PIDFILE ] && kill `cat $PIDFILE` && rm -rf $PIDFILE  
}  
  
case "$1" in  
  start)  
    start $2 $3  
    ;;  
  stop)  
    stop  
    ;;  
  *)  
    echo $"Usage:$0  {start|stop,NIC device(eth*), time_range(s)}"  
    exit 2  
esac  
 今天发现一个更好用的工具nicstat。
nicstat可以提供更加全面的网卡信息。
          显示TCP流量统计
          显示UDP流量统计
          报告进出网卡的字节数
          报告进出网卡的数据数
          报告网卡利用率
          报告NIC饱和度和其他信息
 
 安装make环境
yum install gcc gcc-c++ make automake autoconf -y
由于nicstat依赖32 bit glibc package,所以
yum install libgcc.i686 glibc.i686 glibc-devel.i686  -y
文件并安装
cd /usr/local/src
wget http://nchc.dl.sourceforge.net/project/nicstat/nicstat-1.92.tar.gz
tar xf nicstat-1.92.tar.gz
cd nicstat-1.92
cp Makefile. Makefile
make
 
 
安装错误及解决方法
[[email protected] nicstat-1.92]# make
gcc -O3 -m32    nicstat.c   -o nicstat
In file included from /usr/include/features.h:385,
                 from /usr/include/stdio.h:28,
                 from nicstat.c:33:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
nicstat.c:99:1: warning: "DUPLEX_UNKNOWN" redefined
In file included from nicstat.c:84:
/usr/include/linux/ethtool.h:689:1: warning: this is the location of the previous definition
make: *** [nicstat] Error 1
======> yum install glibc-devel.i686
[[email protected] nicstat-1.92]# make
gcc -O3 -m32    nicstat.c   -o nicstat
nicstat.c:99:1: warning: "DUPLEX_UNKNOWN" redefined
In file included from nicstat.c:84:
/usr/include/linux/ethtool.h:519:1: warning: this is the location of the previous definition
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
make: *** [nicstat] Error 1
=======>yum install libgcc.i686
 
安装脚本:
Xml代码  
#/bin/bash  
#author junun  
#blog 
#  
  
SOFT_DIR=/usr/local/src  
  
function nicstat_ins {  
    echo "===========will inst nicstat"  
  
    ping -c 1 -t 1 www.baidu.com   
    if [[ $? -gt 0 ]];then   
        echo "nameserver 8.8.8.8\rnameserver 202.96.128.68" >>  /etc/resolv.conf   
    fi   
  
    yum install gcc gcc-c++ make automake autoconf -y   
  
    yum install libgcc.i686 glibc.i686 glibc-devel.i686  -y  
  
    cd $SOFT_DIR  
  
    wget http://nchc.dl.sourceforge.net/project/nicstat/nicstat-1.92.tar.gz  
  
    tar xf nicstat-1.92.tar.gz  
  
    cd nicstat-1.92  
  
    cp Makefile.Linux Makefile  
  
    make  
    [ $? -eq 0 ] || error  "\033[31m there are something to make \033[0m"  
  
    echo "alias nicstat='bash $SOFT_DIR/nicstat-1.92/nicstat.sh'" > /etc/profile.d/nicstat.sh  
}  
  
nicstat_ins  
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<