From 43ed7d97cc2eabef53631117d1306fb7fb43020b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 23 Feb 2015 18:29:53 +0100 Subject: [PATCH] SONAR-5936 remove ES CPU usage which is most of times null --- .../server/platform/monitoring/EsMonitor.java | 5 -- .../platform/monitoring/EsMonitorTest.java | 82 +++++++++++++++++++ .../monitoring/PluginsMonitorTest.java | 11 ++- 3 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java index ec32f0a120e..849de379090 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java @@ -26,7 +26,6 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; -import org.elasticsearch.monitor.process.ProcessStats; import org.sonar.server.es.EsClient; import java.util.Date; @@ -108,10 +107,6 @@ public class EsMonitor extends BaseMonitorMBean implements EsMonitorMBean { nodeAttributes.put("Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().bytes())); nodeAttributes.put("Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes())); nodeAttributes.put("Open Files", stats.getProcess().getOpenFileDescriptors()); - ProcessStats.Cpu cpu = stats.getProcess().getCpu(); - if (cpu != null) { - nodeAttributes.put("CPU Load Average", formatPercent(cpu.getPercent())); - } nodeAttributes.put("JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPrecent())); nodeAttributes.put("JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().bytes())); nodeAttributes.put("JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().bytes())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java new file mode 100644 index 00000000000..b95584d1fb2 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java @@ -0,0 +1,82 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.monitoring; + +import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.api.config.Settings; +import org.sonar.server.es.EsTester; +import org.sonar.server.issue.index.IssueIndexDefinition; + +import java.util.LinkedHashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EsMonitorTest { + + @ClassRule + public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings())); + + @Test + public void name() throws Exception { + EsMonitor monitor = new EsMonitor(esTester.client()); + assertThat(monitor.name()).isEqualTo("ElasticSearch"); + } + + + @Test + public void cluster_attributes() throws Exception { + EsMonitor monitor = new EsMonitor(esTester.client()); + LinkedHashMap attributes = monitor.attributes(); + assertThat(monitor.getState()).isEqualTo(ClusterHealthStatus.GREEN.name()); + assertThat(attributes.get("State")).isEqualTo(ClusterHealthStatus.GREEN); + assertThat(attributes.get("Number of Nodes")).isEqualTo(1); + } + + @Test + public void node_attributes() throws Exception { + EsMonitor monitor = new EsMonitor(esTester.client()); + LinkedHashMap attributes = monitor.attributes(); + Map nodesAttributes = (Map)attributes.get("Nodes"); + + // one node + assertThat(nodesAttributes).hasSize(1); + Map nodeAttributes = (Map)nodesAttributes.values().iterator().next(); + assertThat(nodeAttributes.get("Type")).isEqualTo("Master"); + assertThat(nodeAttributes.get("Disk Usage")).isNotNull(); + assertThat(nodeAttributes.get("Store Size")).isNotNull(); + } + + @Test + public void index_attributes() throws Exception { + EsMonitor monitor = new EsMonitor(esTester.client()); + LinkedHashMap attributes = monitor.attributes(); + Map indicesAttributes = (Map)attributes.get("Indices"); + + // one index "issues" + assertThat(indicesAttributes).hasSize(1); + Map indexAttributes = (Map)indicesAttributes.values().iterator().next(); + assertThat(indexAttributes.get("Docs")).isEqualTo(0L); + assertThat(indexAttributes.get("Shards")).isEqualTo(1); + assertThat(indexAttributes.get("Store Size")).isNotNull(); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java index 4ee0fe3eef2..3f69c4faf57 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -46,9 +47,13 @@ public class PluginsMonitorTest { public void plugin_name_and_version() throws Exception { LinkedHashMap attributes = sut.attributes(); - assertThat(attributes) - .containsEntry("plugin-1", "1.1") - .containsEntry("plugin-2", "2.2"); + assertThat(attributes).containsKeys("key-1", "key-2"); + assertThat((Map) attributes.get("key-1")) + .containsEntry("Name", "plugin-1") + .containsEntry("Version", "1.1"); + assertThat((Map)attributes.get("key-2")) + .containsEntry("Name", "plugin-2") + .containsEntry("Version", "2.2"); } private static class FakePluginRepository implements PluginRepository { -- 2.39.5