Skip to content

Commit

Permalink
FS changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Oct 5, 2023
1 parent b2fb22a commit 47032e5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
21 changes: 19 additions & 2 deletions server/src/main/java/org/opensearch/monitor/fs/FsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ public static class DeviceStats implements Writeable, ToXContentFragment {
final double currentWriteTime;
final double previousWriteTime;

final double currentQueueSize;

final double previousQueueSize;

public DeviceStats(
final int majorDeviceNumber,
final int minorDeviceNumber,
Expand All @@ -253,6 +257,7 @@ public DeviceStats(
final long currentIOTime,
final double currentReadTime,
final double currentWriteTime,
final double currentQueueSize,
final DeviceStats previousDeviceStats
) {
this(
Expand All @@ -272,7 +277,9 @@ public DeviceStats(
currentReadTime,
previousDeviceStats != null ? previousDeviceStats.previousReadTime : -1.0,
currentWriteTime,
previousDeviceStats != null ? previousDeviceStats.previousWriteTime : -1.0
previousDeviceStats != null ? previousDeviceStats.previousWriteTime : -1.0,
currentQueueSize,
previousDeviceStats != null ? previousDeviceStats.previousQueueSize : -1.0
);
}

Expand All @@ -293,7 +300,9 @@ private DeviceStats(
final double currentReadTime,
final double previousReadTime,
final double currentWriteTime,
final double previousWriteTime
final double previousWriteTime,
final double currentQueueSize,
final double previousQueueSize
) {
this.majorDeviceNumber = majorDeviceNumber;
this.minorDeviceNumber = minorDeviceNumber;
Expand All @@ -312,6 +321,8 @@ private DeviceStats(
this.previousReadTime = previousReadTime;
this.currentWriteTime = currentWriteTime;
this.previousWriteTime = previousWriteTime;
this.currentQueueSize = currentQueueSize;
this.previousQueueSize = previousQueueSize;
}

public DeviceStats(StreamInput in) throws IOException {
Expand All @@ -332,6 +343,8 @@ public DeviceStats(StreamInput in) throws IOException {
previousReadTime = in.readDouble();
currentWriteTime = in.readDouble();
previousWriteTime = in.readDouble();
currentQueueSize = in.readDouble();
previousQueueSize = in.readDouble();
}

@Override
Expand All @@ -352,6 +365,8 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeDouble(currentReadTime);
out.writeDouble(currentWriteTime);
out.writeDouble(previousWriteTime);
out.writeDouble(currentQueueSize);
out.writeDouble(previousQueueSize);
}

public long operations() {
Expand Down Expand Up @@ -406,6 +421,8 @@ public double getCurrentWriteTime() {
return this.currentWriteTime;
}

public double getCurrentQueueSize() { return this.currentQueueSize; }

public String getDeviceName() {
return this.deviceName;
}
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/org/opensearch/monitor/fs/FsProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ final FsInfo.IoStats ioStats(final Set<Tuple<Integer, Integer>> devicesNumbers,
final long sectorsWritten = Long.parseLong(fields[9]);
final double readTime = Double.parseDouble(fields[6]);
final double writeTime = Double.parseDouble(fields[10]);
final long ioTime = Long.parseLong(fields[12]);
final long ioTime = fields.length >= 12 ? Long.parseLong(fields[12]) : -1;
final double queueSize = fields.length >= 14 ? Double.parseDouble(fields[14]) : -1;
final FsInfo.DeviceStats deviceStats = new FsInfo.DeviceStats(
majorDeviceNumber,
minorDeviceNumber,
Expand All @@ -137,6 +138,7 @@ final FsInfo.IoStats ioStats(final Set<Tuple<Integer, Integer>> devicesNumbers,
ioTime,
readTime,
writeTime,
queueSize,
deviceMap.get(Tuple.tuple(majorDeviceNumber, minorDeviceNumber))
);
devicesStats.add(deviceStats);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.opensearch.ratelimiting.tracker;

import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
Expand All @@ -17,7 +16,6 @@

import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class AverageDiskStats implements Writeable {
private final double readIopsAverage;
Expand All @@ -28,15 +26,19 @@ public class AverageDiskStats implements Writeable {
private final double writeLatencyAverage;
private final double ioUtilizationPercent;

private final double queueSize;

public AverageDiskStats(double readIopsAverage, double writeIopsAverage, double readKbAverage, double writeKbAverage,
double readLatencyAverage, double writeLatencyAverage, double ioUtilizationPercent) {
double readLatencyAverage, double writeLatencyAverage, double ioUtilizationPercent,
double queueSize) {
this.readIopsAverage = readIopsAverage;
this.writeIopsAverage = writeIopsAverage;
this.readKbAverage = readKbAverage;
this.writeKbAverage = writeKbAverage;
this.readLatencyAverage = readLatencyAverage;
this.writeLatencyAverage = writeLatencyAverage;
this.ioUtilizationPercent = ioUtilizationPercent;
this.queueSize = queueSize;
}

public AverageDiskStats(StreamInput in) throws IOException {
Expand All @@ -47,6 +49,7 @@ public AverageDiskStats(StreamInput in) throws IOException {
this.writeKbAverage = in.readDouble();
this.writeLatencyAverage = in.readDouble();
this.ioUtilizationPercent = in.readDouble();
this.queueSize = in.readDouble();
}

public double getIoUtilizationPercent() {
Expand Down Expand Up @@ -82,6 +85,14 @@ public void writeTo(StreamOutput out) throws IOException {

}

@Override
public String toString() {
return String.format("IO_UTIL : {} , Queue_size: {}, Read_latency: {} , Read_Iops: {}, " +
"ReadThroughput: {}, Write_latency : {}, Write_Iops : {}, WriteThroughput : {}", ioUtilizationPercent,
queueSize, readLatencyAverage, readIopsAverage, readKbAverage, writeLatencyAverage, writeIopsAverage,
writeKbAverage);
}

public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject("io_stats");
builder.field("read_iops_average", String.format(Locale.ROOT, "%.1f", readIopsAverage ));
Expand All @@ -91,6 +102,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
builder.field("read_latency_average", String.format(Locale.ROOT, "%.8f", readLatencyAverage));
builder.field("write_latency_average", String.format(Locale.ROOT, "%.8f", writeLatencyAverage));
builder.field("io_utilization_percent", String.format(Locale.ROOT, "%.3f", ioUtilizationPercent));
builder.field("queue_size", String.format(Locale.ROOT, "%.3f", queueSize));
builder.endObject();
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class AverageIOUsageTracker extends AbstractLifecycleComponent {
private final AtomicReference<MovingAverage> writeKbObservations = new AtomicReference<>();
private final AtomicReference<MovingAverageDouble> readLatencyObservations = new AtomicReference<>();
private final AtomicReference<MovingAverageDouble> writeLatencyObservations = new AtomicReference<>();

private final AtomicReference<MovingAverageDouble> queueSizeObservations = new AtomicReference<>();
private final Map<String, IoUsageFetcher.DiskStats> previousIOTimeMap = new HashMap<>();
public AverageIOUsageTracker(
ThreadPool threadPool,
Expand All @@ -61,6 +63,7 @@ public AverageIOUsageTracker(
this.windowDuration = windowDuration;
this.setWindowDuration(windowDuration);
this.ioUsageFetcher = new IoUsageFetcher(fsService);

// Add this post integration
// clusterSettings.addSettingsUpdateConsumer(
// PerformanceTrackerSettings.GLOBAL_IO_WINDOW_DURATION_SETTING,
Expand Down Expand Up @@ -106,9 +109,11 @@ public double getWriteLatencyAverage() {
return writeLatencyObservations.get().getAverage();
}

public double getQueueSizeAverage() { return queueSizeObservations.get().getAverage(); }

public AverageDiskStats getAverageDiskStats() {
return new AverageDiskStats(getReadIopsAverage(), getWriteIopsAverage(), getReadKbAverage(), getWriteKbAverage(),
getReadLatencyAverage(), getWriteLatencyAverage(), getIoPercentAverage());
getReadLatencyAverage(), getWriteLatencyAverage(), getIoPercentAverage(), getQueueSizeAverage());
}

public void setWindowDuration(TimeValue windowDuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ class DiskStats {
public double writeOps;
public long readThroughputInKB;
public long writeThroughputInKB;

public double queueSize;
public DiskStats(long ioTime, double readTime, double writeTime, double readOps, double writeOps,
long readThroughputInKB, long writeThroughputInKB) {
long readThroughputInKB, long writeThroughputInKB, double queueSize) {
this.ioTime = ioTime;
this.readTime = readTime;
this.writeTime = writeTime;
this.readOps = readOps;
this.writeOps = writeOps;
this.readThroughputInKB = readThroughputInKB;
this.writeThroughputInKB = writeThroughputInKB;
this.queueSize = queueSize;
}

public long getIoTime() {
Expand Down Expand Up @@ -83,6 +86,7 @@ public DiskStats getDiskUtilizationStats(Map<String, DiskStats> previousIOTimeMa
double writeTime = 0;
double readOps = 0.0;
double writeOps = 0.0;
double queueSize = 0.0;
// For non linux machines, this will be null
if(this.fsService.stats().getIoStats() == null) {
return null;
Expand All @@ -98,6 +102,7 @@ public DiskStats getDiskUtilizationStats(Map<String, DiskStats> previousIOTimeMa
writekb += devicesStat.getCurrentWriteKilobytes() - previousIOTimeMap.get(devicesStat.getDeviceName()).writeThroughputInKB;
readTime += devicesStat.getCurrentReadTime() - previousIOTimeMap.get(devicesStat.getDeviceName()).readTime;
writeTime += devicesStat.getCurrentWriteTime() - previousIOTimeMap.get(devicesStat.getDeviceName()).writeTime;
queueSize += devicesStat.getCurrentQueueSize() - previousIOTimeMap.get(devicesStat.getDeviceName()).queueSize;
// Avoid dividing by fractions which will give false positives in results
if(readTime < 1) readTime = 1;
if(readOps < 1) readOps = 1;
Expand All @@ -106,12 +111,12 @@ public DiskStats getDiskUtilizationStats(Map<String, DiskStats> previousIOTimeMa
}
DiskStats ps = new DiskStats(devicesStat.getCurrentIOTime(), devicesStat.getCurrentReadTime(),
devicesStat.getCurrentWriteTime(), devicesStat.currentReadOperations(), devicesStat.currentWriteOperations(),
devicesStat.getCurrentReadKilobytes(), devicesStat.getCurrentWriteKilobytes());
devicesStat.getCurrentReadKilobytes(), devicesStat.getCurrentWriteKilobytes(), devicesStat.getCurrentQueueSize());
currentIOTimeMap.put(devicesStat.getDeviceName(), ps);
}
logger.debug("IO use percent : {}", ioUsePercent);
previousIOTimeMap.putAll(currentIOTimeMap);

return new DiskStats(ioUsePercent, readTime, writeTime, readOps, writeOps, readkb, writekb);
return new DiskStats(ioUsePercent, readTime, writeTime, readOps, writeOps, readkb, writekb, queueSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package org.opensearch.ratelimiting.tracker;public class NodePerformanceTracker {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package org.opensearch.ratelimiting.tracker;public class PerformanceTrackerSettings {
}

0 comments on commit 47032e5

Please sign in to comment.