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 <[email protected]>
  • Loading branch information
Ajay Kumar Movva committed Mar 4, 2024
1 parent 22da423 commit 14ca3ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 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

0 comments on commit 14ca3ca

Please sign in to comment.