From a39babaf4dcc2f690f65907adf92963d2308b65b 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 --- .../java/org/opensearch/node/IoUsageStats.java | 2 +- .../tracker/AverageIoUsageTracker.java | 18 +++++++++++------- .../org/opensearch/node/IoUsageStatsTests.java | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/opensearch/node/IoUsageStats.java b/server/src/main/java/org/opensearch/node/IoUsageStats.java index 75cd93981f04d..ecb1ac1bb1de4 100644 --- a/server/src/main/java/org/opensearch/node/IoUsageStats.java +++ b/server/src/main/java/org/opensearch/node/IoUsageStats.java @@ -58,7 +58,7 @@ public void setIoUtilisationPercent(double ioUtilisationPercent) { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field("io_utilization_percent", String.format(Locale.ROOT, "%.1f", this.ioUtilisationPercent)); + builder.field("max_io_utilization_percent", String.format(Locale.ROOT, "%.1f", this.ioUtilisationPercent)); return builder.endObject(); } 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() { diff --git a/server/src/test/java/org/opensearch/node/IoUsageStatsTests.java b/server/src/test/java/org/opensearch/node/IoUsageStatsTests.java index 30681df0361fb..4a4de44e3acea 100644 --- a/server/src/test/java/org/opensearch/node/IoUsageStatsTests.java +++ b/server/src/test/java/org/opensearch/node/IoUsageStatsTests.java @@ -39,12 +39,12 @@ public void testIoUsageStats() throws IOException { XContentBuilder builder = JsonXContent.contentBuilder(); builder = ioUsageStats.toXContent(builder, ToXContent.EMPTY_PARAMS); String response = builder.toString(); - assertEquals(response, "{\"io_utilization_percent\":\"10.0\"}"); + assertEquals(response, "{\"max_io_utilization_percent\":\"10.0\"}"); ioUsageStats.setIoUtilisationPercent(20); builder = JsonXContent.contentBuilder(); builder = ioUsageStats.toXContent(builder, ToXContent.EMPTY_PARAMS); response = builder.toString(); - assertEquals(response, "{\"io_utilization_percent\":\"20.0\"}"); + assertEquals(response, "{\"max_io_utilization_percent\":\"20.0\"}"); } public void testIoUsageStatsToString() {