Search in sources :

Example 21 with NodeInfo

use of org.elasticsearch.action.admin.cluster.node.info.NodeInfo in project MSEC by Tencent.

the class ESHelper method waitForClusterReady.

public void waitForClusterReady(final TransportClient client, ArrayList<String> ips, final ClusterHealthStatus status) throws IOException {
    Logger logger = Logger.getLogger(ESHelper.class);
    int timeout = 60;
    int node_num = 0;
    long begin = System.currentTimeMillis() / 1000L;
    long end = begin;
    Set<String> done_ips = new HashSet<>();
    try {
        logger.info("waiting for cluster state: " + status.name());
        ClusterHealthResponse healthResponse = null;
        while (true) {
            try {
                healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status).setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet();
            } catch (NoNodeAvailableException | MasterNotDiscoveredException ex) {
                end = System.currentTimeMillis() / 1000L;
                if (end - begin >= timeout)
                    throw new IOException("Server start timeout");
                logger.info("server still starting/discovering, retry...");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                }
                continue;
            }
            if (healthResponse != null && healthResponse.isTimedOut()) {
                end = System.currentTimeMillis() / 1000L;
                if (//timeout
                end - begin >= timeout)
                    throw new IOException("cluster not ready, current state is " + healthResponse.getStatus().name());
                continue;
            } else {
                logger.info("cluster state ok");
                int new_node_num = healthResponse.getNumberOfNodes();
                if (new_node_num > node_num) {
                    node_num = new_node_num;
                    NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().all().get();
                    for (NodeInfo node : nodeInfos.getNodes()) {
                        if (!done_ips.contains(node.getHostname()) && ips.contains(node.getHostname())) {
                            updateStatus(node.getHostname(), "Done.");
                            done_ips.add(node.getHostname());
                        }
                    }
                    if (done_ips.size() == ips.size())
                        break;
                    end = System.currentTimeMillis() / 1000L;
                    if (//timeout
                    end - begin >= timeout)
                        break;
                }
            }
        }
    } catch (final ElasticsearchTimeoutException e) {
        throw new IOException("ES API timeout");
    }
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) Logger(org.apache.log4j.Logger) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo)

Example 22 with NodeInfo

use of org.elasticsearch.action.admin.cluster.node.info.NodeInfo in project graylog2-server by Graylog2.

the class IndexerClusterCheckerThread method doRun.

@Override
public void doRun() {
    if (!notificationService.isFirst(Notification.Type.ES_OPEN_FILES)) {
        return;
    }
    try {
        cluster.health().getStatus();
    } catch (Exception e) {
        LOG.info("Indexer not fully initialized yet. Skipping periodic cluster check.");
        return;
    }
    boolean allHigher = true;
    final Map<String, NodeInfo> nodesInfos = cluster.getDataNodes();
    final Map<String, NodeStats> nodesStats = cluster.getNodesStats(nodesInfos.keySet().toArray(new String[nodesInfos.size()]));
    for (Map.Entry<String, NodeStats> entry : nodesStats.entrySet()) {
        final String nodeId = entry.getKey();
        final NodeStats nodeStats = entry.getValue();
        final NodeInfo nodeInfo = nodesInfos.get(nodeId);
        final String nodeName = nodeInfo.getNode().getName();
        // Check number of maximum open files.
        final ProcessStats processStats = nodeStats.getProcess();
        if (processStats == null) {
            LOG.debug("Couldn't read process stats of Elasticsearch node {}", nodeName);
            return;
        }
        final long maxFileDescriptors = processStats.getMaxFileDescriptors();
        final JvmInfo jvmInfo = nodeInfo.getJvm();
        if (jvmInfo == null) {
            LOG.debug("Couldn't read JVM info of Elasticsearch node {}", nodeName);
            return;
        }
        final String osName = jvmInfo.getSystemProperties().getOrDefault("os.name", "");
        if (osName.startsWith("Windows")) {
            LOG.debug("Skipping open file limit check for Indexer node <{}> on Windows", nodeName);
        } else if (maxFileDescriptors != -1 && maxFileDescriptors < MINIMUM_OPEN_FILES_LIMIT) {
            // Write notification.
            final Notification notification = notificationService.buildNow().addType(Notification.Type.ES_OPEN_FILES).addSeverity(Notification.Severity.URGENT).addDetail("hostname", nodeInfo.getHostname()).addDetail("max_file_descriptors", maxFileDescriptors);
            if (notificationService.publishIfFirst(notification)) {
                LOG.warn("Indexer node <{}> open file limit is too low: [{}]. Set it to at least {}.", nodeName, maxFileDescriptors, MINIMUM_OPEN_FILES_LIMIT);
            }
            allHigher = false;
        }
    }
    if (allHigher) {
        Notification notification = notificationService.build().addType(Notification.Type.ES_OPEN_FILES);
        notificationService.fixed(notification);
    }
}
Also used : ProcessStats(org.elasticsearch.monitor.process.ProcessStats) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) Notification(org.graylog2.notifications.Notification) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) Map(java.util.Map)

Aggregations

NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)22 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)9 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)6 TransportAddress (org.elasticsearch.common.transport.TransportAddress)6 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)5 Map (java.util.Map)4 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)4 Table (org.elasticsearch.common.Table)4 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NodesInfoRequest (org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)3 Settings (org.elasticsearch.common.settings.Settings)3 JvmInfo (org.elasticsearch.monitor.jvm.JvmInfo)3 ClusterUpdateSettingsResponse (org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)2 HttpInfo (org.elasticsearch.http.HttpInfo)2 ProcessStats (org.elasticsearch.monitor.process.ProcessStats)2 PluginInfo (org.elasticsearch.plugins.PluginInfo)2 ThreadPool (org.elasticsearch.threadpool.ThreadPool)2 TransportInfo (org.elasticsearch.transport.TransportInfo)2