我正在寻找一种方法来获取 eth 端口的带宽使用情况。但我需要过滤结果,只显示过去 24 小时的数字。或者以小时或分钟为单位的任何时间段。只是除了阅读 ifconfig 和 /proc/net/dev 的内容之外的其他内容。我知道这些是自上次重新启动以来的总数。有没有办法做到这一点?
答案1
你有没有尝试过使用IP流量?
要测量 24 小时内特定接口的带宽,您可以尝试如下操作:
iptraf -d eth1 -B -L /tmp/iptraf.log -t 1440
这将生成这样的报告
Total: 307 packets, 67553 bytes
(incoming: 167 packets, 46093 bytes; outgoing: 140 packets, 21460 bytes)
IP: 307 packets, 63237 bytes
(incoming: 167 packets, 43737 bytes; outgoing: 140 packets, 19500 bytes)
TCP: 288 packets, 59678 bytes
(incoming: 156 packets, 40861 bytes; outgoing: 132 packets, 18817 bytes)
UDP: 9 packets, 2719 bytes
(incoming: 6 packets, 2456 bytes; outgoing: 3 packets, 263 bytes)
ICMP: 10 packets, 840 bytes
(incoming: 5 packets, 420 bytes; outgoing: 5 packets, 420 bytes)
Other IP: 0 packets, 0 bytes
(incoming: 0 packets, 0 bytes; outgoing: 0 packets, 0 bytes)
Non-IP: 0 packets, 0 bytes
(incoming: 0 packets, 0 bytes; outgoing: 0 packets, 0 bytes)
Broadcast: 3 packets, 1770 bytes
Average rates:
Total: 9.00 kbits/s, 5.12 packets/s
Incoming: 6.13 kbits/s, 2.78 packets/s
Outgoing: 2.85 kbits/s, 2.33 packets/s
Peak total activity: 26.27 kbits/s, 11.40 packets/s
Peak incoming rate: 17.85 kbits/s, 6.20 packets/s
Peak outgoing rate: 8.41 kbits/s, 5.80 packets/s
IP checksum errors: 0