获取内存和CPU使用情况
我想获取总物理内存、CPU 使用率以及正在使用的内存量。我已经研究过 Runtime.freeMemory() ,但这并不是整个系统的可用内存。
I would like to get the total physical memory, the CPU usage, and and the amount of memory being used. I have looked into Runtime.freeMemory()
, but that isn't the free memory for the whole system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道我的回答迟到了,但我认为这段代码很有趣。
这是“封闭”代码的改编,应在直接应用之前进行修改:
I know I'm late with my answer, but I think this code is interesting.
This is an adaptation of "closed" code, and should be revised before aplying directly:
您可以使用 SIGAR (http://support.hyperic.com/display/SIGAR/Home)。我相信这是跨平台的(我只在 Windows 上尝试过)并且我知道它有效(因为我已经尝试过)。
Javadoc:http://www.hyperic.com/support/docs/sigar/
二进制文件: http://support.hyperic.com/display/SIGAR/Home#Home -二进制文件
You can use SIGAR (http://support.hyperic.com/display/SIGAR/Home). I believe this is cross platform (I've only tried it on Windows) and I know it works (because I've tried it).
Javadoc: http://www.hyperic.com/support/docs/sigar/
Binaries: http://support.hyperic.com/display/SIGAR/Home#Home-binaries
内存和 CPU。
中央处理器示例:
Memory and CPU.
CPU example:
在 Linux 上,您可以将 /proc/meminfo 作为文本文件打开并解析结果。
On Linux you could open /proc/meminfo as a text file and parse the result.
如果用于交互式使用,则通过“jconsole”使用 JMX。它显示漂亮的实时图表和许多其他诊断信息。
Use JMX via 'jconsole', if this if for interactive use. It displays nice realtime graphs, and lots of other diagnostic information.