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;