This is an automated email from the ASF dual-hosted git repository.
lidongdai pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 5bae933 update get system load (#4524)
5bae933 is described below
commit 5bae9336b025afb77bb0459fc10f333a8ff35d48
Author: crazycarry <[email protected]>
AuthorDate: Sun Jan 24 14:53:27 2021 +0800
update get system load (#4524)
Co-authored-by: hujinhui <[email protected]>
Co-authored-by: dailidong <[email protected]>
---
.../org/apache/dolphinscheduler/common/utils/OSUtils.java | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
index 08e092d..b48f2d3 100644
---
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
@@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.common.shell.ShellExecutor;
import org.apache.commons.configuration.Configuration;
+import java.lang.management.OperatingSystemMXBean;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
@@ -130,11 +131,17 @@ public class OSUtils {
* @return load average
*/
public static double loadAverage() {
- double loadAverage = hal.getProcessor().getSystemLoadAverage();
- if (Double.isNaN(loadAverage)) {
- return NEGATIVE_ONE;
+ double loadAverage;
+ try {
+ OperatingSystemMXBean osBean =
ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
+ loadAverage = osBean.getSystemLoadAverage();
+ } catch (Exception e) {
+ logger.error("get operation system load average exception, try
another method ", e);
+ loadAverage = hal.getProcessor().getSystemLoadAverage();
+ if (Double.isNaN(loadAverage)) {
+ return NEGATIVE_ONE;
+ }
}
-
DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
df.setRoundingMode(RoundingMode.HALF_UP);
return Double.parseDouble(df.format(loadAverage));