From d66c032827817a65366acd0f98d5c64694b91dae Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 19 Sep 2017 21:49:28 +0200 Subject: [PATCH] SONAR-9845 Display type of disk in System Info on Linu --- .../sonar/process/systeminfo/SystemInfoUtils.java | 12 +++++++----- .../process/systeminfo/SystemInfoUtilsTest.java | 13 +++++++++++++ .../server/platform/monitoring/EsStateSection.java | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/SystemInfoUtils.java b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/SystemInfoUtils.java index 0126bbe2ae7..58cb458bdeb 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/systeminfo/SystemInfoUtils.java +++ b/server/sonar-process/src/main/java/org/sonar/process/systeminfo/SystemInfoUtils.java @@ -55,11 +55,13 @@ public class SystemInfoUtils { } } - public static void setAttribute(Section.Builder section, String key, boolean value) { - section.addAttributesBuilder() - .setKey(key) - .setBooleanValue(value) - .build(); + public static void setAttribute(Section.Builder section, String key, @Nullable Boolean value) { + if (value != null) { + section.addAttributesBuilder() + .setKey(key) + .setBooleanValue(value) + .build(); + } } public static void setAttribute(Section.Builder section, String key, long value) { diff --git a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/SystemInfoUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/SystemInfoUtilsTest.java index 03410f34ea9..f7e3c09ca72 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/SystemInfoUtilsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/SystemInfoUtilsTest.java @@ -30,6 +30,19 @@ import static org.assertj.core.api.Assertions.assertThat; public class SystemInfoUtilsTest { + @Test + public void test_setAttribute_with_boolean_parameter() { + Section.Builder builder = Section.newBuilder(); + SystemInfoUtils.setAttribute(builder, "isNull", (Boolean)null); + SystemInfoUtils.setAttribute(builder, "isTrue", true); + SystemInfoUtils.setAttribute(builder, "isFalse", false); + + Section section = builder.build(); + assertThat(SystemInfoUtils.attribute(section, "isNull")).isNull(); + assertThat(SystemInfoUtils.attribute(section, "isTrue").getBooleanValue()).isTrue(); + assertThat(SystemInfoUtils.attribute(section, "isFalse").getBooleanValue()).isFalse(); + } + @Test public void test_order() { Collection
sections = asList( diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java index d6f5f0df07d..e0cd9c9bca2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java @@ -66,6 +66,7 @@ public class EsStateSection implements SystemInfoSection { setAttribute(protobuf, "Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().getBytes())); setAttribute(protobuf, "Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes())); setAttribute(protobuf, "Open Files", stats.getProcess().getOpenFileDescriptors()); + setAttribute(protobuf, "Spinning", stats.getFs().getTotal().getSpins()); setAttribute(protobuf, "JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPercent())); setAttribute(protobuf, "JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().getBytes())); setAttribute(protobuf, "JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().getBytes())); -- 2.39.5