3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.monitoring.cluster;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25 import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
26 import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
27 import org.sonar.api.server.ServerSide;
28 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
29 import org.sonar.server.es.EsClient;
30 import org.sonar.server.platform.monitoring.EsStateSection;
33 public class SearchNodesInfoLoaderImpl implements SearchNodesInfoLoader {
35 private final EsClient esClient;
37 public SearchNodesInfoLoaderImpl(EsClient esClient) {
38 this.esClient = esClient;
41 public Collection<NodeInfo> load() {
42 NodesStatsResponse nodesStats = esClient.prepareNodesStats()
49 List<NodeInfo> result = new ArrayList<>();
50 nodesStats.getNodes().forEach(nodeStat -> result.add(toNodeInfo(nodeStat)));
54 private static NodeInfo toNodeInfo(NodeStats stat) {
55 String nodeName = stat.getNode().getName();
56 NodeInfo info = new NodeInfo(nodeName);
58 ProtobufSystemInfo.Section.Builder section = ProtobufSystemInfo.Section.newBuilder();
59 section.setName("Search State");
60 EsStateSection.toProtobuf(stat, section);
61 info.addSection(section.build());