From b5fa0812a82efd3344fdfee5c8a253618ae63bc6 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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 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..101f60f36c346 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,11 +68,14 @@ 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() {