mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Catch UnsatisfiedLinkError when getting CPU usage
Affects issues: - Fixed #1807
This commit is contained in:
parent
624ed50054
commit
19b64455b4
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user