Search in sources :

Example 1 with JvmStats

use of org.opensearch.monitor.jvm.JvmStats in project OpenSearch by opensearch-project.

the class NodeStatsTests method createNodeStats.

public 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;
        }
        long memTotal = randomNonNegativeLong();
        long swapTotal = randomNonNegativeLong();
        osStats = new OsStats(System.currentTimeMillis(), new OsStats.Cpu(randomShort(), loadAverages), new OsStats.Mem(memTotal, randomLongBetween(0, memTotal)), new OsStats.Swap(swapTotal, randomLongBetween(0, swapTotal)), new OsStats.Cgroup(randomAlphaOfLength(8), randomNonNegativeLong(), randomAlphaOfLength(8), randomNonNegativeLong(), randomNonNegativeLong(), new OsStats.Cgroup.CpuStat(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()), randomAlphaOfLength(8), Long.toString(randomNonNegativeLong()), Long.toString(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(randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), new JvmStats.MemoryPoolGcStats(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(randomAlphaOfLengthBetween(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(randomAlphaOfLengthBetween(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(randomAlphaOfLengthBetween(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(), randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), null);
            deviceStatsArray[i] = new FsInfo.DeviceStats(randomInt(), randomInt(), randomAlphaOfLengthBetween(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(randomAlphaOfLengthBetween(3, 10), randomBoolean() ? randomAlphaOfLengthBetween(3, 10) : null, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        }
        fsInfo = new FsInfo(randomNonNegativeLong(), ioStats, paths);
    }
    TransportStats transportStats = frequently() ? new TransportStats(randomNonNegativeLong(), 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(randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomDouble(), randomNonNegativeLong());
        }
        allCircuitBreakerStats = new AllCircuitBreakerStats(circuitBreakerStatsArray);
    }
    ScriptStats scriptStats = frequently() ? new ScriptStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null;
    DiscoveryStats discoveryStats = frequently() ? new DiscoveryStats(randomBoolean() ? new PendingClusterStateStats(randomInt(), randomInt(), randomInt()) : null, randomBoolean() ? new PublishClusterStateStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null) : null;
    IngestStats ingestStats = null;
    if (frequently()) {
        IngestStats.Stats totalStats = new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        int numPipelines = randomIntBetween(0, 10);
        int numProcessors = randomIntBetween(0, 10);
        List<IngestStats.PipelineStat> ingestPipelineStats = new ArrayList<>(numPipelines);
        Map<String, List<IngestStats.ProcessorStat>> ingestProcessorStats = new HashMap<>(numPipelines);
        for (int i = 0; i < numPipelines; i++) {
            String pipelineId = randomAlphaOfLengthBetween(3, 10);
            ingestPipelineStats.add(new IngestStats.PipelineStat(pipelineId, new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong())));
            List<IngestStats.ProcessorStat> processorPerPipeline = new ArrayList<>(numProcessors);
            for (int j = 0; j < numProcessors; j++) {
                IngestStats.Stats processorStats = new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
                processorPerPipeline.add(new IngestStats.ProcessorStat(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), processorStats));
            }
            ingestProcessorStats.put(pipelineId, processorPerPipeline);
        }
        ingestStats = new IngestStats(totalStats, ingestPipelineStats, ingestProcessorStats);
    }
    AdaptiveSelectionStats adaptiveSelectionStats = null;
    if (frequently()) {
        int numNodes = randomIntBetween(0, 10);
        Map<String, Long> nodeConnections = new HashMap<>();
        Map<String, ResponseCollectorService.ComputedNodeStats> nodeStats = new HashMap<>();
        for (int i = 0; i < numNodes; i++) {
            String nodeId = randomAlphaOfLengthBetween(3, 10);
            // add outgoing connection info
            if (frequently()) {
                nodeConnections.put(nodeId, randomLongBetween(0, 100));
            }
            // add node calculations
            if (frequently()) {
                ResponseCollectorService.ComputedNodeStats stats = new ResponseCollectorService.ComputedNodeStats(nodeId, randomIntBetween(1, 10), randomIntBetween(0, 2000), randomDoubleBetween(1.0, 10000000.0, true), randomDoubleBetween(1.0, 10000000.0, true));
                nodeStats.put(nodeId, stats);
            }
        }
        adaptiveSelectionStats = new AdaptiveSelectionStats(nodeConnections, nodeStats);
    }
    ScriptCacheStats scriptCacheStats = scriptStats != null ? scriptStats.toScriptCacheStats() : null;
    // 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, adaptiveSelectionStats, scriptCacheStats, null, null);
}
Also used : HashMap(java.util.HashMap) DiscoveryStats(org.opensearch.discovery.DiscoveryStats) ArrayList(java.util.ArrayList) ResponseCollectorService(org.opensearch.node.ResponseCollectorService) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) TransportStats(org.opensearch.transport.TransportStats) CircuitBreakerStats(org.opensearch.indices.breaker.CircuitBreakerStats) AllCircuitBreakerStats(org.opensearch.indices.breaker.AllCircuitBreakerStats) ArrayList(java.util.ArrayList) List(java.util.List) ScriptStats(org.opensearch.script.ScriptStats) PublishClusterStateStats(org.opensearch.cluster.coordination.PublishClusterStateStats) PendingClusterStateStats(org.opensearch.cluster.coordination.PendingClusterStateStats) AdaptiveSelectionStats(org.opensearch.node.AdaptiveSelectionStats) IngestStats(org.opensearch.ingest.IngestStats) IngestStats(org.opensearch.ingest.IngestStats) PendingClusterStateStats(org.opensearch.cluster.coordination.PendingClusterStateStats) CircuitBreakerStats(org.opensearch.indices.breaker.CircuitBreakerStats) OsStats(org.opensearch.monitor.os.OsStats) ScriptCacheStats(org.opensearch.script.ScriptCacheStats) DiscoveryStats(org.opensearch.discovery.DiscoveryStats) AllCircuitBreakerStats(org.opensearch.indices.breaker.AllCircuitBreakerStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) HttpStats(org.opensearch.http.HttpStats) TransportStats(org.opensearch.transport.TransportStats) ScriptStats(org.opensearch.script.ScriptStats) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) AdaptiveSelectionStats(org.opensearch.node.AdaptiveSelectionStats) PublishClusterStateStats(org.opensearch.cluster.coordination.PublishClusterStateStats) ProcessStats(org.opensearch.monitor.process.ProcessStats) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) FsInfo(org.opensearch.monitor.fs.FsInfo) HttpStats(org.opensearch.http.HttpStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) ProcessStats(org.opensearch.monitor.process.ProcessStats) OsStats(org.opensearch.monitor.os.OsStats) ScriptCacheStats(org.opensearch.script.ScriptCacheStats) AllCircuitBreakerStats(org.opensearch.indices.breaker.AllCircuitBreakerStats)

Example 2 with JvmStats

use of org.opensearch.monitor.jvm.JvmStats in project fess by codelibs.

the class SystemMonitorTarget method appendJvmStats.

private void appendJvmStats(final StringBuilder buf) {
    buf.append("\"jvm\":{");
    final JvmStats jvmStats = JvmStats.jvmStats();
    final Mem mem = jvmStats.getMem();
    buf.append("\"memory\":{");
    buf.append("\"heap\":{");
    append(buf, "used", () -> mem.getHeapUsed().getBytes()).append(',');
    append(buf, "committed", () -> mem.getHeapCommitted().getBytes()).append(',');
    append(buf, "max", () -> mem.getHeapMax().getBytes()).append(',');
    append(buf, "percent", () -> mem.getHeapUsedPercent());
    buf.append("},");
    buf.append("\"non_heap\":{");
    append(buf, "used", () -> mem.getNonHeapUsed().getBytes()).append(',');
    append(buf, "committed", () -> mem.getNonHeapCommitted().getBytes());
    buf.append('}');
    buf.append("},");
    final List<BufferPool> bufferPools = jvmStats.getBufferPools();
    buf.append("\"pools\":{");
    buf.append(bufferPools.stream().map(p -> {
        final StringBuilder b = new StringBuilder();
        b.append('"').append(StringEscapeUtils.escapeJson(p.getName())).append("\":{");
        append(b, "count", () -> p.getCount()).append(',');
        append(b, "used", () -> p.getUsed().getBytes()).append(',');
        append(b, "capacity", () -> p.getTotalCapacity().getBytes()).append('}');
        return b.toString();
    }).collect(Collectors.joining(",")));
    buf.append("},");
    final GarbageCollectors gc = jvmStats.getGc();
    buf.append("\"gc\":{");
    buf.append(Arrays.stream(gc.getCollectors()).map(c -> {
        final StringBuilder b = new StringBuilder();
        b.append('"').append(StringEscapeUtils.escapeJson(c.getName())).append("\":{");
        append(b, "count", () -> c.getCollectionCount()).append(',');
        append(b, "time", () -> c.getCollectionTime().getMillis()).append('}');
        return b.toString();
    }).collect(Collectors.joining(",")));
    buf.append("},");
    final Threads threads = jvmStats.getThreads();
    buf.append("\"threads\":{");
    append(buf, "count", () -> threads.getCount()).append(',');
    append(buf, "peak", () -> threads.getPeakCount());
    buf.append("},");
    final Classes classes = jvmStats.getClasses();
    buf.append("\"classes\":{");
    append(buf, "loaded", () -> classes.getLoadedClassCount()).append(',');
    append(buf, "total_loaded", () -> classes.getTotalLoadedClassCount()).append(',');
    append(buf, "unloaded", () -> classes.getUnloadedClassCount());
    buf.append("},");
    append(buf, "uptime", () -> jvmStats.getUptime().getMillis());
    buf.append("},");
}
Also used : JvmStats(org.opensearch.monitor.jvm.JvmStats) Threads(org.opensearch.monitor.jvm.JvmStats.Threads) BufferPool(org.opensearch.monitor.jvm.JvmStats.BufferPool) Mem(org.opensearch.monitor.jvm.JvmStats.Mem) GarbageCollectors(org.opensearch.monitor.jvm.JvmStats.GarbageCollectors) Classes(org.opensearch.monitor.jvm.JvmStats.Classes)

Example 3 with JvmStats

use of org.opensearch.monitor.jvm.JvmStats in project OpenSearch by opensearch-project.

the class RestNodesAction method buildTable.

Table buildTable(boolean fullId, RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
    DiscoveryNodes nodes = state.getState().nodes();
    String masterId = nodes.getMasterNodeId();
    Table table = getTableWithHeader(req);
    for (DiscoveryNode node : nodes) {
        NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
        NodeStats stats = nodesStats.getNodesMap().get(node.getId());
        JvmInfo jvmInfo = info == null ? null : info.getInfo(JvmInfo.class);
        JvmStats jvmStats = stats == null ? null : stats.getJvm();
        FsInfo fsInfo = stats == null ? null : stats.getFs();
        OsStats osStats = stats == null ? null : stats.getOs();
        ProcessStats processStats = stats == null ? null : stats.getProcess();
        NodeIndicesStats indicesStats = stats == null ? null : stats.getIndices();
        table.startRow();
        table.addCell(fullId ? node.getId() : Strings.substring(node.getId(), 0, 4));
        table.addCell(info == null ? null : info.getInfo(ProcessInfo.class).getId());
        table.addCell(node.getHostAddress());
        table.addCell(node.getAddress().address().getPort());
        final HttpInfo httpInfo = info == null ? null : info.getInfo(HttpInfo.class);
        if (httpInfo != null) {
            TransportAddress transportAddress = httpInfo.getAddress().publishAddress();
            table.addCell(NetworkAddress.format(transportAddress.address()));
        } else {
            table.addCell("-");
        }
        table.addCell(node.getVersion().toString());
        table.addCell(info == null ? null : info.getBuild().type().displayName());
        table.addCell(info == null ? null : info.getBuild().hash());
        table.addCell(jvmInfo == null ? null : jvmInfo.version());
        ByteSizeValue diskTotal = null;
        ByteSizeValue diskUsed = null;
        ByteSizeValue diskAvailable = null;
        String diskUsedPercent = null;
        if (fsInfo != null) {
            diskTotal = fsInfo.getTotal().getTotal();
            diskAvailable = fsInfo.getTotal().getAvailable();
            diskUsed = new ByteSizeValue(diskTotal.getBytes() - diskAvailable.getBytes());
            double diskUsedRatio = diskTotal.getBytes() == 0 ? 1.0 : (double) diskUsed.getBytes() / diskTotal.getBytes();
            diskUsedPercent = String.format(Locale.ROOT, "%.2f", 100.0 * diskUsedRatio);
        }
        table.addCell(diskTotal);
        table.addCell(diskUsed);
        table.addCell(diskAvailable);
        table.addCell(diskUsedPercent);
        table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed());
        table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsedPercent());
        table.addCell(jvmInfo == null ? null : jvmInfo.getMem().getHeapMax());
        table.addCell(osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsed());
        table.addCell(osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsedPercent());
        table.addCell(osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getTotal());
        table.addCell(processStats == null ? null : processStats.getOpenFileDescriptors());
        table.addCell(processStats == null ? null : calculatePercentage(processStats.getOpenFileDescriptors(), processStats.getMaxFileDescriptors()));
        table.addCell(processStats == null ? null : processStats.getMaxFileDescriptors());
        table.addCell(osStats == null ? null : Short.toString(osStats.getCpu().getPercent()));
        boolean hasLoadAverage = osStats != null && osStats.getCpu().getLoadAverage() != null;
        table.addCell(!hasLoadAverage || osStats.getCpu().getLoadAverage()[0] == -1 ? null : String.format(Locale.ROOT, "%.2f", osStats.getCpu().getLoadAverage()[0]));
        table.addCell(!hasLoadAverage || osStats.getCpu().getLoadAverage()[1] == -1 ? null : String.format(Locale.ROOT, "%.2f", osStats.getCpu().getLoadAverage()[1]));
        table.addCell(!hasLoadAverage || osStats.getCpu().getLoadAverage()[2] == -1 ? null : String.format(Locale.ROOT, "%.2f", osStats.getCpu().getLoadAverage()[2]));
        table.addCell(jvmStats == null ? null : jvmStats.getUptime());
        final String roles;
        if (node.getRoles().isEmpty()) {
            roles = "-";
        } else {
            roles = node.getRoles().stream().map(DiscoveryNodeRole::roleNameAbbreviation).sorted().collect(Collectors.joining());
        }
        table.addCell(roles);
        table.addCell(masterId == null ? "x" : masterId.equals(node.getId()) ? "*" : "-");
        table.addCell(node.getName());
        CompletionStats completionStats = indicesStats == null ? null : stats.getIndices().getCompletion();
        table.addCell(completionStats == null ? null : completionStats.getSize());
        FieldDataStats fdStats = indicesStats == null ? null : stats.getIndices().getFieldData();
        table.addCell(fdStats == null ? null : fdStats.getMemorySize());
        table.addCell(fdStats == null ? null : fdStats.getEvictions());
        QueryCacheStats fcStats = indicesStats == null ? null : indicesStats.getQueryCache();
        table.addCell(fcStats == null ? null : fcStats.getMemorySize());
        table.addCell(fcStats == null ? null : fcStats.getEvictions());
        table.addCell(fcStats == null ? null : fcStats.getHitCount());
        table.addCell(fcStats == null ? null : fcStats.getMissCount());
        RequestCacheStats qcStats = indicesStats == null ? null : indicesStats.getRequestCache();
        table.addCell(qcStats == null ? null : qcStats.getMemorySize());
        table.addCell(qcStats == null ? null : qcStats.getEvictions());
        table.addCell(qcStats == null ? null : qcStats.getHitCount());
        table.addCell(qcStats == null ? null : qcStats.getMissCount());
        FlushStats flushStats = indicesStats == null ? null : indicesStats.getFlush();
        table.addCell(flushStats == null ? null : flushStats.getTotal());
        table.addCell(flushStats == null ? null : flushStats.getTotalTime());
        GetStats getStats = indicesStats == null ? null : indicesStats.getGet();
        table.addCell(getStats == null ? null : getStats.current());
        table.addCell(getStats == null ? null : getStats.getTime());
        table.addCell(getStats == null ? null : getStats.getCount());
        table.addCell(getStats == null ? null : getStats.getExistsTime());
        table.addCell(getStats == null ? null : getStats.getExistsCount());
        table.addCell(getStats == null ? null : getStats.getMissingTime());
        table.addCell(getStats == null ? null : getStats.getMissingCount());
        IndexingStats indexingStats = indicesStats == null ? null : indicesStats.getIndexing();
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCurrent());
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteTime());
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCount());
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCurrent());
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexTime());
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCount());
        table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexFailedCount());
        MergeStats mergeStats = indicesStats == null ? null : indicesStats.getMerge();
        table.addCell(mergeStats == null ? null : mergeStats.getCurrent());
        table.addCell(mergeStats == null ? null : mergeStats.getCurrentNumDocs());
        table.addCell(mergeStats == null ? null : mergeStats.getCurrentSize());
        table.addCell(mergeStats == null ? null : mergeStats.getTotal());
        table.addCell(mergeStats == null ? null : mergeStats.getTotalNumDocs());
        table.addCell(mergeStats == null ? null : mergeStats.getTotalSize());
        table.addCell(mergeStats == null ? null : mergeStats.getTotalTime());
        RefreshStats refreshStats = indicesStats == null ? null : indicesStats.getRefresh();
        table.addCell(refreshStats == null ? null : refreshStats.getTotal());
        table.addCell(refreshStats == null ? null : refreshStats.getTotalTime());
        table.addCell(refreshStats == null ? null : refreshStats.getExternalTotal());
        table.addCell(refreshStats == null ? null : refreshStats.getExternalTotalTime());
        table.addCell(refreshStats == null ? null : refreshStats.getListeners());
        ScriptStats scriptStats = stats == null ? null : stats.getScriptStats();
        table.addCell(scriptStats == null ? null : scriptStats.getCompilations());
        table.addCell(scriptStats == null ? null : scriptStats.getCacheEvictions());
        table.addCell(scriptStats == null ? null : scriptStats.getCompilationLimitTriggered());
        SearchStats searchStats = indicesStats == null ? null : indicesStats.getSearch();
        table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCurrent());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchTime());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCount());
        table.addCell(searchStats == null ? null : searchStats.getOpenContexts());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCurrent());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryTime());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCount());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCurrent());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollTime());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCount());
        SegmentsStats segmentsStats = indicesStats == null ? null : indicesStats.getSegments();
        table.addCell(segmentsStats == null ? null : segmentsStats.getCount());
        table.addCell(segmentsStats == null ? null : segmentsStats.getZeroMemory());
        table.addCell(segmentsStats == null ? null : segmentsStats.getIndexWriterMemory());
        table.addCell(segmentsStats == null ? null : segmentsStats.getVersionMapMemory());
        table.addCell(segmentsStats == null ? null : segmentsStats.getBitsetMemory());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getSuggestCurrent());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getSuggestTime());
        table.addCell(searchStats == null ? null : searchStats.getTotal().getSuggestCount());
        table.endRow();
    }
    return table;
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) RefreshStats(org.opensearch.index.refresh.RefreshStats) TransportAddress(org.opensearch.common.transport.TransportAddress) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) GetStats(org.opensearch.index.get.GetStats) SegmentsStats(org.opensearch.index.engine.SegmentsStats) HttpInfo(org.opensearch.http.HttpInfo) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) FsInfo(org.opensearch.monitor.fs.FsInfo) FlushStats(org.opensearch.index.flush.FlushStats) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) ScriptStats(org.opensearch.script.ScriptStats) ProcessStats(org.opensearch.monitor.process.ProcessStats) Table(org.opensearch.common.Table) IndexingStats(org.opensearch.index.shard.IndexingStats) OsStats(org.opensearch.monitor.os.OsStats) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) SearchStats(org.opensearch.index.search.stats.SearchStats) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) MergeStats(org.opensearch.index.merge.MergeStats) NodeIndicesStats(org.opensearch.indices.NodeIndicesStats) RequestCacheStats(org.opensearch.index.cache.request.RequestCacheStats) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats)

Example 4 with JvmStats

use of org.opensearch.monitor.jvm.JvmStats in project OpenSearch by opensearch-project.

the class NodeStatsTests method testSerialization.

public void testSerialization() throws IOException {
    NodeStats nodeStats = createNodeStats();
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        nodeStats.writeTo(out);
        try (StreamInput in = out.bytes().streamInput()) {
            NodeStats deserializedNodeStats = new NodeStats(in);
            assertEquals(nodeStats.getNode(), deserializedNodeStats.getNode());
            assertEquals(nodeStats.getTimestamp(), deserializedNodeStats.getTimestamp());
            if (nodeStats.getOs() == null) {
                assertNull(deserializedNodeStats.getOs());
            } else {
                assertEquals(nodeStats.getOs().getTimestamp(), deserializedNodeStats.getOs().getTimestamp());
                assertEquals(nodeStats.getOs().getSwap().getFree(), deserializedNodeStats.getOs().getSwap().getFree());
                assertEquals(nodeStats.getOs().getSwap().getTotal(), deserializedNodeStats.getOs().getSwap().getTotal());
                assertEquals(nodeStats.getOs().getSwap().getUsed(), deserializedNodeStats.getOs().getSwap().getUsed());
                assertEquals(nodeStats.getOs().getMem().getFree(), deserializedNodeStats.getOs().getMem().getFree());
                assertEquals(nodeStats.getOs().getMem().getTotal(), deserializedNodeStats.getOs().getMem().getTotal());
                assertEquals(nodeStats.getOs().getMem().getUsed(), deserializedNodeStats.getOs().getMem().getUsed());
                assertEquals(nodeStats.getOs().getMem().getFreePercent(), deserializedNodeStats.getOs().getMem().getFreePercent());
                assertEquals(nodeStats.getOs().getMem().getUsedPercent(), deserializedNodeStats.getOs().getMem().getUsedPercent());
                assertEquals(nodeStats.getOs().getCpu().getPercent(), deserializedNodeStats.getOs().getCpu().getPercent());
                assertEquals(nodeStats.getOs().getCgroup().getCpuAcctControlGroup(), deserializedNodeStats.getOs().getCgroup().getCpuAcctControlGroup());
                assertEquals(nodeStats.getOs().getCgroup().getCpuAcctUsageNanos(), deserializedNodeStats.getOs().getCgroup().getCpuAcctUsageNanos());
                assertEquals(nodeStats.getOs().getCgroup().getCpuControlGroup(), deserializedNodeStats.getOs().getCgroup().getCpuControlGroup());
                assertEquals(nodeStats.getOs().getCgroup().getCpuCfsPeriodMicros(), deserializedNodeStats.getOs().getCgroup().getCpuCfsPeriodMicros());
                assertEquals(nodeStats.getOs().getCgroup().getCpuCfsQuotaMicros(), deserializedNodeStats.getOs().getCgroup().getCpuCfsQuotaMicros());
                assertEquals(nodeStats.getOs().getCgroup().getCpuStat().getNumberOfElapsedPeriods(), deserializedNodeStats.getOs().getCgroup().getCpuStat().getNumberOfElapsedPeriods());
                assertEquals(nodeStats.getOs().getCgroup().getCpuStat().getNumberOfTimesThrottled(), deserializedNodeStats.getOs().getCgroup().getCpuStat().getNumberOfTimesThrottled());
                assertEquals(nodeStats.getOs().getCgroup().getCpuStat().getTimeThrottledNanos(), deserializedNodeStats.getOs().getCgroup().getCpuStat().getTimeThrottledNanos());
                assertEquals(nodeStats.getOs().getCgroup().getMemoryLimitInBytes(), deserializedNodeStats.getOs().getCgroup().getMemoryLimitInBytes());
                assertEquals(nodeStats.getOs().getCgroup().getMemoryUsageInBytes(), deserializedNodeStats.getOs().getCgroup().getMemoryUsageInBytes());
                assertArrayEquals(nodeStats.getOs().getCpu().getLoadAverage(), deserializedNodeStats.getOs().getCpu().getLoadAverage(), 0);
            }
            if (nodeStats.getProcess() == null) {
                assertNull(deserializedNodeStats.getProcess());
            } else {
                assertEquals(nodeStats.getProcess().getTimestamp(), deserializedNodeStats.getProcess().getTimestamp());
                assertEquals(nodeStats.getProcess().getCpu().getTotal(), deserializedNodeStats.getProcess().getCpu().getTotal());
                assertEquals(nodeStats.getProcess().getCpu().getPercent(), deserializedNodeStats.getProcess().getCpu().getPercent());
                assertEquals(nodeStats.getProcess().getMem().getTotalVirtual(), deserializedNodeStats.getProcess().getMem().getTotalVirtual());
                assertEquals(nodeStats.getProcess().getMaxFileDescriptors(), deserializedNodeStats.getProcess().getMaxFileDescriptors());
                assertEquals(nodeStats.getProcess().getOpenFileDescriptors(), deserializedNodeStats.getProcess().getOpenFileDescriptors());
            }
            JvmStats jvm = nodeStats.getJvm();
            JvmStats deserializedJvm = deserializedNodeStats.getJvm();
            if (jvm == null) {
                assertNull(deserializedJvm);
            } else {
                JvmStats.Mem mem = jvm.getMem();
                JvmStats.Mem deserializedMem = deserializedJvm.getMem();
                assertEquals(jvm.getTimestamp(), deserializedJvm.getTimestamp());
                assertEquals(mem.getHeapUsedPercent(), deserializedMem.getHeapUsedPercent());
                assertEquals(mem.getHeapUsed(), deserializedMem.getHeapUsed());
                assertEquals(mem.getHeapCommitted(), deserializedMem.getHeapCommitted());
                assertEquals(mem.getNonHeapCommitted(), deserializedMem.getNonHeapCommitted());
                assertEquals(mem.getNonHeapUsed(), deserializedMem.getNonHeapUsed());
                assertEquals(mem.getHeapMax(), deserializedMem.getHeapMax());
                final Map<String, JvmStats.MemoryPool> pools = StreamSupport.stream(mem.spliterator(), false).collect(Collectors.toMap(JvmStats.MemoryPool::getName, Function.identity()));
                final Map<String, JvmStats.MemoryPool> deserializedPools = StreamSupport.stream(deserializedMem.spliterator(), false).collect(Collectors.toMap(JvmStats.MemoryPool::getName, Function.identity()));
                final int poolsCount = (int) StreamSupport.stream(nodeStats.getJvm().getMem().spliterator(), false).count();
                assertThat(pools.keySet(), hasSize(poolsCount));
                assertThat(deserializedPools.keySet(), hasSize(poolsCount));
                for (final Map.Entry<String, JvmStats.MemoryPool> entry : pools.entrySet()) {
                    assertThat(deserializedPools.containsKey(entry.getKey()), is(true));
                    assertEquals(entry.getValue().getName(), deserializedPools.get(entry.getKey()).getName());
                    assertEquals(entry.getValue().getMax(), deserializedPools.get(entry.getKey()).getMax());
                    assertEquals(entry.getValue().getPeakMax(), deserializedPools.get(entry.getKey()).getPeakMax());
                    assertEquals(entry.getValue().getPeakUsed(), deserializedPools.get(entry.getKey()).getPeakUsed());
                    assertEquals(entry.getValue().getUsed(), deserializedPools.get(entry.getKey()).getUsed());
                    assertEquals(entry.getValue().getLastGcStats().getUsed(), deserializedPools.get(entry.getKey()).getLastGcStats().getUsed());
                    assertEquals(entry.getValue().getLastGcStats().getMax(), deserializedPools.get(entry.getKey()).getLastGcStats().getMax());
                    assertEquals(entry.getValue().getLastGcStats().getUsagePercent(), deserializedPools.get(entry.getKey()).getLastGcStats().getUsagePercent());
                }
                JvmStats.Classes classes = jvm.getClasses();
                assertEquals(classes.getLoadedClassCount(), deserializedJvm.getClasses().getLoadedClassCount());
                assertEquals(classes.getTotalLoadedClassCount(), deserializedJvm.getClasses().getTotalLoadedClassCount());
                assertEquals(classes.getUnloadedClassCount(), deserializedJvm.getClasses().getUnloadedClassCount());
                assertEquals(jvm.getGc().getCollectors().length, deserializedJvm.getGc().getCollectors().length);
                for (int i = 0; i < jvm.getGc().getCollectors().length; i++) {
                    JvmStats.GarbageCollector garbageCollector = jvm.getGc().getCollectors()[i];
                    JvmStats.GarbageCollector deserializedGarbageCollector = deserializedJvm.getGc().getCollectors()[i];
                    assertEquals(garbageCollector.getName(), deserializedGarbageCollector.getName());
                    assertEquals(garbageCollector.getCollectionCount(), deserializedGarbageCollector.getCollectionCount());
                    assertEquals(garbageCollector.getCollectionTime(), deserializedGarbageCollector.getCollectionTime());
                }
                assertEquals(jvm.getThreads().getCount(), deserializedJvm.getThreads().getCount());
                assertEquals(jvm.getThreads().getPeakCount(), deserializedJvm.getThreads().getPeakCount());
                assertEquals(jvm.getUptime(), deserializedJvm.getUptime());
                if (jvm.getBufferPools() == null) {
                    assertNull(deserializedJvm.getBufferPools());
                } else {
                    assertEquals(jvm.getBufferPools().size(), deserializedJvm.getBufferPools().size());
                    for (int i = 0; i < jvm.getBufferPools().size(); i++) {
                        JvmStats.BufferPool bufferPool = jvm.getBufferPools().get(i);
                        JvmStats.BufferPool deserializedBufferPool = deserializedJvm.getBufferPools().get(i);
                        assertEquals(bufferPool.getName(), deserializedBufferPool.getName());
                        assertEquals(bufferPool.getCount(), deserializedBufferPool.getCount());
                        assertEquals(bufferPool.getTotalCapacity(), deserializedBufferPool.getTotalCapacity());
                        assertEquals(bufferPool.getUsed(), deserializedBufferPool.getUsed());
                    }
                }
            }
            if (nodeStats.getThreadPool() == null) {
                assertNull(deserializedNodeStats.getThreadPool());
            } else {
                Iterator<ThreadPoolStats.Stats> threadPoolIterator = nodeStats.getThreadPool().iterator();
                Iterator<ThreadPoolStats.Stats> deserializedThreadPoolIterator = deserializedNodeStats.getThreadPool().iterator();
                while (threadPoolIterator.hasNext()) {
                    ThreadPoolStats.Stats stats = threadPoolIterator.next();
                    ThreadPoolStats.Stats deserializedStats = deserializedThreadPoolIterator.next();
                    assertEquals(stats.getName(), deserializedStats.getName());
                    assertEquals(stats.getThreads(), deserializedStats.getThreads());
                    assertEquals(stats.getActive(), deserializedStats.getActive());
                    assertEquals(stats.getLargest(), deserializedStats.getLargest());
                    assertEquals(stats.getCompleted(), deserializedStats.getCompleted());
                    assertEquals(stats.getQueue(), deserializedStats.getQueue());
                    assertEquals(stats.getRejected(), deserializedStats.getRejected());
                }
            }
            FsInfo fs = nodeStats.getFs();
            FsInfo deserializedFs = deserializedNodeStats.getFs();
            if (fs == null) {
                assertNull(deserializedFs);
            } else {
                assertEquals(fs.getTimestamp(), deserializedFs.getTimestamp());
                assertEquals(fs.getTotal().getAvailable(), deserializedFs.getTotal().getAvailable());
                assertEquals(fs.getTotal().getTotal(), deserializedFs.getTotal().getTotal());
                assertEquals(fs.getTotal().getFree(), deserializedFs.getTotal().getFree());
                assertEquals(fs.getTotal().getMount(), deserializedFs.getTotal().getMount());
                assertEquals(fs.getTotal().getPath(), deserializedFs.getTotal().getPath());
                assertEquals(fs.getTotal().getType(), deserializedFs.getTotal().getType());
                FsInfo.IoStats ioStats = fs.getIoStats();
                FsInfo.IoStats deserializedIoStats = deserializedFs.getIoStats();
                assertEquals(ioStats.getTotalOperations(), deserializedIoStats.getTotalOperations());
                assertEquals(ioStats.getTotalReadKilobytes(), deserializedIoStats.getTotalReadKilobytes());
                assertEquals(ioStats.getTotalReadOperations(), deserializedIoStats.getTotalReadOperations());
                assertEquals(ioStats.getTotalWriteKilobytes(), deserializedIoStats.getTotalWriteKilobytes());
                assertEquals(ioStats.getTotalWriteOperations(), deserializedIoStats.getTotalWriteOperations());
                assertEquals(ioStats.getDevicesStats().length, deserializedIoStats.getDevicesStats().length);
                for (int i = 0; i < ioStats.getDevicesStats().length; i++) {
                    FsInfo.DeviceStats deviceStats = ioStats.getDevicesStats()[i];
                    FsInfo.DeviceStats deserializedDeviceStats = deserializedIoStats.getDevicesStats()[i];
                    assertEquals(deviceStats.operations(), deserializedDeviceStats.operations());
                    assertEquals(deviceStats.readKilobytes(), deserializedDeviceStats.readKilobytes());
                    assertEquals(deviceStats.readOperations(), deserializedDeviceStats.readOperations());
                    assertEquals(deviceStats.writeKilobytes(), deserializedDeviceStats.writeKilobytes());
                    assertEquals(deviceStats.writeOperations(), deserializedDeviceStats.writeOperations());
                }
            }
            if (nodeStats.getTransport() == null) {
                assertNull(deserializedNodeStats.getTransport());
            } else {
                assertEquals(nodeStats.getTransport().getRxCount(), deserializedNodeStats.getTransport().getRxCount());
                assertEquals(nodeStats.getTransport().getRxSize(), deserializedNodeStats.getTransport().getRxSize());
                assertEquals(nodeStats.getTransport().getServerOpen(), deserializedNodeStats.getTransport().getServerOpen());
                assertEquals(nodeStats.getTransport().getTxCount(), deserializedNodeStats.getTransport().getTxCount());
                assertEquals(nodeStats.getTransport().getTxSize(), deserializedNodeStats.getTransport().getTxSize());
            }
            if (nodeStats.getHttp() == null) {
                assertNull(deserializedNodeStats.getHttp());
            } else {
                assertEquals(nodeStats.getHttp().getServerOpen(), deserializedNodeStats.getHttp().getServerOpen());
                assertEquals(nodeStats.getHttp().getTotalOpen(), deserializedNodeStats.getHttp().getTotalOpen());
            }
            if (nodeStats.getBreaker() == null) {
                assertNull(deserializedNodeStats.getBreaker());
            } else {
                assertEquals(nodeStats.getBreaker().getAllStats().length, deserializedNodeStats.getBreaker().getAllStats().length);
                for (int i = 0; i < nodeStats.getBreaker().getAllStats().length; i++) {
                    CircuitBreakerStats circuitBreakerStats = nodeStats.getBreaker().getAllStats()[i];
                    CircuitBreakerStats deserializedCircuitBreakerStats = deserializedNodeStats.getBreaker().getAllStats()[i];
                    assertEquals(circuitBreakerStats.getEstimated(), deserializedCircuitBreakerStats.getEstimated());
                    assertEquals(circuitBreakerStats.getLimit(), deserializedCircuitBreakerStats.getLimit());
                    assertEquals(circuitBreakerStats.getName(), deserializedCircuitBreakerStats.getName());
                    assertEquals(circuitBreakerStats.getOverhead(), deserializedCircuitBreakerStats.getOverhead(), 0);
                    assertEquals(circuitBreakerStats.getTrippedCount(), deserializedCircuitBreakerStats.getTrippedCount(), 0);
                }
            }
            ScriptStats scriptStats = nodeStats.getScriptStats();
            if (scriptStats == null) {
                assertNull(deserializedNodeStats.getScriptStats());
            } else {
                assertEquals(scriptStats.getCacheEvictions(), deserializedNodeStats.getScriptStats().getCacheEvictions());
                assertEquals(scriptStats.getCompilations(), deserializedNodeStats.getScriptStats().getCompilations());
            }
            DiscoveryStats discoveryStats = nodeStats.getDiscoveryStats();
            DiscoveryStats deserializedDiscoveryStats = deserializedNodeStats.getDiscoveryStats();
            if (discoveryStats == null) {
                assertNull(deserializedDiscoveryStats);
            } else {
                PendingClusterStateStats queueStats = discoveryStats.getQueueStats();
                if (queueStats == null) {
                    assertNull(deserializedDiscoveryStats.getQueueStats());
                } else {
                    assertEquals(queueStats.getCommitted(), deserializedDiscoveryStats.getQueueStats().getCommitted());
                    assertEquals(queueStats.getTotal(), deserializedDiscoveryStats.getQueueStats().getTotal());
                    assertEquals(queueStats.getPending(), deserializedDiscoveryStats.getQueueStats().getPending());
                }
            }
            IngestStats ingestStats = nodeStats.getIngestStats();
            IngestStats deserializedIngestStats = deserializedNodeStats.getIngestStats();
            if (ingestStats == null) {
                assertNull(deserializedIngestStats);
            } else {
                IngestStats.Stats totalStats = ingestStats.getTotalStats();
                assertEquals(totalStats.getIngestCount(), deserializedIngestStats.getTotalStats().getIngestCount());
                assertEquals(totalStats.getIngestCurrent(), deserializedIngestStats.getTotalStats().getIngestCurrent());
                assertEquals(totalStats.getIngestFailedCount(), deserializedIngestStats.getTotalStats().getIngestFailedCount());
                assertEquals(totalStats.getIngestTimeInMillis(), deserializedIngestStats.getTotalStats().getIngestTimeInMillis());
                assertEquals(ingestStats.getPipelineStats().size(), deserializedIngestStats.getPipelineStats().size());
                for (IngestStats.PipelineStat pipelineStat : ingestStats.getPipelineStats()) {
                    String pipelineId = pipelineStat.getPipelineId();
                    IngestStats.Stats deserializedPipelineStats = getPipelineStats(deserializedIngestStats.getPipelineStats(), pipelineId);
                    assertEquals(pipelineStat.getStats().getIngestFailedCount(), deserializedPipelineStats.getIngestFailedCount());
                    assertEquals(pipelineStat.getStats().getIngestTimeInMillis(), deserializedPipelineStats.getIngestTimeInMillis());
                    assertEquals(pipelineStat.getStats().getIngestCurrent(), deserializedPipelineStats.getIngestCurrent());
                    assertEquals(pipelineStat.getStats().getIngestCount(), deserializedPipelineStats.getIngestCount());
                    List<IngestStats.ProcessorStat> processorStats = ingestStats.getProcessorStats().get(pipelineId);
                    // intentionally validating identical order
                    Iterator<IngestStats.ProcessorStat> it = deserializedIngestStats.getProcessorStats().get(pipelineId).iterator();
                    for (IngestStats.ProcessorStat processorStat : processorStats) {
                        IngestStats.ProcessorStat deserializedProcessorStat = it.next();
                        assertEquals(processorStat.getStats().getIngestFailedCount(), deserializedProcessorStat.getStats().getIngestFailedCount());
                        assertEquals(processorStat.getStats().getIngestTimeInMillis(), deserializedProcessorStat.getStats().getIngestTimeInMillis());
                        assertEquals(processorStat.getStats().getIngestCurrent(), deserializedProcessorStat.getStats().getIngestCurrent());
                        assertEquals(processorStat.getStats().getIngestCount(), deserializedProcessorStat.getStats().getIngestCount());
                    }
                    assertFalse(it.hasNext());
                }
            }
            AdaptiveSelectionStats adaptiveStats = nodeStats.getAdaptiveSelectionStats();
            AdaptiveSelectionStats deserializedAdaptiveStats = deserializedNodeStats.getAdaptiveSelectionStats();
            if (adaptiveStats == null) {
                assertNull(deserializedAdaptiveStats);
            } else {
                assertEquals(adaptiveStats.getOutgoingConnections(), deserializedAdaptiveStats.getOutgoingConnections());
                assertEquals(adaptiveStats.getRanks(), deserializedAdaptiveStats.getRanks());
                adaptiveStats.getComputedStats().forEach((k, v) -> {
                    ResponseCollectorService.ComputedNodeStats aStats = adaptiveStats.getComputedStats().get(k);
                    ResponseCollectorService.ComputedNodeStats bStats = deserializedAdaptiveStats.getComputedStats().get(k);
                    assertEquals(aStats.nodeId, bStats.nodeId);
                    assertEquals(aStats.queueSize, bStats.queueSize, 0.01);
                    assertEquals(aStats.serviceTime, bStats.serviceTime, 0.01);
                    assertEquals(aStats.responseTime, bStats.responseTime, 0.01);
                });
            }
            ScriptCacheStats scriptCacheStats = nodeStats.getScriptCacheStats();
            ScriptCacheStats deserializedScriptCacheStats = deserializedNodeStats.getScriptCacheStats();
            if (scriptCacheStats == null) {
                assertNull(deserializedScriptCacheStats);
            } else if (deserializedScriptCacheStats.getContextStats() != null) {
                Map<String, ScriptStats> deserialized = deserializedScriptCacheStats.getContextStats();
                long evictions = 0;
                long limited = 0;
                long compilations = 0;
                Map<String, ScriptStats> stats = scriptCacheStats.getContextStats();
                for (String context : stats.keySet()) {
                    ScriptStats deserStats = deserialized.get(context);
                    ScriptStats generatedStats = stats.get(context);
                    evictions += generatedStats.getCacheEvictions();
                    assertEquals(generatedStats.getCacheEvictions(), deserStats.getCacheEvictions());
                    limited += generatedStats.getCompilationLimitTriggered();
                    assertEquals(generatedStats.getCompilationLimitTriggered(), deserStats.getCompilationLimitTriggered());
                    compilations += generatedStats.getCompilations();
                    assertEquals(generatedStats.getCompilations(), deserStats.getCompilations());
                }
                ScriptStats sum = deserializedScriptCacheStats.sum();
                assertEquals(evictions, sum.getCacheEvictions());
                assertEquals(limited, sum.getCompilationLimitTriggered());
                assertEquals(compilations, sum.getCompilations());
            }
        }
    }
}
Also used : DiscoveryStats(org.opensearch.discovery.DiscoveryStats) ResponseCollectorService(org.opensearch.node.ResponseCollectorService) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) FsInfo(org.opensearch.monitor.fs.FsInfo) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) CircuitBreakerStats(org.opensearch.indices.breaker.CircuitBreakerStats) AllCircuitBreakerStats(org.opensearch.indices.breaker.AllCircuitBreakerStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) ScriptStats(org.opensearch.script.ScriptStats) PendingClusterStateStats(org.opensearch.cluster.coordination.PendingClusterStateStats) AdaptiveSelectionStats(org.opensearch.node.AdaptiveSelectionStats) ScriptCacheStats(org.opensearch.script.ScriptCacheStats) IngestStats(org.opensearch.ingest.IngestStats) StreamInput(org.opensearch.common.io.stream.StreamInput) IngestStats(org.opensearch.ingest.IngestStats) PendingClusterStateStats(org.opensearch.cluster.coordination.PendingClusterStateStats) CircuitBreakerStats(org.opensearch.indices.breaker.CircuitBreakerStats) OsStats(org.opensearch.monitor.os.OsStats) ScriptCacheStats(org.opensearch.script.ScriptCacheStats) DiscoveryStats(org.opensearch.discovery.DiscoveryStats) AllCircuitBreakerStats(org.opensearch.indices.breaker.AllCircuitBreakerStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) HttpStats(org.opensearch.http.HttpStats) TransportStats(org.opensearch.transport.TransportStats) ScriptStats(org.opensearch.script.ScriptStats) ThreadPoolStats(org.opensearch.threadpool.ThreadPoolStats) AdaptiveSelectionStats(org.opensearch.node.AdaptiveSelectionStats) PublishClusterStateStats(org.opensearch.cluster.coordination.PublishClusterStateStats) ProcessStats(org.opensearch.monitor.process.ProcessStats) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Aggregations

JvmStats (org.opensearch.monitor.jvm.JvmStats)4 FsInfo (org.opensearch.monitor.fs.FsInfo)3 OsStats (org.opensearch.monitor.os.OsStats)3 ProcessStats (org.opensearch.monitor.process.ProcessStats)3 ScriptStats (org.opensearch.script.ScriptStats)3 HashMap (java.util.HashMap)2 PendingClusterStateStats (org.opensearch.cluster.coordination.PendingClusterStateStats)2 PublishClusterStateStats (org.opensearch.cluster.coordination.PublishClusterStateStats)2 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)2 DiscoveryStats (org.opensearch.discovery.DiscoveryStats)2 HttpStats (org.opensearch.http.HttpStats)2 AllCircuitBreakerStats (org.opensearch.indices.breaker.AllCircuitBreakerStats)2 CircuitBreakerStats (org.opensearch.indices.breaker.CircuitBreakerStats)2 IngestStats (org.opensearch.ingest.IngestStats)2 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 List (java.util.List)1 Map (java.util.Map)1 NodeInfo (org.opensearch.action.admin.cluster.node.info.NodeInfo)1 NodeStats (org.opensearch.action.admin.cluster.node.stats.NodeStats)1