pid资源消耗
请帮助我找到导出流程资源使用的好方法。更具体地说:
我有一个 ac# 程序用作静态 Web 应用程序的测试压力客户端。在该 C# 程序中,我同时运行 30 个线程。
该日志记录程序应该能够每秒写入一个文件: -处理器负载 -内存使用
任何用bash编写的解决方案都会有很大的帮助!
谢谢!
Please help me in finding a good way to export a process resources use. To be more specific:
I have a c# program used as a test-stress client for a rest-ful web application. In that C# program I run 30 threads simultaneously.
This logging program should be able to write on a file, each second:
-processor load
-memory used
Any solution written in bash would be of a great help!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您使用 vmstat 实用程序进行 CPU 负载测量,并使用 ps 测量每个进程的 CPU 利用率。
不幸的是,我不记得您必须发送的命令行选项,但我相信您可以轻松找到它们。
几年前我完成了类似的任务。我在后台运行 vmstat(带有所需的命令行选项)并读取其输出。所以,我有总体的 CPU 和内存利用率。
顺便说一句,vmstat“知道”定期运行,因此您甚至不必实现自己的循环。
此外,我还运行了 ps(带有所需参数)来测量有趣进程的 CPU。
底线:这里有 10% 的 java 和 90% 的 shell 脚本。
还有最后一个注释。可以使用纯 java 来发现总体 CPU 利用率:
ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()
这将返回最后一分钟的系统负载平均值。因此,如果 1 分钟分辨率适合您,请使用它而不是 vmstat。否则 vmstat 就是你的解决方案。
I'd suggest you to use vmstat utility for CPU load measurement and ps to measure the CPU utilization per process.
Unfortunately I do not remember exactly the command line options that you have to send but I am sure you can find them yourself easily.
I implemented similar task several years ago. I ran vmstat (with required command line options) in background and read its output. So, I had the overall cpu and memory utilization.
BTW vmstat "knows" to run periodically, so you even do not have to implement your own loop.
Additionally I ran ps (with required parameters) that measured CPU of interesting process.
Bottom line: there is 10% of java and 90% of shell scripting here.
And the last note. The overall CPU utilization may be discovered using pure java:
ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()
This returns system load average in last minute. So, if 1 min resolution is good for you use this instead of vmstat. Otherwise vmstat is your solution.