in src/main/java/org/opensearch/performanceanalyzer/collectors/NodeStatsFixedShardsMetricsCollector.java [219:274]
public void collectMetrics(long startTime) {
IndicesService indicesService = OpenSearchResources.INSTANCE.getIndicesService();
if (indicesService == null) {
return;
}
try {
// reach the end of current shardId list. retrieve new shard list from IndexService
if (!currentShardsIter.hasNext()) {
populateCurrentShards();
}
for (int i = 0; i < controller.getNodeStatsShardsPerCollection(); i++) {
if (!currentShardsIter.hasNext()) {
break;
}
IndexShard currentIndexShard = currentShardsIter.next().getValue();
IndexShardStats currentIndexShardStats =
Utils.indexShardStats(
indicesService,
currentIndexShard,
new CommonStatsFlags(
CommonStatsFlags.Flag.Segments,
CommonStatsFlags.Flag.Store,
CommonStatsFlags.Flag.Indexing,
CommonStatsFlags.Flag.Merge,
CommonStatsFlags.Flag.Flush,
CommonStatsFlags.Flag.Refresh,
CommonStatsFlags.Flag.Recovery));
for (ShardStats shardStats : currentIndexShardStats.getShards()) {
StringBuilder value = new StringBuilder();
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds());
// - go through the list of metrics to be collected and emit
value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
.append(
new NodeStatsMetricsFixedShardsPerCollectionStatus(shardStats)
.serialize());
saveMetricValues(
value.toString(),
startTime,
currentIndexShardStats.getShardId().getIndexName(),
String.valueOf(currentIndexShardStats.getShardId().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);
}
}