如何自动测量两个主机之间的带宽使用情况 [英] How to automate measuring of bandwidth usage between two hosts

查看:263
本文介绍了如何自动测量两个主机之间的带宽使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有TCP客户端和服务器的应用程序.我将客户端和服务器设置在不同的计算机上.现在,我要测量正在消耗多少带宽(在应用程序的一次运行中发送和接收的字节).我发现wireshark是一种可以帮助我获得此统计数据的工具.但是,wireshark似乎依赖于GUI.我想要的是一种自动化对该统计数据进行度量和报告的方法.我不在乎Wireshark捕获的有关单个数据包的信息.我不需要那个信息.有什么方法可以运行wireshark,以便它所做的全部工作都写到文件中,即应用程序在两端运行时在两个主机之间发送和接收的总字节数?

I have an application that has a TCP client and a server. I set up the client and server on separate machines. Now I want to measure how much bandwidth is being consumed ( bytes sent and received during a single run of the application). I have discovered that wireshark is one such tool that can help me get this statistic. However, wireshark seems to be GUI dependent. What I wanted was a way to automate the measuring and reporting of this statistic. I dont care about the information about individual packets captured by wireshark. I dont need that information. Is there some way to run wireshark so that all it does is write to a file, the total bytes sent and received between two hosts while the application was running on both ends?

还有没有更好的方法来捕获此统计信息?通过netstat或/proc/dev/net或任何其他工具?

Also, is there a better way to capture this statistic ? Through netstat or /proc/dev/net or any other tool ?

我的两台机器都具有ubuntu 10.04或更高版本.

Both my machines have ubuntu 10.04 or later running on them.

推荐答案

Bro 是用于测量面向连接的统计信息.您可以记录应用程序通信的痕迹或实时分析它:

Bro is an appropriate tool to measure connection-oriented statistics. You can either record a trace of your application communication or analyze it in realtime:

bro -r <trace>
bro -i <interface>

此后,请查看同一目录中的连接日志(conn.log),了解应用程序发送和接收的字节数.具体来说,您对TCP有效负载大小感兴趣,该大小通过orig_bytesresp_bytes列公开.这是一个示例:

Thereafter, have a look at the connection log (conn.log) in the same directory for the amount of bytes sent and received by the application. Specifically, you're interested in the TCP payload size, which conn.log exposes via the columns orig_bytes and resp_bytes. Here is an example:

bro-cut id.orig_h id.resp_h conn_state orig_bytes resp_bytes < conn.log | head 

将产生以下输出:

192.168.1.102   192.168.1.1     SF      301     300
192.168.1.103   192.168.1.255   S0      350     0
192.168.1.102   192.168.1.255   S0      350     0
192.168.1.103   192.168.1.255   S0      560     0
192.168.1.102   192.168.1.255   S0      348     0
192.168.1.104   192.168.1.255   S0      350     0
192.168.1.104   192.168.1.255   S0      549     0
192.168.1.103   192.168.1.1     SF      303     300
192.168.1.102   192.168.1.255   S0      -       -
192.168.1.104   192.168.1.1     SF      311     300

每一行代表一个连接,省略了传输层端口.最后两列表示发起者(第一列)和响应者(第二列)发送的字节. conn_state列代表连接状态.有关所有可能的字段,请参考文档价值观.一些重要的值是:

Each row represents a single connection, transport-layer ports omitted. The last two columns represent the bytes sent by the originator (first column) and responder (second column). The column conn_state represents the connection status. Please refer to the documentation for all possible field values. Some important values are:

  • S0 :看到连接尝试,没有回复.
  • S1 :连接已建立,未终止.
  • SF :正常建立和终止.注意,这是与状态S1相同的符号.您可以将两者区分开来,因为对于S1,摘要中将不包含任何字节计数,而对于SF,则将具有字节计数.
  • REJ :连接尝试被拒绝.
  • S0: Connection attempt seen, no reply.
  • S1: Connection established, not terminated.
  • SF: Normal establishment and termination. Note that this is the same symbol as for state S1. You can tell the two apart because for S1 there will not be any byte counts in the summary, while for SF there will be.
  • REJ: Connection attempt rejected.

这篇关于如何自动测量两个主机之间的带宽使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆