]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5936 remove ES CPU usage which is most of times null
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 23 Feb 2015 17:29:53 +0000 (18:29 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 23 Feb 2015 17:30:36 +0000 (18:30 +0100)
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java

index ec32f0a120e4e3b223aadb450220d66befaa0b7c..849de379090d6b1e4c31414fe4e1e092069bc605 100644 (file)
@@ -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 (file)
index 0000000..b95584d
--- /dev/null
@@ -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<String, Object> 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<String, Object> 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<String, Object> 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();
+  }
+}
index 4ee0fe3eef2bb42df98e6b023e2789fdaef3be08..3f69c4faf576ab61f73353aa32789824367d714f 100644 (file)
@@ -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<String, Object> 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 {