IBM JRE: Could not register cpu usage.
jpfourny opened this issue · comments
Error seen in logs:
2018-09-24 14:41:42,507 [WARN] org.stagemonitor.jvm.JvmPlugin | Could not register cpu usage. (java.lang:type=OperatingSystem is not an instance of interface com.sun.management.OperatingSystemMXBean)
CPU usage cannot be gathered on IBM JRE because CpuUtilisationWatch relies directly on com.sun.management.OperatingSystemMXBean, which is not available.
An IBM-specific subclass exists, documented here: https://www.ibm.com/support/knowledgecenter/en/SSYKE2_7.1.0/com.ibm.java.api.71.doc/com.ibm.lang.management/com/ibm/lang/management/OperatingSystemMXBean.html
Note: The IBM interface exposes two methods, one that returns 100-ns unit, and another in nanoseconds (which should be equivalent to the Sun version). See: getProcessCpuTimeByNS().
Recommendation: Use reflection to access the IBM-specific interface, since you probably won't have it at compile time without an IBM JDK.