Catch UnsatisfiedLinkError when getting CPU usage

Affects issues:
- Fixed #1807
This commit is contained in:
Risto Lahtela 2021-03-21 11:12:24 +02:00
parent 624ed50054
commit 19b64455b4

View File

@ -54,6 +54,7 @@ public class SystemUsage {
double averageUsage; double averageUsage;
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
try {
if (osBean instanceof com.sun.management.OperatingSystemMXBean) { if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean; com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
averageUsage = nativeOsBean.getSystemCpuLoad(); averageUsage = nativeOsBean.getSystemCpuLoad();
@ -64,6 +65,9 @@ public class SystemUsage {
if (averageUsage < 0) { if (averageUsage < 0) {
averageUsage = -1; // If unavailable, getSystemLoadAverage() returns -1 averageUsage = -1; // If unavailable, getSystemLoadAverage() returns -1
} }
} catch (UnsatisfiedLinkError e) {
averageUsage = -1; // Using some docker or something
}
return averageUsage * 100.0; return averageUsage * 100.0;
} }