--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 java.util.Map;
+import org.elasticsearch.ElasticsearchException;
+import org.elasticsearch.action.admin.indices.stats.IndexStats;
+import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.process.systeminfo.Global;
+import org.sonar.process.systeminfo.SystemInfoSection;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.es.EsClient;
+
+import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;
+import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
+
+@ServerSide
+public class EsIndexesSection implements SystemInfoSection, Global {
+
+ private final EsClient esClient;
+
+ public EsIndexesSection(EsClient esClient) {
+ this.esClient = esClient;
+ }
+
+ @Override
+ public ProtobufSystemInfo.Section toProtobuf() {
+ ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
+ protobuf.setName("Search Indexes");
+ try {
+ completeIndexAttributes(protobuf);
+ } catch (Exception es) {
+ Loggers.get(EsIndexesSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"Error\" attribute.", es);
+ setAttribute(protobuf, "Error", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage());
+ }
+ return protobuf.build();
+ }
+
+ private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) {
+ IndicesStatsResponse indicesStats = esClient.prepareStats().all().get();
+ for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) {
+ String prefix = "Index " + indexStats.getKey() + " - ";
+ setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount());
+ setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length);
+ setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes()));
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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 java.util.Map;
-import org.elasticsearch.ElasticsearchException;
-import org.elasticsearch.action.admin.indices.stats.IndexStats;
-import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.systeminfo.Global;
-import org.sonar.process.systeminfo.SystemInfoSection;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-import org.sonar.server.es.EsClient;
-
-import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;
-import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
-
-@ServerSide
-public class EsStatisticsSection implements SystemInfoSection, Global {
-
- private final EsClient esClient;
-
- public EsStatisticsSection(EsClient esClient) {
- this.esClient = esClient;
- }
-
- @Override
- public ProtobufSystemInfo.Section toProtobuf() {
- ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
- protobuf.setName("Search Statistics");
- try {
- completeIndexAttributes(protobuf);
- } catch (Exception es) {
- Loggers.get(EsStatisticsSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"Error\" attribute.", es);
- setAttribute(protobuf, "Error", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage());
- }
- return protobuf.build();
- }
-
- private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) {
- IndicesStatsResponse indicesStats = esClient.prepareStats().all().get();
- for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) {
- String prefix = "Index " + indexStats.getKey() + " - ";
- setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount());
- setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length);
- setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes()));
- }
- }
-}
new JvmStateSection("Web JVM State"),
DatabaseSection.class,
EsStateSection.class,
- EsStatisticsSection.class,
+ EsIndexesSection.class,
PluginsSection.class,
SettingsSection.class,
StandaloneSystemSection.class,
new JvmPropertiesSection("Web JVM Properties"),
new JvmStateSection("Web JVM State"),
DatabaseSection.class,
- EsStatisticsSection.class,
+ EsIndexesSection.class,
GlobalSystemSection.class,
LoggingSection.class,
NodeSystemSection.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ElasticsearchException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.es.EsClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.issue.index.IssueIndexDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
+import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
+
+public class EsIndexesSectionTest {
+
+ @Rule
+ public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
+
+ private EsIndexesSection underTest = new EsIndexesSection(esTester.client());
+
+ @Test
+ public void name() {
+ assertThat(underTest.toProtobuf().getName()).isEqualTo("Search Indexes");
+ }
+
+ @Test
+ public void index_attributes() {
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+
+ // one index "issues"
+ assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L);
+ assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0);
+ assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull();
+ }
+
+ @Test
+ public void attributes_displays_exception_message_when_cause_null_when_client_fails() {
+ EsClient esClientMock = mock(EsClient.class);
+ EsIndexesSection underTest = new EsIndexesSection(esClientMock);
+ when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with no cause"));
+
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThatAttributeIs(section, "Error", "RuntimeException with no cause");
+ }
+
+ @Test
+ public void attributes_displays_exception_message_when_cause_is_not_ElasticSearchException_when_client_fails() {
+ EsClient esClientMock = mock(EsClient.class);
+ EsIndexesSection underTest = new EsIndexesSection(esClientMock);
+ when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with cause not ES", new IllegalArgumentException("some cause message")));
+
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThatAttributeIs(section, "Error", "RuntimeException with cause not ES");
+ }
+
+ @Test
+ public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() {
+ EsClient esClientMock = mock(EsClient.class);
+ EsIndexesSection underTest = new EsIndexesSection(esClientMock);
+ when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message")));
+
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThatAttributeIs(section, "Error", "some cause message");
+ }
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.ElasticsearchException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.index.IssueIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
-import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
-
-public class EsStatisticsSectionTest {
-
- @Rule
- public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
-
- private EsStatisticsSection underTest = new EsStatisticsSection(esTester.client());
-
- @Test
- public void name() {
- assertThat(underTest.toProtobuf().getName()).isEqualTo("Search Statistics");
- }
-
- @Test
- public void index_attributes() {
- ProtobufSystemInfo.Section section = underTest.toProtobuf();
-
- // one index "issues"
- assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L);
- assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0);
- assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull();
- }
-
- @Test
- public void attributes_displays_exception_message_when_cause_null_when_client_fails() {
- EsClient esClientMock = mock(EsClient.class);
- EsStatisticsSection underTest = new EsStatisticsSection(esClientMock);
- when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with no cause"));
-
- ProtobufSystemInfo.Section section = underTest.toProtobuf();
- assertThatAttributeIs(section, "Error", "RuntimeException with no cause");
- }
-
- @Test
- public void attributes_displays_exception_message_when_cause_is_not_ElasticSearchException_when_client_fails() {
- EsClient esClientMock = mock(EsClient.class);
- EsStatisticsSection underTest = new EsStatisticsSection(esClientMock);
- when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with cause not ES", new IllegalArgumentException("some cause message")));
-
- ProtobufSystemInfo.Section section = underTest.toProtobuf();
- assertThatAttributeIs(section, "Error", "RuntimeException with cause not ES");
- }
-
- @Test
- public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() {
- EsClient esClientMock = mock(EsClient.class);
- EsStatisticsSection underTest = new EsStatisticsSection(esClientMock);
- when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message")));
-
- ProtobufSystemInfo.Section section = underTest.toProtobuf();
- assertThatAttributeIs(section, "Error", "some cause message");
- }
-}