From 27b60be726c78a3fe45e72b85041bd107ec3bce4 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Movva Date: Mon, 4 Mar 2024 14:07:52 +0530 Subject: [PATCH] Enable IO Usage Tracker For Linux OS Signed-off-by: Ajay Kumar Movva --- .../tracker/AverageIoUsageTracker.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/opensearch/node/resource/tracker/AverageIoUsageTracker.java b/server/src/main/java/org/opensearch/node/resource/tracker/AverageIoUsageTracker.java index 97df9e6511596..5ce4ca555dddd 100644 --- a/server/src/main/java/org/opensearch/node/resource/tracker/AverageIoUsageTracker.java +++ b/server/src/main/java/org/opensearch/node/resource/tracker/AverageIoUsageTracker.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.lucene.util.Constants; import org.opensearch.common.unit.TimeValue; import org.opensearch.monitor.fs.FsInfo.DeviceStats; import org.opensearch.monitor.fs.FsService; @@ -28,14 +29,14 @@ public class AverageIoUsageTracker extends AbstractAverageUsageTracker { private final FsService fsService; private final HashMap prevIoTimeDeviceMap; private long prevTimeInMillis; - private final IoUsageStats ioUsageStats; + private IoUsageStats ioUsageStats; public AverageIoUsageTracker(FsService fsService, ThreadPool threadPool, TimeValue pollingInterval, TimeValue windowDuration) { super(threadPool, pollingInterval, windowDuration); this.fsService = fsService; this.prevIoTimeDeviceMap = new HashMap<>(); this.prevTimeInMillis = -1; - this.ioUsageStats = new IoUsageStats(-1); + this.ioUsageStats = null; } /** @@ -67,15 +68,18 @@ public long getUsage() { @Override protected void doStart() { - scheduledFuture = threadPool.scheduleWithFixedDelay(() -> { - long usage = getUsage(); - recordUsage(usage); - updateIoUsageStats(); - }, pollingInterval, ThreadPool.Names.GENERIC); + if(Constants.LINUX) { + this.ioUsageStats = new IoUsageStats(-1); + scheduledFuture = threadPool.scheduleWithFixedDelay(() -> { + long usage = getUsage(); + recordUsage(usage); + updateIoUsageStats(); + }, pollingInterval, ThreadPool.Names.GENERIC); + } } private boolean preValidateFsStats() { - return fsService == null + return fsService == null || fsService.stats() == null || fsService.stats().getIoStats() == null || fsService.stats().getIoStats().getDevicesStats() == null;