`

linux网络监控

阅读更多

尝试过其中的部分方法还是好用的

一:对于Linux 网卡流量查看,iptraf 一个很不错的工具.RHEL5 iso自带有,我的系统默认没有安装. 他可以按照用户的需要,按照不同的协议统计,也可以按照不同的端口统计,还可以按照不同的网卡统计,总之,是一个很强大的工具. 在命令行直接输入:iptraf,进入一个文本图形界面,如下:

 

 

Ip 流量监控简单的流量统计信息详细的流量统计信息这个不太清楚 Lan统计 Fileters :设置一些过滤选项,如:ip,arp rarp等等. Configure :一些配置选项,觉得很有用的一个就是日志配置.自己可以指定监控信息以日志的形式保存到用户指定的位置. 先选择---------------第一个,看看.如图:

 

我选择所有网卡.

 

我开启了日志功能,日志的保存位置,默认吧.

 

我这个实验是用的虚拟机,我的真实机在不停的ping试验机. 这个工具还有一些命令参数,其实也就是上面这些选项.很方便.大家可以man一下.

二:对于Linux 网卡流量查看nload 这个工具,RHEL5没有自带,需要自行下载一个安装上.

nload是:1.#/usr/local/nload/bin/nload

一般的服务器都会有内网和外网两块网卡,nload默认的是eth0网卡,如果你想监测eth1网卡的流量:
那么

1.#/usr/local/nload/bin/nload eth1
这样即可.
nload默认分为上下两块:上半部分是:Incoming也就是进入网卡的流量,下半部分是:Outgoing,也就是从这块网卡出去的流量,每部分都 有当前流量(Curr),平均流量(Avg),最小流量(Min),最大流量(Max),总和流量(Ttl)这几个部分,看起来还是蛮直观的.
另外,你也可以自己定义流量数值显示的单位 #/usr/local/nload/bin/nload –help
就可以看到具体的相关参数了.

直接输入命令.得到下面的结果.很直观,很好.

 

三:ifstat 这个工具
RHEL5也没有自带,但是这也是一个很不错的简单易用的工具.安装好,直接输入命令,效果如下

 

如果有多网卡,就会有多列.很不错吧.

四:Linux 网卡流量查看中sar 这个工具RHEL5自带有,默 认也安装.一个强大的工具(好像这些工具都蛮强的),参数很多,有时间man一下. -n参数很有用,他有6个不同的开关:DEV | EDEV | NFS | NFSD | SOCK | ALL .DEV显示网络接口信息,EDEV显示关于网络错误的统计数据,NFS统计活动的NFS客户端的信息,NFSD统计NFS服务器的信息,SOCK显示套 接字信息,ALL显示所有5个开关.它们可以单独或者一起使用.我们现在要用的就是-n DEV了. 输入命令:sar –n DEV 1 4 <!--[if !vml]-->

 

命令后面 1 4 意思是:每一秒钟取一次值,取四次. IFACE:LAN接口
rxpck/s:每秒钟接收的数据包
txpck/s:每秒钟发送的数据包
rxbyt/s:每秒钟接收的字节数
txbyt/s:每秒钟发送的字节数
rxcmp/s:每秒钟接收的压缩数据包
txcmp/s:每秒钟发送的压缩数据包
rxmcst/s:每秒钟接收的多播数据包

 

IFACE:LAN接口 rxerr/s:每秒钟接收的坏数据包 txerr/s:每秒钟发送的坏数据包 coll/s:每秒冲突数 rxdrop/s:缓冲充满,每秒钟丢弃的已接收数据包数 txdrop/s:缓 冲充满,每秒钟丢弃的已发送数据包数 txcarr/s:发送数据包时,每秒载波错误数 rxfram/s:每秒接收数据包的帧对齐错误数 rxfifo/s:接收的数据包每秒FIFO过速的错误数 txfifo/s:发送的数据包每秒FIFO过速的错误数 下面几个更简单的方法,虽然可以看到流量的统计信息,但是太简单,也不直观.

五:iftop

iftop默认也是监测eth0网卡的流量,如果你想要监测eth1这块网卡,则需要加-i eth1来指定网卡,也就是这样:

1.#/usr/local/iftop/sbin/iftop -i eth1
iftop显示的也很直观,样子和操作有些像top命令.
在iftop的图表中有三列流量的数值显示,
其中第一列的意思是:在之前两秒钟的平均流量
第二列的意思

是:在之前10秒钟一共的流量
一列的意思是:在之前的40秒钟五分之一的流量数值
大约是这个意思,具体的限于本人英文不好,下面贴出man page的英文:
Display:
When running, iftop uses the whole screen to display network usage. At the top of the display is a logarithmic scale for the bar graph which gives a visual indication of traffic.

 

The main part of the display lists, for each pair of hosts, the rate at which data has been sent and received over the preceding 2, 10 and 40 second intervals. The direction of data flow is indicated by arrows, <= and =>. For instance,

1.foo.example.com => bar.example.com 1Kb 500b 100b
2. <= 2Mb 2Mb 2Mb
shows, on the first line, traffic from foo.example.com to bar.example.com; in the preceding 2 seconds, this averaged 1Kbit/s, around half that amount over the preceding 10s, and a fifth of that over the whole of the last 40s. During each of those intervals, the data sent in the other direction was about 2Mbit/s. On the actual display, part of each line is inverted to give a visual indication of the 10s average of traffic. You might expect to see something like this where host foo is making repeated HTTP requests to bar, which is sending data back which saturates a 2Mbit/s link.
By default, the pairs of hosts responsible for the most traffic (10 second average) are displayed at the top of the list.

At the bottom of the display, various totals are shown, including peak traffic over the last 40s, total traffic transferred (after filtering), and total transfer rates averaged over 2s, 10s and 40s.

六:mtr工具

usage: mtr [-hvrctglspni46] [--help] [--version] [--report]
[--report-cycles=COUNT] [--curses] [--gtk]
[--raw] [--split] [--no-dns] [--address interface]
[--psize=bytes/-s bytes]
[--interval=SECONDS] HOSTNAME [PACKETSIZE]

根据以上参数:mtr -h 提供帮助命令 mtr -v 显示mtr的版本信息 mtr -r 已报告模式显示 例This option puts mtr into report mode. When in this mode, mtr will run for the number of cycles specified by the -c option, and then print statistics and exit. [root@test6 ~]# mtr -r 218.213.83.193
test6.test.com Snt: 10 Loss% Last Avg Best Wrst StDev
172.16.3.2 0.0% 0.8 1.8 0.8 9.2 2.6
115.238.91.225 0.0% 1.7 2.3 1.2 5.6 1.5
61.130.126.125 0.0% 4.2 1.9 1.1 5.4 1.5
220.191.128.113 0.0% 3.4 1.8 0.9 5.0 1.3
202.97.55.5 0.0% 7.1 4.3 3.4 7.1 1.1
202.97.33.74 0.0% 5.2 4.4 3.7 6.6 0.9
202.97.33.2 10.0% 5.6 6.9 5.6 10.2 1.5
202.97.33.5 0.0% 4.0 4.7 3.7 7.1 1.2
202.97.61.38 0.0% 33.5 33.5 31.8 36.8 1.5
202.97.62.58

0.0% 80.7 35.8 28.7 80.7 16.2
218.213.83.193 0.0% 29.9 36.2 29.0 95.0 20.7 可发现我们测试一个IP地址以报告的形式呈现. 报告说明: 在报告的第一列显示的是IP地址和本机域名,这点和tracert很像 第二列 snt:10 设置每秒发送数据包的数量,默认值是10 可以通过参数 -c来指定. [root@test6 ~]# mtr -r -c 20 218.213.83.193
test6.test.com Snt: 20 Loss% Last Avg Best Wrst StDev
172.16.3.2 0.0% 0.8 2.1 0.7 10.4 2.3
115.238.91.225 0.0% 1.1 1.6 1.1 2.9 0.5
61.130.126.125 0.0% 1.8 1.4 0.9 2.3 0.3
220.191.128.113 0.0% 1.0 3.4 1.0 22.8 6.6
202.97.55.5 0.0% 3.8 3.6 3.3 4.1 0.2
202.97.33.74 0.0% 3.9 3.8 3.4 4.7 0.3
202.97.33.2 10.0% 6.6 6.8 6.1 7.5 0.5
202.97.33.5 0.0% 3.7 4.0 3.7 5.0 0.4
202.97.61.38 15.0% 32.4 32.5 31.3 34.9 0.9
202.97.62.58 0.0% 28.6 29.1 28.5 33.1 1.0
218.213.83.193 0.0% 30.0 29.6 29.1 30.4 0.4 其中-c 的说明是: --report-cycles COUNT Use this option to set the number of pings sent to determine both the machines on the network and the reliability of those machines.Each cycle lasts one second 第三列是显示的每个对应IP的丢包率 第四列显示的最近一次的返回时延 第五列是平均值 这个应该是发送ping包的平均时延 第六列是最好或者说时延最短的 第七列是 最差或者说时延最常的 第八列是 标准偏差 接下来接着说相关参数: mtr -s 用来指定ping数据包的大小 mtr -n no-dns不对IP地址做域名解析 mtr -a 来设置发送数据包的IP地址 这个对一个主机由多个IP地址是有用的 mtr -i 使用这个参数来设置ICMP返回之间的要求默认是1秒 mtr -4 IPv4 mtr -6 IPv6


七: 命令: [root@station204 ~]# watch more /proc/net/dev

 

八:调用ifconfig这个命令:

[root@station204 ~]# watch ifconfig

 

或者是命令: watch -n 1 "/sbin/ifconfig eth0 | grep bytes"

持续的监视某块网卡的数据流量
其中 eht0 对应你想要监视的网卡 bytes 对应中文版系统的“字节”

1 代表 1秒钟刷新一次                   

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics