Skip to content

Commit

Permalink
Enable IO Usage Tracker For Linux OS
Browse files Browse the repository at this point in the history
Signed-off-by: Ajay Kumar Movva <movvaam@amazon.com>
  • Loading branch information
Ajay Kumar Movva committed Mar 4, 2024
1 parent 22da423 commit a39baba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/node/IoUsageStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,14 +29,14 @@ public class AverageIoUsageTracker extends AbstractAverageUsageTracker {
private final FsService fsService;
private final HashMap<String, Long> 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;
}

/**
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a39baba

Please sign in to comment.