Search in sources :

Example 1 with ThreadPoolStats

use of org.elasticsearch.threadpool.ThreadPoolStats in project elasticsearch by elastic.

the class NodeStatsTests method createNodeStats.

private static NodeStats createNodeStats() {
    DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
    OsStats osStats = null;
    if (frequently()) {
        double[] loadAverages = new double[3];
        for (int i = 0; i < 3; i++) {
            loadAverages[i] = randomBoolean() ? randomDouble() : -1;
        }
        osStats = new OsStats(System.currentTimeMillis(), new OsStats.Cpu(randomShort(), loadAverages), new OsStats.Mem(randomLong(), randomLong()), new OsStats.Swap(randomLong(), randomLong()), new OsStats.Cgroup(randomAsciiOfLength(8), randomNonNegativeLong(), randomAsciiOfLength(8), randomNonNegativeLong(), randomNonNegativeLong(), new OsStats.Cgroup.CpuStat(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong())));
    }
    ProcessStats processStats = frequently() ? new ProcessStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), new ProcessStats.Cpu(randomShort(), randomNonNegativeLong()), new ProcessStats.Mem(randomNonNegativeLong())) : null;
    JvmStats jvmStats = null;
    if (frequently()) {
        int numMemoryPools = randomIntBetween(0, 10);
        List<JvmStats.MemoryPool> memoryPools = new ArrayList<>(numMemoryPools);
        for (int i = 0; i < numMemoryPools; i++) {
            memoryPools.add(new JvmStats.MemoryPool(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
        }
        JvmStats.Threads threads = new JvmStats.Threads(randomIntBetween(1, 1000), randomIntBetween(1, 1000));
        int numGarbageCollectors = randomIntBetween(0, 10);
        JvmStats.GarbageCollector[] garbageCollectorsArray = new JvmStats.GarbageCollector[numGarbageCollectors];
        for (int i = 0; i < numGarbageCollectors; i++) {
            garbageCollectorsArray[i] = new JvmStats.GarbageCollector(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong());
        }
        JvmStats.GarbageCollectors garbageCollectors = new JvmStats.GarbageCollectors(garbageCollectorsArray);
        int numBufferPools = randomIntBetween(0, 10);
        List<JvmStats.BufferPool> bufferPoolList = new ArrayList<>();
        for (int i = 0; i < numBufferPools; i++) {
            bufferPoolList.add(new JvmStats.BufferPool(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
        }
        JvmStats.Classes classes = new JvmStats.Classes(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        jvmStats = frequently() ? new JvmStats(randomNonNegativeLong(), randomNonNegativeLong(), new JvmStats.Mem(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), memoryPools), threads, garbageCollectors, randomBoolean() ? Collections.emptyList() : bufferPoolList, classes) : null;
    }
    ThreadPoolStats threadPoolStats = null;
    if (frequently()) {
        int numThreadPoolStats = randomIntBetween(0, 10);
        List<ThreadPoolStats.Stats> threadPoolStatsList = new ArrayList<>();
        for (int i = 0; i < numThreadPoolStats; i++) {
            threadPoolStatsList.add(new ThreadPoolStats.Stats(randomAsciiOfLengthBetween(3, 10), randomIntBetween(1, 1000), randomIntBetween(1, 1000), randomIntBetween(1, 1000), randomNonNegativeLong(), randomIntBetween(1, 1000), randomIntBetween(1, 1000)));
        }
        threadPoolStats = new ThreadPoolStats(threadPoolStatsList);
    }
    FsInfo fsInfo = null;
    if (frequently()) {
        int numDeviceStats = randomIntBetween(0, 10);
        FsInfo.DeviceStats[] deviceStatsArray = new FsInfo.DeviceStats[numDeviceStats];
        for (int i = 0; i < numDeviceStats; i++) {
            FsInfo.DeviceStats previousDeviceStats = randomBoolean() ? null : new FsInfo.DeviceStats(randomInt(), randomInt(), randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), null);
            deviceStatsArray[i] = new FsInfo.DeviceStats(randomInt(), randomInt(), randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), previousDeviceStats);
        }
        FsInfo.IoStats ioStats = new FsInfo.IoStats(deviceStatsArray);
        int numPaths = randomIntBetween(0, 10);
        FsInfo.Path[] paths = new FsInfo.Path[numPaths];
        for (int i = 0; i < numPaths; i++) {
            paths[i] = new FsInfo.Path(randomAsciiOfLengthBetween(3, 10), randomBoolean() ? randomAsciiOfLengthBetween(3, 10) : null, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        }
        fsInfo = new FsInfo(randomNonNegativeLong(), ioStats, paths);
    }
    TransportStats transportStats = frequently() ? new TransportStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null;
    HttpStats httpStats = frequently() ? new HttpStats(randomNonNegativeLong(), randomNonNegativeLong()) : null;
    AllCircuitBreakerStats allCircuitBreakerStats = null;
    if (frequently()) {
        int numCircuitBreakerStats = randomIntBetween(0, 10);
        CircuitBreakerStats[] circuitBreakerStatsArray = new CircuitBreakerStats[numCircuitBreakerStats];
        for (int i = 0; i < numCircuitBreakerStats; i++) {
            circuitBreakerStatsArray[i] = new CircuitBreakerStats(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomDouble(), randomNonNegativeLong());
        }
        allCircuitBreakerStats = new AllCircuitBreakerStats(circuitBreakerStatsArray);
    }
    ScriptStats scriptStats = frequently() ? new ScriptStats(randomNonNegativeLong(), randomNonNegativeLong()) : null;
    DiscoveryStats discoveryStats = frequently() ? new DiscoveryStats(randomBoolean() ? new PendingClusterStateStats(randomInt(), randomInt(), randomInt()) : null) : null;
    IngestStats ingestStats = null;
    if (frequently()) {
        IngestStats.Stats totalStats = new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        int numStatsPerPipeline = randomIntBetween(0, 10);
        Map<String, IngestStats.Stats> statsPerPipeline = new HashMap<>();
        for (int i = 0; i < numStatsPerPipeline; i++) {
            statsPerPipeline.put(randomAsciiOfLengthBetween(3, 10), new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
        }
        ingestStats = new IngestStats(totalStats, statsPerPipeline);
    }
    //TODO NodeIndicesStats are not tested here, way too complicated to create, also they need to be migrated to Writeable yet
    return new NodeStats(node, randomNonNegativeLong(), null, osStats, processStats, jvmStats, threadPoolStats, fsInfo, transportStats, httpStats, allCircuitBreakerStats, scriptStats, discoveryStats, ingestStats);
}
Also used : HashMap(java.util.HashMap) DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) ArrayList(java.util.ArrayList) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) TransportStats(org.elasticsearch.transport.TransportStats) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats) ScriptStats(org.elasticsearch.script.ScriptStats) PendingClusterStateStats(org.elasticsearch.discovery.zen.PendingClusterStateStats) IngestStats(org.elasticsearch.ingest.IngestStats) PendingClusterStateStats(org.elasticsearch.discovery.zen.PendingClusterStateStats) IngestStats(org.elasticsearch.ingest.IngestStats) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) HttpStats(org.elasticsearch.http.HttpStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) ScriptStats(org.elasticsearch.script.ScriptStats) OsStats(org.elasticsearch.monitor.os.OsStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) TransportStats(org.elasticsearch.transport.TransportStats) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) FsInfo(org.elasticsearch.monitor.fs.FsInfo) HttpStats(org.elasticsearch.http.HttpStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) OsStats(org.elasticsearch.monitor.os.OsStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats)

Example 2 with ThreadPoolStats

use of org.elasticsearch.threadpool.ThreadPoolStats in project elasticsearch by elastic.

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.getThreadPool()) {
                    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.getProcess().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 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(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(minThreads);
            table.addCell(maxThreads);
            table.addCell(keepAlive);
            table.endRow();
        }
    }
    return table;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Table(org.elasticsearch.common.Table) ThreadPool(org.elasticsearch.threadpool.ThreadPool) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 ThreadPoolStats (org.elasticsearch.threadpool.ThreadPoolStats)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 Table (org.elasticsearch.common.Table)1 DiscoveryStats (org.elasticsearch.discovery.DiscoveryStats)1 PendingClusterStateStats (org.elasticsearch.discovery.zen.PendingClusterStateStats)1 HttpStats (org.elasticsearch.http.HttpStats)1 AllCircuitBreakerStats (org.elasticsearch.indices.breaker.AllCircuitBreakerStats)1 CircuitBreakerStats (org.elasticsearch.indices.breaker.CircuitBreakerStats)1 IngestStats (org.elasticsearch.ingest.IngestStats)1 FsInfo (org.elasticsearch.monitor.fs.FsInfo)1 JvmStats (org.elasticsearch.monitor.jvm.JvmStats)1 OsStats (org.elasticsearch.monitor.os.OsStats)1