Fix #973
This commit is contained in:
parent
bb27800bbd
commit
37b9004569
@ -22,10 +22,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -59,8 +56,7 @@ public class SystemUtils {
|
|||||||
public static final String FUNCTION_MODE_NAMING = "naming";
|
public static final String FUNCTION_MODE_NAMING = "naming";
|
||||||
|
|
||||||
|
|
||||||
|
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory
|
||||||
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean)ManagementFactory
|
|
||||||
.getOperatingSystemMXBean();
|
.getOperatingSystemMXBean();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,15 +94,15 @@ public class SystemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float getLoad() {
|
public static float getLoad() {
|
||||||
return (float)operatingSystemMXBean.getSystemLoadAverage();
|
return (float) operatingSystemMXBean.getSystemLoadAverage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getCPU() {
|
public static float getCPU() {
|
||||||
return (float)operatingSystemMXBean.getSystemCpuLoad();
|
return (float) operatingSystemMXBean.getSystemCpuLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getMem() {
|
public static float getMem() {
|
||||||
return (float)(1 - (double)operatingSystemMXBean.getFreePhysicalMemorySize() / (double)operatingSystemMXBean
|
return (float) (1 - (double) operatingSystemMXBean.getFreePhysicalMemorySize() / (double) operatingSystemMXBean
|
||||||
.getTotalPhysicalMemorySize());
|
.getTotalPhysicalMemorySize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,8 +124,11 @@ public class SystemUtils {
|
|||||||
|
|
||||||
public static List<String> readClusterConf() throws IOException {
|
public static List<String> readClusterConf() throws IOException {
|
||||||
List<String> instanceList = new ArrayList<String>();
|
List<String> instanceList = new ArrayList<String>();
|
||||||
List<String> lines = IoUtils.readLines(
|
Reader reader = null;
|
||||||
new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)), UTF_8));
|
|
||||||
|
try {
|
||||||
|
reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)), UTF_8);
|
||||||
|
List<String> lines = IoUtils.readLines(reader);
|
||||||
String comment = "#";
|
String comment = "#";
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
String instance = line.trim();
|
String instance = line.trim();
|
||||||
@ -145,6 +144,11 @@ public class SystemUtils {
|
|||||||
instanceList.add(instance);
|
instanceList.add(instance);
|
||||||
}
|
}
|
||||||
return instanceList;
|
return instanceList;
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeClusterConf(String content) throws IOException {
|
public static void writeClusterConf(String content) throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user