我以前用脚本实现对实时网卡流量统
#!/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饱和度和其他信息
完整的安装过程(基于centos 6.3 x86_64,如果是ubuntu或者其linux可以参照官网文档)?
安装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.Linux Makefile
make
安装错误及解决方法
[root@andy 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
[root@localhost 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
安装脚本:
#/bin/bash #author junun #blog http://angus717.blog.51cto.com # 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
具体使用可以看http://angus717.blog.51cto.com/1593644/1208937,以后可能不在维护51的博客了。
相关推荐
nicstat-1.92.tar.gz nicstat-1.92.tar.gz nicstat-1.92.tar.gz
nicstat 是 Solaris 和 Linux 的网络流量统计工具
nicstat 是 Solaris 和 Linux 的网络流量统计工具
Linux网络监控工具(nicstat-1.92.tar.gz),nicstat 是 Solaris 和 Linux 的网络流量统计工具
nicstat源码,nicstat 是 Solaris 和 Linux 的网络流量统计工具。
nicstat源码,nicstat 是 Solaris 和 Linux 的网络流量统计工具。
Linux网络监控工具(nicstat-1.95.tar.gz),nicstat 是 Solaris 和 Linux 的网络流量统计工具
在类Unix系统中可以使用top查看系统资源、进程、内存占用等信息。查看网络状态可以使用netstat、nmap等工具。若要查看实时的网络流量,监控TCP/IP连接等,则可以使用iftop。
适用于 Solaris 和 Linux 的网络流量静态实用程序
要使用,请指示工具箱实用程序使用ragnarb/toolbox而不是默认的 Fedora 容器。 请参阅此容器的条目。 包含的工具 该工具箱面向性能指标收集和调试。 一些工具包括通用工具,如 htop、dstat、atop 和 sar; 更具体...
二 性能分析工具介绍(mytop,innotop,orzdba,tcpdump,pt-query-digest,tbdba-slow-picker.pl,iotop,io-profile,nicstat,mpstat,iostat,vmstat,tcprstat,dstat,oprofile,vmtouch) 三 主从复制延时解决(relay-fetch...
大部分在我日常工具箱里或者在实践的案例里面使用过,都有很高的价值,这里方便大家索引下: nicstat:参见这里 oprofile:参见这里 perf:参见这里 systemtap:参见这里 iotop:参见这里 blktrace:参见这里 ...