我有一个python脚本,用于urllibs
解析一些网页,并使用selenium通过javascript抓取页面,我想知道它的累积带宽使用情况。我查看过 nethogs,但它告诉我每秒的使用情况,但不会告诉我脚本在 eth0 上接收或发送了多少数据。
理想情况下,我希望它在开始监视后跟踪所有新进程,然后保留每个进程总共使用的表格。
存在这样的工具吗?如果没有,Python 中是否有一个库可以在脚本中实现来跟踪这个情况?
答案1
如果您正在寻找一个作为外部进程运行的网络监视器,并且可以提供每个连接的传输字节数统计信息,那么IP流量可以做到这一点。
看看示例截图,尤其是TCP/UDP统计明细。
答案2
nethogs 现在允许显示累积带宽使用情况。只需按“m”即可。
usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [-a] [-l] [-f filter][device [device [device ...]]]
-V : prints version.
-h : prints this help.
-b : bughunt mode - implies tracemode.
-d : delay for update refresh rate in seconds. default is 1.
-v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0.
-c : number of updates. default is 0 (unlimited).
-t : tracemode.
-p : sniff in promiscious mode (not recommended).
-s : sort output by sent column.
-l : display command line.
-a : monitor all devices, even loopback/stopped ones.
-f : EXPERIMENTAL: specify string pcap filter (like tcpdump). This may be removed orchanged in a future version.
device : device(s) to monitor. default is all interfaces up and running excluding loopback
When nethogs is running, press:
q: quit
s: sort by SENT traffic
r: sort by RECEIVE traffic
l: display command line
m: switch between total (KB, B, MB) and KB/s mode