Python 스크립트 대역폭 사용량 측정

Python 스크립트 대역폭 사용량 측정

일부 웹 페이지를 구문 분석하고 셀레늄을 사용하여 자바 스크립트를 통해 페이지를 긁어내는 Python 스크립트가 있는데 urllibs누적 대역폭 사용량을 알고 싶습니다. 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

관련 정보