-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate IO Usage Tracker to the Resource Usage Collector Service an…
…d Emit IO Usage Stats Signed-off-by: Ajay Kumar Movva <[email protected]>
- Loading branch information
Ajay Kumar Movva
committed
Jan 14, 2024
1 parent
988dea8
commit 842d3d4
Showing
14 changed files
with
289 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
server/src/main/java/org/opensearch/node/IoUsageStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.node; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
/** | ||
* This class is to store tne IO Usage Stats and used to return in node stats API. | ||
*/ | ||
public class IoUsageStats implements Writeable, ToXContentFragment { | ||
|
||
private double ioUtilisationPercent; | ||
|
||
public IoUsageStats(double ioUtilisationPercent) { | ||
this.ioUtilisationPercent = ioUtilisationPercent; | ||
} | ||
|
||
public IoUsageStats(StreamInput in) throws IOException { | ||
this.ioUtilisationPercent = in.readDouble(); | ||
} | ||
|
||
/** | ||
* Write this into the {@linkplain StreamOutput}. | ||
* | ||
* @param out | ||
*/ | ||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeDouble(this.ioUtilisationPercent); | ||
} | ||
|
||
public double getIoUtilisationPercent() { | ||
return ioUtilisationPercent; | ||
} | ||
|
||
public void setIoUtilisationPercent(double ioUtilisationPercent) { | ||
this.ioUtilisationPercent = ioUtilisationPercent; | ||
} | ||
|
||
/** | ||
* @param builder | ||
* @param params | ||
* @return | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("io_utilization_percent", this.ioUtilisationPercent); | ||
return builder.endObject(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ", IO utilization percent: " + String.format(Locale.ROOT, "%.1f", this.ioUtilisationPercent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
server/src/main/java/org/opensearch/node/resource/tracker/AverageIoUsageTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.node.resource.tracker; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.monitor.fs.FsService; | ||
import org.opensearch.node.IoUsageStats; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
/** | ||
* AverageIoUsageTracker tracks the IO usage by polling the FS Stats for IO metrics every (pollingInterval) | ||
* and keeping track of the rolling average over a defined time window (windowDuration). | ||
*/ | ||
public class AverageIoUsageTracker extends AbstractAverageUsageTracker { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(AverageIoUsageTracker.class); | ||
private final FsService fsService; | ||
private long prevIoTimeMillis; | ||
private long prevTimeMillis; | ||
private final IoUsageStats ioUsageStats; | ||
|
||
public AverageIoUsageTracker(FsService fsService, ThreadPool threadPool, TimeValue pollingInterval, TimeValue windowDuration) { | ||
super(threadPool, pollingInterval, windowDuration); | ||
this.fsService = fsService; | ||
this.prevIoTimeMillis = -1; | ||
this.prevTimeMillis = -1; | ||
this.ioUsageStats = new IoUsageStats(0); | ||
} | ||
|
||
/** | ||
* Get current IO usage percentage calculated using fs stats | ||
*/ | ||
@Override | ||
public long getUsage() { | ||
long usage = 0; | ||
if (this.preValidateFsStats()) { | ||
return usage; | ||
} | ||
long currentIoTimeMillis = fsService.stats().getIoStats().getTotalIOTimeMillis(); | ||
long ioDevicesCount = fsService.stats().getIoStats().getDevicesStats().length; | ||
long currentTimeMillis = fsService.stats().getTimestamp(); | ||
if (prevTimeMillis > 0 && (currentTimeMillis - this.prevTimeMillis > 0)) { | ||
long averageIoTime = (currentIoTimeMillis - this.prevIoTimeMillis) / ioDevicesCount; | ||
usage = averageIoTime * 100 / (currentTimeMillis - this.prevTimeMillis); | ||
} | ||
this.prevTimeMillis = currentTimeMillis; | ||
this.prevIoTimeMillis = currentIoTimeMillis; | ||
return usage; | ||
} | ||
|
||
@Override | ||
protected void doStart() { | ||
scheduledFuture = threadPool.scheduleWithFixedDelay(() -> { | ||
long usage = getUsage(); | ||
recordUsage(usage); | ||
updateIoUsageStats(); | ||
}, pollingInterval, ThreadPool.Names.GENERIC); | ||
} | ||
|
||
private boolean preValidateFsStats() { | ||
return fsService == null | ||
|| fsService.stats() == null | ||
|| fsService.stats().getIoStats() == null | ||
|| fsService.stats().getIoStats().getDevicesStats() == null; | ||
} | ||
|
||
private void updateIoUsageStats() { | ||
this.ioUsageStats.setIoUtilisationPercent(this.isReady() ? this.getAverage() : 0); | ||
} | ||
|
||
public IoUsageStats getIoUsageStats() { | ||
return this.ioUsageStats; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.