summaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-24 22:11:05 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-09-26 23:49:38 +0200
commit7587e6f000c2cbf90c66f2424f3a7f597899d73d (patch)
treee051eefd9cf5e99a6b708cd1bbd49dca14a0000e /server/sonar-process
parentd66de7082395dcc2c2535c6429db68617cc98137 (diff)
downloadsonarqube-7587e6f000c2cbf90c66f2424f3a7f597899d73d.tar.gz
sonarqube-7587e6f000c2cbf90c66f2424f3a7f597899d73d.zip
SONAR-9802 add memory and cpu metrics to JvmStateSection
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java7
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java6
2 files changed, 11 insertions, 2 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java
index 804e2f0de5e..b5cf9c90f46 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/JvmStateSection.java
@@ -22,9 +22,11 @@ package org.sonar.process.systeminfo;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
+import java.lang.management.OperatingSystemMXBean;
import java.lang.management.ThreadMXBean;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import static java.lang.String.format;
import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
/**
@@ -47,6 +49,8 @@ public class JvmStateSection implements SystemInfoSection {
ProtobufSystemInfo.Section toProtobuf(MemoryMXBean memoryBean) {
ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
protobuf.setName(name);
+ addAttributeInMb(protobuf,"Max Memory (MB)", Runtime.getRuntime().maxMemory());
+ addAttributeInMb(protobuf, "Free Memory (MB)", Runtime.getRuntime().freeMemory());
MemoryUsage heap = memoryBean.getHeapMemoryUsage();
addAttributeInMb(protobuf, "Heap Committed (MB)", heap.getCommitted());
addAttributeInMb(protobuf, "Heap Init (MB)", heap.getInit());
@@ -57,7 +61,8 @@ public class JvmStateSection implements SystemInfoSection {
addAttributeInMb(protobuf, "Non Heap Init (MB)", nonHeap.getInit());
addAttributeInMb(protobuf, "Non Heap Max (MB)", nonHeap.getMax());
addAttributeInMb(protobuf, "Non Heap Used (MB)", nonHeap.getUsed());
-
+ OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
+ setAttribute(protobuf,"System Load Average", format("%.1f%% (last minute)", os.getSystemLoadAverage() * 100.0));
ThreadMXBean thread = ManagementFactory.getThreadMXBean();
setAttribute(protobuf, "Threads", thread.getThreadCount());
diff --git a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java
index 77da5df5719..c2513a418d4 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java
@@ -39,7 +39,11 @@ public class JvmStateSectionTest {
assertThat(section.getName()).isEqualTo(PROCESS_NAME);
assertThat(section.getAttributesCount()).isGreaterThan(0);
- assertThat(section.getAttributesList()).extracting("key").contains("Threads", "Heap Max (MB)");
+ assertThat(section.getAttributesList()).extracting("key")
+ .contains(
+ "Max Memory (MB)", "Free Memory (MB)",
+ "Heap Max (MB)",
+ "System Load Average", "Threads");
}
@Test