org.elasticsearch.threadpool.ThreadPoolStats Java Examples

The following examples show how to use org.elasticsearch.threadpool.ThreadPoolStats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public NodeStats(DiscoveryNode node, long timestamp, @Nullable NodeIndicesStats indices,
                 @Nullable OsStats os, @Nullable ProcessStats process, @Nullable JvmStats jvm, @Nullable ThreadPoolStats threadPool,
                 @Nullable FsInfo fs, @Nullable TransportStats transport, @Nullable HttpStats http,
                 @Nullable AllCircuitBreakerStats breaker,
                 @Nullable ScriptStats scriptStats) {
    super(node);
    this.timestamp = timestamp;
    this.indices = indices;
    this.os = os;
    this.process = process;
    this.jvm = jvm;
    this.threadPool = threadPool;
    this.fs = fs;
    this.transport = transport;
    this.http = http;
    this.breaker = breaker;
    this.scriptStats = scriptStats;
}
 
Example #2
Source File: ThreadPools.java    From crate with Apache License 2.0 6 votes vote down vote up
@Nullable
private ThreadPoolInfo getThreadPoolInfo(String name) {
    for (ThreadPoolStats.Stats stats : threadPool.stats()) {
        if (stats.getName().equals(name)) {
            return new ThreadPoolInfo(
                stats.getName(),
                stats.getThreads(),
                stats.getQueue(),
                stats.getLargest(),
                stats.getActive(),
                stats.getCompleted(),
                stats.getRejected());
        }
    }
    return null;
}
 
Example #3
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    timestamp = in.readVLong();
    if (in.readBoolean()) {
        indices = NodeIndicesStats.readIndicesStats(in);
    }
    if (in.readBoolean()) {
        os = OsStats.readOsStats(in);
    }
    if (in.readBoolean()) {
        process = ProcessStats.readProcessStats(in);
    }
    if (in.readBoolean()) {
        jvm = JvmStats.readJvmStats(in);
    }
    if (in.readBoolean()) {
        threadPool = ThreadPoolStats.readThreadPoolStats(in);
    }
    if (in.readBoolean()) {
        fs = FsInfo.readFsInfo(in);
    }
    if (in.readBoolean()) {
        transport = TransportStats.readTransportStats(in);
    }
    if (in.readBoolean()) {
        http = HttpStats.readHttpStats(in);
    }
    breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in);
    scriptStats = in.readOptionalStreamable(new ScriptStats());

}
 
Example #4
Source File: PrometheusMetricsCollector.java    From elasticsearch-prometheus-exporter with Apache License 2.0 5 votes vote down vote up
private void updateThreadPoolMetrics(ThreadPoolStats tps) {
    if (tps != null) {
        for (ThreadPoolStats.Stats st : tps) {
            String name = st.getName();
            catalog.setNodeGauge("threadpool_threads_number", st.getThreads(), name, "threads");
            catalog.setNodeGauge("threadpool_threads_number", st.getActive(), name, "active");
            catalog.setNodeGauge("threadpool_threads_number", st.getLargest(), name, "largest");
            catalog.setNodeGauge("threadpool_threads_count", st.getCompleted(), name, "completed");
            catalog.setNodeGauge("threadpool_threads_count", st.getRejected(), name, "rejected");
            catalog.setNodeGauge("threadpool_tasks_number", st.getQueue(), name, "queue");
        }
    }
}
 
Example #5
Source File: GraphiteReporter.java    From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License 5 votes vote down vote up
private void sendNodeThreadPoolStats(ThreadPoolStats threadPoolStats) {
    String type = buildMetricName("node.threadpool");
    Iterator<ThreadPoolStats.Stats> statsIterator = threadPoolStats.iterator();
    while (statsIterator.hasNext()) {
        ThreadPoolStats.Stats stats = statsIterator.next();
        String id = type + "." + stats.getName();

        sendInt(id, "threads", stats.getThreads());
        sendInt(id, "queue", stats.getQueue());
        sendInt(id, "active", stats.getActive());
        sendInt(id, "rejected", stats.getRejected());
        sendInt(id, "largest", stats.getLargest());
        sendInt(id, "completed", stats.getCompleted());
    }
}
 
Example #6
Source File: NodeStatsContext.java    From crate with Apache License 2.0 5 votes vote down vote up
public NodeStatsContext(StreamInput in, boolean complete) throws IOException {
    this.complete = complete;
    this.id = DataTypes.STRING.readValueFrom(in);
    this.name = DataTypes.STRING.readValueFrom(in);
    this.hostname = DataTypes.STRING.readValueFrom(in);
    this.timestamp = in.readLong();
    this.version = in.readBoolean() ? Version.readVersion(in) : null;
    this.build = in.readBoolean() ? Build.readBuild(in) : null;
    this.restUrl = DataTypes.STRING.readValueFrom(in);
    this.pgPort = in.readOptionalVInt();
    this.httpPort = in.readOptionalVInt();
    this.transportPort = in.readOptionalVInt();
    this.jvmStats = in.readOptionalWriteable(JvmStats::new);
    this.osInfo = in.readOptionalWriteable(OsInfo::new);
    this.processStats = in.readOptionalWriteable(ProcessStats::new);
    this.osStats = in.readOptionalWriteable(OsStats::new);
    this.fsInfo = in.readOptionalWriteable(FsInfo::new);
    this.extendedOsStats = in.readOptionalWriteable(ExtendedOsStats::new);
    this.threadPools = in.readOptionalWriteable(ThreadPoolStats::new);
    this.httpStats = in.readOptionalWriteable(HttpStats::new);
    this.psqlStats = in.readOptionalWriteable(ConnectionStats::new);
    this.openTransportConnections = in.readLong();
    this.clusterStateVersion = in.readLong();

    this.osName = DataTypes.STRING.readValueFrom(in);
    this.osArch = DataTypes.STRING.readValueFrom(in);
    this.osVersion = DataTypes.STRING.readValueFrom(in);
    this.javaVersion = DataTypes.STRING.readValueFrom(in);
    this.jvmName = DataTypes.STRING.readValueFrom(in);
    this.jvmVendor = DataTypes.STRING.readValueFrom(in);
    this.jvmVersion = DataTypes.STRING.readValueFrom(in);
}
 
Example #7
Source File: RestThreadPoolAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
    boolean fullId = req.paramAsBoolean("full_id", false);
    DiscoveryNodes nodes = state.getState().nodes();
    Table table = getTableWithHeader(req);

    for (DiscoveryNode node : nodes) {
        NodeInfo info = nodesInfo.getNodesMap().get(node.id());
        NodeStats stats = nodesStats.getNodesMap().get(node.id());
        table.startRow();

        table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
        table.addCell(info == null ? null : info.getProcess().getId());
        table.addCell(node.getHostName());
        table.addCell(node.getHostAddress());
        if (node.address() instanceof InetSocketTransportAddress) {
            table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
        } else {
            table.addCell("-");
        }

        final Map<String, ThreadPoolStats.Stats> poolThreadStats;
        final Map<String, ThreadPool.Info> poolThreadInfo;

        if (stats == null) {
            poolThreadStats = Collections.emptyMap();
            poolThreadInfo = Collections.emptyMap();
        } else {
            poolThreadStats = new HashMap<>(14);
            poolThreadInfo = new HashMap<>(14);

            ThreadPoolStats threadPoolStats = stats.getThreadPool();
            for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) {
                poolThreadStats.put(threadPoolStat.getName(), threadPoolStat);
            }
            if (info != null) {
                for (ThreadPool.Info threadPoolInfo : info.getThreadPool()) {
                    poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo);
                }
            }
        }
        for (String pool : SUPPORTED_NAMES) {
            ThreadPoolStats.Stats poolStats = poolThreadStats.get(pool);
            ThreadPool.Info poolInfo = poolThreadInfo.get(pool);

            Long maxQueueSize = null;
            String keepAlive = null;
            Integer minThreads = null;
            Integer maxThreads = null;

            if (poolInfo != null) {
                if (poolInfo.getQueueSize() != null) {
                    maxQueueSize = poolInfo.getQueueSize().singles();
                }
                if (poolInfo.getKeepAlive() != null) {
                    keepAlive = poolInfo.getKeepAlive().toString();
                }
                if (poolInfo.getMin() >= 0) {
                    minThreads = poolInfo.getMin();
                }
                if (poolInfo.getMax() >= 0) {
                    maxThreads = poolInfo.getMax();
                }
            }

            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);
            table.addCell(poolStats == null ? null : poolStats.getRejected());
            table.addCell(poolStats == null ? null : poolStats.getLargest());
            table.addCell(poolStats == null ? null : poolStats.getCompleted());
            table.addCell(minThreads);
            table.addCell(maxThreads);
            table.addCell(keepAlive);
        }

        table.endRow();
    }

    return table;
}
 
Example #8
Source File: NodeStats.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Thread Pool level statistics.
 */
@Nullable
public ThreadPoolStats getThreadPool() {
    return this.threadPool;
}
 
Example #9
Source File: EsQuery.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
private SearchRequestBuilder buildSearchRequest (EsQueryDo esQueryObj) throws  EsException {
    if (Check.NuNStrStrict(esClientFactory.getIndexs(esQueryObj.getIndexName()))) {
        throw new EsException("没有指定要搜索的索引名称(indexName)");
    }
    for (ThreadPoolStats.Stats stats : esClientFactory.getClient().threadPool().stats()) {
        logger.info(JSON.toJSONString(stats));
    }
    //加载要搜索索引
    SearchRequestBuilder searchRequestBuilder = esClientFactory.getClient().prepareSearch(esClientFactory.getIndexs(esQueryObj.getIndexName()));
    //由spring从配置加载要搜索的index的类型
    searchRequestBuilder.setTypes(esQueryObj.getTypeName());
    //由spring从配置加载要搜索的类型
    searchRequestBuilder.setSearchType(SearchType.fromId(esQueryObj.getSearchType()));
    //查询可以为null
    searchRequestBuilder.setQuery(esQueryObj.getQueryBuilder());

    if (!Check.NuNCollection(esQueryObj.getSortBuilders())) {
        for (SortBuilder sortBuilder : esQueryObj.getSortBuilders()) {
            searchRequestBuilder.addSort(sortBuilder);
        }
    }
    if (!Check.NuNCollection(esQueryObj.getAggregationBuilders())) {
        for (AbstractAggregationBuilder aggregationBuilder : esQueryObj.getAggregationBuilders()) {
            searchRequestBuilder.addAggregation(aggregationBuilder);
        }

    }
    //设置高亮域
   if (esQueryObj.isHighLigth()) {
        if (!Check.NuNObject(esQueryObj.highLigthFields())) {
            for (String hlFieldName : esQueryObj.highLigthFields()) {
                searchRequestBuilder.addHighlightedField(hlFieldName).setHighlighterPreTags(esQueryObj.getHighLigthPreTag())
                        .setHighlighterPostTags(esQueryObj.getHighLigthPostTag());
            }
        }
    }
    //分页
    searchRequestBuilder.setFrom(esQueryObj.getFromIndex()).setSize(esQueryObj.getSize());
    searchRequestBuilder.setExplain(esQueryObj.isExplain());
    return searchRequestBuilder;
}
 
Example #10
Source File: ThreadPoolStatsMonitor.java    From Raigad with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws Exception {
    // If Elasticsearch is started then only start the monitoring
    if (!ElasticsearchProcessMonitor.isElasticsearchRunning()) {
        String exceptionMsg = "Elasticsearch is not yet started, check back again later";
        logger.info(exceptionMsg);
        return;
    }

    ThreadPoolStatsBean threadPoolStatsBean = new ThreadPoolStatsBean();

    try {
        NodesStatsResponse nodesStatsResponse = ElasticsearchTransportClient.getNodesStatsResponse(config);
        NodeStats nodeStats = null;

        List<NodeStats> nodeStatsList = nodesStatsResponse.getNodes();

        if (nodeStatsList.size() > 0) {
            nodeStats = nodeStatsList.get(0);
        }

        if (nodeStats == null) {
            logger.info("Thread pool stats are not available (node stats is not available)");
            return;
        }

        ThreadPoolStats threadPoolStats = nodeStats.getThreadPool();

        if (threadPoolStats == null) {
            logger.info("Thread pool stats are not available");
            return;
        }

        Iterator<ThreadPoolStats.Stats> threadPoolStatsIterator = threadPoolStats.iterator();

        while (threadPoolStatsIterator.hasNext()) {
            ThreadPoolStats.Stats stat = threadPoolStatsIterator.next();
            if (stat.getName().equals("index")) {
                threadPoolStatsBean.indexThreads = stat.getThreads();
                threadPoolStatsBean.indexQueue = stat.getQueue();
                threadPoolStatsBean.indexActive = stat.getActive();
                threadPoolStatsBean.indexRejected = stat.getRejected();
                threadPoolStatsBean.indexLargest = stat.getLargest();
                threadPoolStatsBean.indexCompleted = stat.getCompleted();
            } else if (stat.getName().equals("get")) {
                threadPoolStatsBean.getThreads = stat.getThreads();
                threadPoolStatsBean.getQueue = stat.getQueue();
                threadPoolStatsBean.getActive = stat.getActive();
                threadPoolStatsBean.getRejected = stat.getRejected();
                threadPoolStatsBean.getLargest = stat.getLargest();
                threadPoolStatsBean.getCompleted = stat.getCompleted();
            } else if (stat.getName().equals("search")) {
                threadPoolStatsBean.searchThreads = stat.getThreads();
                threadPoolStatsBean.searchQueue = stat.getQueue();
                threadPoolStatsBean.searchActive = stat.getActive();
                threadPoolStatsBean.searchRejected = stat.getRejected();
                threadPoolStatsBean.searchLargest = stat.getLargest();
                threadPoolStatsBean.searchCompleted = stat.getCompleted();
            } else if (stat.getName().equals("bulk")) {
                threadPoolStatsBean.bulkThreads = stat.getThreads();
                threadPoolStatsBean.bulkQueue = stat.getQueue();
                threadPoolStatsBean.bulkActive = stat.getActive();
                threadPoolStatsBean.bulkRejected = stat.getRejected();
                threadPoolStatsBean.bulkLargest = stat.getLargest();
                threadPoolStatsBean.bulkCompleted = stat.getCompleted();
            }
        }
    } catch (Exception e) {
        logger.warn("Failed to load thread pool stats data", e);
    }

    tpStatsReporter.threadPoolBean.set(threadPoolStatsBean);
}
 
Example #11
Source File: NodeStatsContext.java    From crate with Apache License 2.0 4 votes vote down vote up
public ThreadPoolStats threadPools() {
    return threadPools;
}