public void collectMetrics()

in src/main/java/org/opensearch/performanceanalyzer/collectors/NodeStatsAllShardsMetricsCollector.java [163:207]


    public void collectMetrics(long startTime) {
        IndicesService indicesService = OpenSearchResources.INSTANCE.getIndicesService();

        if (indicesService == null) {
            return;
        }

        try {
            populateCurrentShards();
            populatePerShardStats(indicesService);

            for (HashMap.Entry currentShard : currentPerShardStats.entrySet()) {
                ShardId shardId = (ShardId) currentShard.getKey();
                ShardStats currentShardStats = (ShardStats) currentShard.getValue();
                if (prevPerShardStats.size() == 0) {
                    // Populating value for the first run.
                    populateMetricValue(
                            currentShardStats, startTime, shardId.getIndexName(), shardId.id());
                    continue;
                }
                ShardStats prevShardStats = prevPerShardStats.get(shardId);
                if (prevShardStats == null) {
                    // Populate value for shards which are new and were not present in the previous
                    // run.
                    populateMetricValue(
                            currentShardStats, startTime, shardId.getIndexName(), shardId.id());
                    continue;
                }
                NodeStatsMetricsAllShardsPerCollectionStatus prevValue =
                        new NodeStatsMetricsAllShardsPerCollectionStatus(prevShardStats);
                NodeStatsMetricsAllShardsPerCollectionStatus currValue =
                        new NodeStatsMetricsAllShardsPerCollectionStatus(currentShardStats);
                populateDiffMetricValue(
                        prevValue, currValue, startTime, shardId.getIndexName(), shardId.id());
            }
        } catch (Exception ex) {
            LOG.debug(
                    "Exception in Collecting NodesStats Metrics: {} for startTime {} with ExceptionCode: {}",
                    () -> ex.toString(),
                    () -> startTime,
                    () -> StatExceptionCode.NODESTATS_COLLECTION_ERROR.toString());
            PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat(
                    ExceptionsAndErrors.NODESTATS_COLLECTION_ERROR, "", 1);
        }
    }