bash 在日志文件中捕获 nethogs 输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20702980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:02:56  来源:igfitidea点击:

Capture nethogs output in log file

linuxbash

提问by vab050

I want to check the network bandwidth used by my process. For this i found that nethogs tool is useful. Using this tool i can see which process is eating up a network bandwidth and process behaviour. But how do I capture data from nethogs for a my process and store it into log file ?

我想检查我的进程使用的网络带宽。为此,我发现 nethogs 工具很有用。使用此工具,我可以查看哪个进程正在占用网络带宽和进程行为。但是如何从 nethogs 为我的进程捕获数据并将其存储到日志文件中?

采纳答案by anubhava

You can use this command to capture output:

您可以使用此命令来捕获输出:

nethogs -d 5 | sed 's/[^[:print:][:cntrl:]]//g' > output.txt

回答by Aquarius Power

I dont know when these options got implemented but you can use nethogs -tor nethogs -b, the pid and user are strangely placed at the end of the pid command string, but easy enough to parse.

我不知道这些选项何时实现,但您可以使用nethogs -tor nethogs -b,pid 和 user 奇怪地放在 pid 命令字符串的末尾,但很容易解析。

I think you need to use the latest cvs version 0.8.1-SNAPSHOT

我认为你需要使用最新的 cvs 版本 0.8.1-SNAPSHOT

回答by Arif A.

The right command of nethogs is

nethogs 的正确命令是

 nethogs -d 1 eth0 > output.txt

You need to specify the network interface otherwise, the default interface eth0 will be used. Sometime, nethogs might not show the proper output because of the network interface. It is always better to provide the network interface and generate some traffic during the experimentation. You can print the output to a file by adding > output.txt-d argument specifies how frequently the output will be shown. Here, I gave 1, this indicates that the output will be shown per second.

您需要指定网络接口,否则将使用默认接口 eth0。有时,由于网络接口,nethogs 可能无法显示正确的输出。在实验过程中提供网络接口并产生一些流量总是更好的。您可以通过添加> output.txt-d 参数将输出打印到文件, 指定输出的显示频率。在这里,我给了 1,这表示将每秒显示输出。

Hope this might be useful.

希望这可能有用。

回答by kaptan

You can run nethogsin background in tracemode and write output to a file like this:

您可以nethogs在跟踪模式下在后台运行并将输出写入文件,如下所示:

sudo nethogs -t eth1 &> /var/tmp/nethogs.log & 

Download and build the nethogs-parseras described here.

下载并nethogs-parser按照此处所述构建。

Then after you have accumulated enough data you can run the parser to see the results:

然后在您积累了足够的数据后,您可以运行解析器来查看结果:

./hogs -type=pretty /var/tmp/nethogs.log 

Make sure to kill the running nethogsprocess when you are done collecting data.

nethogs完成收集数据后,请确保终止正在运行的进程。

More info hereon automating the task.

更多信息在这里对自动化任务。