Get OS-level system information

后端 未结 16 1778
情话喂你
情话喂你 2020-11-22 02:02

I\'m currently building a Java app that could end up being run on many different platforms, but primarily variants of Solaris, Linux and Windows.

Has anyone been abl

16条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:19

    CPU usage isn't straightforward -- java.lang.management via com.sun.management.OperatingSystemMXBean.getProcessCpuTime comes close (see Patrick's excellent code snippet above) but note that it only gives access to time the CPU spent in your process. it won't tell you about CPU time spent in other processes, or even CPU time spent doing system activities related to your process.

    for instance i have a network-intensive java process -- it's the only thing running and the CPU is at 99% but only 55% of that is reported as "processor CPU".

    don't even get me started on "load average" as it's next to useless, despite being the only cpu-related item on the MX bean. if only sun in their occasional wisdom exposed something like "getTotalCpuTime"...

    for serious CPU monitoring SIGAR mentioned by Matt seems the best bet.

提交回复
热议问题