Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ private void updateNetStatus() {

if (MetricLevel.higherOrEqual(MetricLevel.NORMAL, METRIC_CONFIG.getMetricLevel())) {
// update socket num
Process process = null;
try {
Process process = Runtime.getRuntime().exec(this.getConnectNumCmd);
process = Runtime.getRuntime().exec(this.getConnectNumCmd);
StringBuilder result = new StringBuilder();
try (BufferedReader input =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {
Expand All @@ -228,9 +229,17 @@ private void updateNetStatus() {
result.append(line);
}
}
process.waitFor();
this.connectionNum = Integer.parseInt(result.toString().trim());
} catch (IOException e) {
LOGGER.error("Failed to get socket num", e);
} catch (InterruptedException e) {
LOGGER.error("Interrupted while waiting for socket num command", e);
Thread.currentThread().interrupt();
} finally {
if (process != null) {
process.destroyForcibly();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ private void updateLinuxSystemMemInfo() {
long time = System.currentTimeMillis();
if (time - lastUpdateTime > MetricConstant.UPDATE_INTERVAL) {
lastUpdateTime = time;
Process process = null;
try {
Process process = runtime.exec(getSystemMemoryCommand);
process = runtime.exec(getSystemMemoryCommand);
StringBuilder result = new StringBuilder();
try (BufferedReader input =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {
Expand All @@ -227,6 +228,7 @@ private void updateLinuxSystemMemInfo() {
result.append(line).append("\n");
}
}
process.waitFor();
String[] lines = result.toString().trim().split("\n");
// if failed to get result
if (lines.length >= 2) {
Expand All @@ -240,6 +242,13 @@ private void updateLinuxSystemMemInfo() {
}
} catch (IOException e) {
logger.debug("Failed to get memory, because ", e);
} catch (InterruptedException e) {
logger.debug("Interrupted while waiting for memory command", e);
Thread.currentThread().interrupt();
} finally {
if (process != null) {
process.destroyForcibly();
}
}
}
}
Expand Down