Search in sources :

Example 1 with NodeStatsResponse

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;
}
Also used : NodeStatsResponse(org.sonar.server.es.response.NodeStatsResponse) ArrayList(java.util.ArrayList)

Example 2 with NodeStatsResponse

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);
    }
}
Also used : NodeStatsResponse(org.sonar.server.es.response.NodeStatsResponse) NodeStats(org.sonar.server.es.response.NodeStats)

Example 3 with NodeStatsResponse

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));
    });
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) ClearIndicesCacheResponse(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) GetIndexResponse(org.elasticsearch.client.indices.GetIndexResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) Response(org.elasticsearch.client.Response) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) ClusterStatsResponse(org.sonar.server.es.response.ClusterStatsResponse) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) ClearScrollResponse(org.elasticsearch.action.search.ClearScrollResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) NodeStatsResponse(org.sonar.server.es.response.NodeStatsResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndicesStatsResponse(org.sonar.server.es.response.IndicesStatsResponse) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetRequest(org.elasticsearch.action.get.GetRequest) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClearIndicesCacheRequest(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Request(org.elasticsearch.client.Request) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) JsonObject(com.google.gson.JsonObject)

Example 4 with NodeStatsResponse

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");
}
Also used : NodeStatsResponse(org.sonar.server.es.response.NodeStatsResponse) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) URL(java.net.URL) Test(org.junit.Test)

Aggregations

NodeStatsResponse (org.sonar.server.es.response.NodeStatsResponse)4 JsonObject (com.google.gson.JsonObject)2 Gson (com.google.gson.Gson)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 ClearIndicesCacheRequest (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)1 ClearIndicesCacheResponse (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 ForceMergeRequest (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest)1 ForceMergeResponse (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)1 GetMappingsRequest (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest)1 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)1 PutMappingRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest)1 RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 GetSettingsRequest (org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)1 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)1 UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)1