问题原文
原帖链接 · xrfang · CC BY-SA 4.0
nethogs is a great utility to monitor network traffic by process. However, it is "interactive" and not suitable to be used in script... How can I achieve the following using nethogs or similar tool:
I want to monitor a process (by its id or name) for a few second, get its traffic (as a number, in any unit such as KB/s), if the traffic is lower than a threshold, the script returns non-zero.
Thanks a lot.
EDIT:
- Debian 10 Server
- The program I need to monitor is ffmpeg, which push RTSP stream to remote RTMP server. i.e. it is a "client", not "server".
- If possible I'd like to avoid iptables. Also, since there are many instance of ffmpeg running, find out traffice for each and every instance is vital. I don't know if iptables can trace process or not??
已采纳解答
原帖链接 · xrfang · CC BY-SA 4.0
I found that "nethogs" has some command line options, especially -t (trace mode) which is suitable for use in scripts:
nethogs -s -t -c 5 eno1 2>/dev/null | grep ffmpeg
This will count all traffic on the eno1 interface for 5 seconds, then quits.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
