use of org.sonar.server.es.response.NodeStatsResponse in project sonarqube by SonarSource.
the class SearchNodesInfoLoaderImpl method load.
public Collection<NodeInfo> load() {
NodeStatsResponse response = esClient.nodesStats();
List<NodeInfo> result = new ArrayList<>();
response.getNodeStats().forEach(nodeStat -> result.add(toNodeInfo(nodeStat)));
return result;
}
use of org.sonar.server.es.response.NodeStatsResponse in project sonarqube by SonarSource.
the class ElasticSearchMetricTask method updateFileSystemMetrics.
private void updateFileSystemMetrics() {
try {
NodeStatsResponse nodeStatsResponse = esClient.nodesStats();
if (nodeStatsResponse.getNodeStats().isEmpty()) {
LOG.error("Failed to query ES status, no nodes stats returned by elasticsearch API");
} else {
for (NodeStats nodeStat : nodeStatsResponse.getNodeStats()) {
serverMonitoringMetrics.setElasticSearchDiskSpaceFreeBytes(nodeStat.getName(), nodeStat.getDiskAvailableBytes());
serverMonitoringMetrics.setElasticSearchDiskSpaceTotalBytes(nodeStat.getName(), nodeStat.getDiskTotalBytes());
}
}
} catch (Exception e) {
LOG.error("Failed to query ES status", e);
}
}
use of org.sonar.server.es.response.NodeStatsResponse in project sonarqube by SonarSource.
the class EsClient method nodesStats.
// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
public NodeStatsResponse nodesStats() {
return execute(() -> {
Request request = new Request("GET", "/_nodes/stats/fs,process,jvm,indices,breaker");
Response response = restHighLevelClient.getLowLevelClient().performRequest(request);
return NodeStatsResponse.toNodeStatsResponse(gson.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class));
});
}
use of org.sonar.server.es.response.NodeStatsResponse in project sonarqube by SonarSource.
the class ElasticSearchMetricTaskTest method elasticsearch_free_disk_space_is_updated.
@Test
public void elasticsearch_free_disk_space_is_updated() throws IOException {
URL esNodeResponseUrl = getClass().getResource("es-node-response.json");
String jsonPayload = StringUtils.trim(IOUtils.toString(esNodeResponseUrl, StandardCharsets.UTF_8));
JsonObject jsonObject = new Gson().fromJson(jsonPayload, JsonObject.class);
NodeStatsResponse nodeStats = NodeStatsResponse.toNodeStatsResponse(jsonObject);
when(esClient.nodesStats()).thenReturn(nodeStats);
underTest.run();
String nodeName = nodeStats.getNodeStats().get(0).getName();
verify(serverMonitoringMetrics, times(1)).setElasticSearchDiskSpaceFreeBytes(nodeName, 136144027648L);
verify(serverMonitoringMetrics, times(1)).setElasticSearchDiskSpaceTotalBytes(nodeName, 250685575168L);
// elasticsearch health status is not mocked in this test, so this part raise an exception
assertThat(logTester.logs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR)).containsOnly("Failed to query ES status");
}
Aggregations