Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving CPU information in java

Tags:

java

cpu

hardware

I need to write a small client application which gives CPU information such as CPU_TYPE, Processor_Speed, Serial number, UUID, operating system, physical memory and etc...

Does any one knows very straight approach for getting these information.

Thanks in advance Viswanathan G

like image 223
iamjustcoder Avatar asked Sep 15 '11 22:09

iamjustcoder


People also ask

How to get System memory Usage in Java?

If you are looking specifically for memory in JVM: Runtime runtime = Runtime. getRuntime(); NumberFormat format = NumberFormat. getInstance(); StringBuilder sb = new StringBuilder(); long maxMemory = runtime.

How do I monitor CPU and memory?

Press the Windows key , type task manager, and press Enter . In the window that appears, click the Performance tab. On the Performance tab, a list of hardware devices is displayed on the left side.

Does Java use CPU?

Java applications may take high CPU resources for many reasons: Poorly designed application code with inefficient or infinite loops. Inefficient algorithms (poor application logic) Recursive method calls (causing hundreds of recursions)


2 Answers

For CPU try org.hyperic.sigar.cmd.CpuInfo. For OS try System.getProperties().

like image 59
Kashyap Avatar answered Oct 03 '22 00:10

Kashyap


On Windows you could use WMI to get the necessary information by simply executing a (or several) simple scripts.

On linux you can do something similar by parsing information out of proc/cpuinfo and other stuff (not an expert there).

minimal example for win

I'm not aware of any framework that is crossplatform for this kind of information - mostly because there's just no way to get this information without delving deep into the platforms insides. Depending on how much data you need you may get by by parsing the data from some trivial scripts or you could use frameworks for all platforms you need.

like image 33
Voo Avatar answered Oct 02 '22 23:10

Voo