Browse Source

update get system load (#4524)

Co-authored-by: hujinhui <hujinhui@shein.com>
Co-authored-by: dailidong <dailidong66@gmail.com>
pull/3/MERGE
crazycarry 4 years ago committed by GitHub
parent
commit
5bae9336b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java

11
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 org.apache.commons.configuration.Configuration;
import java.lang.management.OperatingSystemMXBean;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -130,11 +131,17 @@ public class OSUtils {
* @return load average * @return load average
*/ */
public static double loadAverage() { public static double loadAverage() {
double loadAverage = hal.getProcessor().getSystemLoadAverage(); 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)) { if (Double.isNaN(loadAverage)) {
return NEGATIVE_ONE; return NEGATIVE_ONE;
} }
}
DecimalFormat df = new DecimalFormat(TWO_DECIMAL); DecimalFormat df = new DecimalFormat(TWO_DECIMAL);
df.setRoundingMode(RoundingMode.HALF_UP); df.setRoundingMode(RoundingMode.HALF_UP);
return Double.parseDouble(df.format(loadAverage)); return Double.parseDouble(df.format(loadAverage));

Loading…
Cancel
Save