Search in sources :

Example 1 with NodeInfo

use of org.opensearch.action.admin.cluster.node.info.NodeInfo in project OpenSearch by opensearch-project.

the class TransportClusterStatsAction method nodeOperation.

@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false, false);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, true, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                CommitStats commitStats;
                SeqNoStats seqNoStats;
                RetentionLeaseStats retentionLeaseStats;
                try {
                    commitStats = indexShard.commitStats();
                    seqNoStats = indexShard.seqNoStats();
                    retentionLeaseStats = indexShard.getRetentionLeaseStats();
                } catch (final AlreadyClosedException e) {
                    // shard is closed - no stats is fine
                    commitStats = null;
                    seqNoStats = null;
                    retentionLeaseStats = null;
                }
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), commitStats, seqNoStats, retentionLeaseStats));
            }
        }
    }
    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }
    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) ClusterStateHealth(org.opensearch.cluster.health.ClusterStateHealth) IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) RetentionLeaseStats(org.opensearch.index.seqno.RetentionLeaseStats) ArrayList(java.util.ArrayList) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ClusterHealthStatus(org.opensearch.cluster.health.ClusterHealthStatus) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) SeqNoStats(org.opensearch.index.seqno.SeqNoStats) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) CommitStats(org.opensearch.index.engine.CommitStats)

Example 2 with NodeInfo

use of org.opensearch.action.admin.cluster.node.info.NodeInfo in project OpenSearch by opensearch-project.

the class RestThreadPoolAction method buildTable.

private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
    final String[] threadPools = req.paramAsStringArray("thread_pool_patterns", new String[] { "*" });
    final DiscoveryNodes nodes = state.getState().nodes();
    final Table table = getTableWithHeader(req);
    // collect all thread pool names that we see across the nodes
    final Set<String> candidates = new HashSet<>();
    for (final NodeStats nodeStats : nodesStats.getNodes()) {
        for (final ThreadPoolStats.Stats threadPoolStats : nodeStats.getThreadPool()) {
            candidates.add(threadPoolStats.getName());
        }
    }
    // collect all thread pool names that match the specified thread pool patterns
    final Set<String> included = new HashSet<>();
    for (final String candidate : candidates) {
        if (Regex.simpleMatch(threadPools, candidate)) {
            included.add(candidate);
        }
    }
    for (final DiscoveryNode node : nodes) {
        final NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
        final NodeStats stats = nodesStats.getNodesMap().get(node.getId());
        final Map<String, ThreadPoolStats.Stats> poolThreadStats;
        final Map<String, ThreadPool.Info> poolThreadInfo;
        if (stats == null) {
            poolThreadStats = Collections.emptyMap();
            poolThreadInfo = Collections.emptyMap();
        } else {
            // we use a sorted map to ensure that thread pools are sorted by name
            poolThreadStats = new TreeMap<>();
            poolThreadInfo = new HashMap<>();
            ThreadPoolStats threadPoolStats = stats.getThreadPool();
            for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) {
                poolThreadStats.put(threadPoolStat.getName(), threadPoolStat);
            }
            if (info != null) {
                for (ThreadPool.Info threadPoolInfo : info.getInfo(ThreadPoolInfo.class)) {
                    poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo);
                }
            }
        }
        for (Map.Entry<String, ThreadPoolStats.Stats> entry : poolThreadStats.entrySet()) {
            if (!included.contains(entry.getKey()))
                continue;
            table.startRow();
            table.addCell(node.getName());
            table.addCell(node.getId());
            table.addCell(node.getEphemeralId());
            table.addCell(info == null ? null : info.getInfo(ProcessInfo.class).getId());
            table.addCell(node.getHostName());
            table.addCell(node.getHostAddress());
            table.addCell(node.getAddress().address().getPort());
            final ThreadPoolStats.Stats poolStats = entry.getValue();
            final ThreadPool.Info poolInfo = poolThreadInfo.get(entry.getKey());
            Long maxQueueSize = null;
            String keepAlive = null;
            Integer core = null;
            Integer max = null;
            Integer size = null;
            if (poolInfo != null) {
                if (poolInfo.getQueueSize() != null) {
                    maxQueueSize = poolInfo.getQueueSize().singles();
                }
                if (poolInfo.getKeepAlive() != null) {
                    keepAlive = poolInfo.getKeepAlive().toString();
                }
                if (poolInfo.getThreadPoolType() == ThreadPool.ThreadPoolType.SCALING) {
                    assert poolInfo.getMin() >= 0;
                    core = poolInfo.getMin();
                    assert poolInfo.getMax() > 0;
                    max = poolInfo.getMax();
                } else {
                    assert poolInfo.getMin() == poolInfo.getMax() && poolInfo.getMax() > 0;
                    size = poolInfo.getMax();
                }
            }
            table.addCell(entry.getKey());
            table.addCell(poolInfo == null ? null : poolInfo.getThreadPoolType().getType());
            table.addCell(poolStats == null ? null : poolStats.getActive());
            table.addCell(poolStats == null ? null : poolStats.getThreads());
            table.addCell(poolStats == null ? null : poolStats.getQueue());
            table.addCell(maxQueueSize == null ? -1 : maxQueueSize);
            table.addCell(poolStats == null ? null : poolStats.getRejected());
            table.addCell(poolStats == null ? null : poolStats.getLargest());
            table.addCell(poolStats == null ? null : poolStats.getCompleted());
            table.addCell(core);
            table.addCell(max);
            table.addCell(size);
            table.addCell(keepAlive);
            table.endRow();
        }
    }
    return table;
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Table(org.opensearch.common.Table) ThreadPool(org.opensearch.threadpool.ThreadPool) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) ThreadPoolInfo(org.opensearch.threadpool.ThreadPoolInfo) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet)

Example 3 with NodeInfo

use of org.opensearch.action.admin.cluster.node.info.NodeInfo in project OpenSearch by opensearch-project.

the class RestPluginsAction method buildTable.

private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo) {
    DiscoveryNodes nodes = state.getState().nodes();
    Table table = getTableWithHeader(req);
    for (DiscoveryNode node : nodes) {
        NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
        if (info == null) {
            continue;
        }
        PluginsAndModules plugins = info.getInfo(PluginsAndModules.class);
        if (plugins == null) {
            continue;
        }
        for (PluginInfo pluginInfo : plugins.getPluginInfos()) {
            table.startRow();
            table.addCell(node.getId());
            table.addCell(node.getName());
            table.addCell(pluginInfo.getName());
            table.addCell(pluginInfo.getVersion());
            table.addCell(pluginInfo.getDescription());
            table.endRow();
        }
    }
    return table;
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Table(org.opensearch.common.Table) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) PluginsAndModules(org.opensearch.action.admin.cluster.node.info.PluginsAndModules) PluginInfo(org.opensearch.plugins.PluginInfo) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 4 with NodeInfo

use of org.opensearch.action.admin.cluster.node.info.NodeInfo in project OpenSearch by opensearch-project.

the class Netty4TransportPublishAddressIT method testDifferentPorts.

public void testDifferentPorts() throws Exception {
    if (!NetworkUtils.SUPPORTS_V6) {
        return;
    }
    logger.info("--> starting a node on ipv4 only");
    Settings ipv4Settings = Settings.builder().put("network.host", "127.0.0.1").build();
    // should bind 127.0.0.1:XYZ
    String ipv4OnlyNode = internalCluster().startNode(ipv4Settings);
    logger.info("--> starting a node on ipv4 and ipv6");
    Settings bothSettings = Settings.builder().put("network.host", "_local_").build();
    // should bind [::1]:XYZ and 127.0.0.1:XYZ+1
    internalCluster().startNode(bothSettings);
    logger.info("--> waiting for the cluster to declare itself stable");
    // fails if port of publish address does not match corresponding bound address
    ensureStableCluster(2);
    logger.info("--> checking if boundAddress matching publishAddress has same port");
    NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get();
    for (NodeInfo nodeInfo : nodesInfoResponse.getNodes()) {
        BoundTransportAddress boundTransportAddress = nodeInfo.getInfo(TransportInfo.class).getAddress();
        if (nodeInfo.getNode().getName().equals(ipv4OnlyNode)) {
            assertThat(boundTransportAddress.boundAddresses().length, equalTo(1));
            assertThat(boundTransportAddress.boundAddresses()[0].getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
        } else {
            assertThat(boundTransportAddress.boundAddresses().length, greaterThan(1));
            for (TransportAddress boundAddress : boundTransportAddress.boundAddresses()) {
                assertThat(boundAddress, instanceOf(TransportAddress.class));
                TransportAddress inetBoundAddress = boundAddress;
                if (inetBoundAddress.address().getAddress() instanceof Inet4Address) {
                    // IPv4 address is preferred publish address for _local_
                    assertThat(inetBoundAddress.getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));
                }
            }
        }
    }
}
Also used : NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) Inet4Address(java.net.Inet4Address) TransportInfo(org.opensearch.transport.TransportInfo) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) Settings(org.opensearch.common.settings.Settings)

Example 5 with NodeInfo

use of org.opensearch.action.admin.cluster.node.info.NodeInfo in project OpenSearch by opensearch-project.

the class Netty4TransportMultiPortIntegrationIT method testThatInfosAreExposed.

@Network
public void testThatInfosAreExposed() throws Exception {
    NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().addMetric(TRANSPORT.metricName()).get();
    for (NodeInfo nodeInfo : response.getNodes()) {
        assertThat(nodeInfo.getInfo(TransportInfo.class).getProfileAddresses().keySet(), hasSize(1));
        assertThat(nodeInfo.getInfo(TransportInfo.class).getProfileAddresses(), hasKey("client1"));
        BoundTransportAddress boundTransportAddress = nodeInfo.getInfo(TransportInfo.class).getProfileAddresses().get("client1");
        for (TransportAddress transportAddress : boundTransportAddress.boundAddresses()) {
            assertThat(transportAddress, instanceOf(TransportAddress.class));
        }
        // bound addresses
        for (TransportAddress transportAddress : boundTransportAddress.boundAddresses()) {
            assertThat(transportAddress, instanceOf(TransportAddress.class));
            assertThat(transportAddress.address().getPort(), is(allOf(greaterThanOrEqualTo(randomPort), lessThanOrEqualTo(randomPort + 10))));
        }
        // publish address
        assertThat(boundTransportAddress.publishAddress(), instanceOf(TransportAddress.class));
        TransportAddress publishAddress = boundTransportAddress.publishAddress();
        assertThat(NetworkAddress.format(publishAddress.address().getAddress()), is("127.0.0.7"));
        assertThat(publishAddress.address().getPort(), is(4321));
    }
}
Also used : NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) TransportInfo(org.opensearch.transport.TransportInfo) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) Network(org.opensearch.test.junit.annotations.Network)

Aggregations

NodeInfo (org.opensearch.action.admin.cluster.node.info.NodeInfo)15 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)6 NodesInfoResponse (org.opensearch.action.admin.cluster.node.info.NodesInfoResponse)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)4 Table (org.opensearch.common.Table)4 TransportAddress (org.opensearch.common.transport.TransportAddress)4 HttpInfo (org.opensearch.http.HttpInfo)4 ProcessInfo (org.opensearch.monitor.process.ProcessInfo)4 Map (java.util.Map)3 NodeStats (org.opensearch.action.admin.cluster.node.stats.NodeStats)3 Settings (org.opensearch.common.settings.Settings)3 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)3 ThreadPool (org.opensearch.threadpool.ThreadPool)3 TransportInfo (org.opensearch.transport.TransportInfo)3 PluginsAndModules (org.opensearch.action.admin.cluster.node.info.PluginsAndModules)2 StreamInput (org.opensearch.common.io.stream.StreamInput)2 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)2 IngestInfo (org.opensearch.ingest.IngestInfo)2