-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate IO Based Usage Tracker and Stats for the Resource Usage Ser…
…vice Signed-off-by: Ajay Kumar Movva <movvaam@amazon.com>
- Loading branch information
Ajay Kumar Movva
committed
Jan 14, 2024
1 parent
988dea8
commit 8dcf40e
Showing
13 changed files
with
250 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
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
/* | ||
* 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; | ||
|
||
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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
/* | ||
* 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; | ||
|
||
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 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)) { | ||
LOGGER.info("Io Time Diff: " + (currentIoTimeMillis - prevIoTimeMillis)); | ||
LOGGER.info("Time Diff: " + (currentTimeMillis - prevTimeMillis)); | ||
LOGGER.info("Count of Devices: " + ioDevicesCount); | ||
long averageIoTime = (currentIoTimeMillis - this.prevIoTimeMillis) / ioDevicesCount; | ||
usage = averageIoTime * 100 / (currentTimeMillis - this.prevTimeMillis); | ||
LOGGER.info("Recording IO usage: {}%", usage); | ||
} | ||
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.