如何监控Java中特定接口的网络使用情况?
我想知道通过特定网络接口传输用于记录目的的确切数据量,是否有任何标准库或 API 调用可以让我以跨平台的方式执行此操作?
I want to know the exact amount of data which is getting transferred through a particular network interface for logging purpose, is there any standard library or api call from which I can do this in a cross platfrom way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎做你想做的事。至少,我认为它会为您指明正确的方向:
http://jnetpcap.com/
编辑:虽然不是严格跨平台的,但 libpcap 具有适用于所有主要平台的库,因此我不认为这是一个阻碍,但我不是需要它的人。
This seems to do what you'd like. At least, I think it will point you in the right direction:
http://jnetpcap.com/
edit: While not strictly cross-platform, libpcap has libraries for all major platforms so I wouldn't consider that a show-stopper, but I'm not the one that needs it.
jNetPcap 在其一些单元测试中使用 Sigar。 Sigar 将自己宣传为“用于收集系统信息的便携式接口”,包括网络接口检测、配置信息和指标。看一下它的 NetInterfaceStat 类。
请注意,Sigar 还依赖于特定于平台的 JNI,即 Rob H 的评论仍然适用。
jNetPcap uses Sigar in some of its unit tests. Sigar advertizes itself as a "portable interface for gathering system information" including network interface detection, configuration info and metrics. Take a look at its NetInterfaceStat class.
Note that Sigar also relies on platform specific JNIs, i.e. Rob H's remark still applies.
SNMP4J 将让您阅读任何 SNMP 兼容设备的接口 mib。 Linux 和 OSX(可能)已经运行了 SNMP 守护进程; Windows 有一个SNMP 服务,您可以< a href="http://www.mydigitallife.info/2007/11/01/install-and-enable-snmp-service-in-windows-xp-vista-and-2003/" rel="nofollow noreferrer">通过控制面板中的程序和功能安装。
SNMP4J will let you read the interface mib of any SNMP-compliant device. Linux and OSX (probably) have an SNMP daemon already running; Windows has an SNMP service that you can install though Programs and Features in Control Panel.