使用 Java 检测 CPU 速度/内存/互联网速度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1297870/
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
Detect CPU Speed/Memory/Internet Speed using Java?
提问by Kirk Ouimet
Is it possible within Java to identify the total CPU speed available as well as the total system memory? Network connection speed to the web would also be awesome.
在 Java 中是否可以确定可用的总 CPU 速度以及总系统内存?到网络的网络连接速度也很棒。
采纳答案by Brian Agnew
This really depends on your OS, since Java will tell you littleabout the underlying machine. Unfortunately you have to use differing approaches depending on your OS.
这实际上取决于您的操作系统,因为Java将告诉你一点关于底层机器。不幸的是,您必须根据您的操作系统使用不同的方法。
If you're on Linux, take a look at the /proc/cpuinfofilesystem for CPU info. /procgenerally has a wealth of information. Network (IO) will be reflected via the command ifconfig.
如果您使用的是 Linux,请查看/proc/cpuinfo文件系统以获取 CPU 信息。/proc一般都有丰富的信息。网络 (IO) 将通过命令反映ifconfig。
If you're on Windows, a useful tool is WMI, which provides access to all sorts of low-level hardware stats. You can run WMI scripts via CScript. Here's a page of examplesof WMI scripts.
如果您使用的是 Windows,一个有用的工具是WMI,它提供对各种低级硬件统计信息的访问。您可以通过CScript运行 WMI 脚本。这是 WMI 脚本示例的页面。
回答by Mr Lou
Properties p = System.getProperties();
p.list(System.out);
System.out.print("Total CPU:");
System.out.println(Runtime.getRuntime().availableProcessors());
System.out.println("Max Memory:" + Runtime.getRuntime().maxMemory() + "\n" + "available Memory:" + Runtime.getRuntime().freeMemory());
System.out.println("os.name=" + System.getProperty("os.name"));
try above
试试上面
回答by Jim Ferrans
Memory stats are available from the Runtimeobject. And take a look a jconsole, a graphical client that presents information about a JMX-enabled Java Virtual Machine. It shows a lot of information including CPU usage, so you could write your own client that accesses the JMX information too.
可以从Runtime对象获得内存统计信息。看看 jconsole,这是一个图形客户端,它显示有关启用 JMX 的 Java 虚拟机的信息。它显示了很多信息,包括 CPU 使用率,因此您也可以编写自己的客户端来访问 JMX 信息。

