|
@@ -21,7 +21,6 @@ package org.elasticsearch.monitor.fs;
|
|
|
|
|
|
import com.google.common.collect.Iterators;
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
-import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.Streamable;
|
|
@@ -35,54 +34,37 @@ import java.util.HashSet;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-/**
|
|
|
- */
|
|
|
-public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
+public class FsStats implements Iterable<FsStats.Path>, Streamable, ToXContent {
|
|
|
|
|
|
- public static class Info implements Streamable, ToXContent {
|
|
|
+ public static class Path implements Streamable, ToXContent {
|
|
|
|
|
|
String path;
|
|
|
@Nullable
|
|
|
String mount;
|
|
|
- @Nullable
|
|
|
- String dev;
|
|
|
/** File system type from {@code java.nio.file.FileStore type()}, if available. */
|
|
|
@Nullable
|
|
|
String type;
|
|
|
long total = -1;
|
|
|
long free = -1;
|
|
|
long available = -1;
|
|
|
- long diskReads = -1;
|
|
|
- long diskWrites = -1;
|
|
|
- long diskReadBytes = -1;
|
|
|
- long diskWriteBytes = -1;
|
|
|
- double diskQueue = -1;
|
|
|
- double diskServiceTime = -1;
|
|
|
+
|
|
|
/** Uses Lucene's {@code IOUtils.spins} method to try to determine if the device backed by spinning media.
|
|
|
* This is null if we could not determine it, true if it possibly spins, else false. */
|
|
|
Boolean spins = null;
|
|
|
|
|
|
- public Info() {
|
|
|
+ public Path() {
|
|
|
}
|
|
|
|
|
|
- public Info(String path, @Nullable String mount, @Nullable String dev, long total, long free, long available, long diskReads,
|
|
|
- long diskWrites, long diskReadBytes, long diskWriteBytes, double diskQueue, double diskServiceTime) {
|
|
|
+ public Path(String path, @Nullable String mount, long total, long free, long available) {
|
|
|
this.path = path;
|
|
|
this.mount = mount;
|
|
|
- this.dev = dev;
|
|
|
this.total = total;
|
|
|
this.free = free;
|
|
|
this.available = available;
|
|
|
- this.diskReads = diskReads;
|
|
|
- this.diskWrites = diskWrites;
|
|
|
- this.diskReadBytes = diskReadBytes;
|
|
|
- this.diskWriteBytes = diskWriteBytes;
|
|
|
- this.diskQueue = diskQueue;
|
|
|
- this.diskServiceTime = diskServiceTime;
|
|
|
}
|
|
|
|
|
|
- static public Info readInfoFrom(StreamInput in) throws IOException {
|
|
|
- Info i = new Info();
|
|
|
+ static public Path readInfoFrom(StreamInput in) throws IOException {
|
|
|
+ Path i = new Path();
|
|
|
i.readFrom(in);
|
|
|
return i;
|
|
|
}
|
|
@@ -91,17 +73,10 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
public void readFrom(StreamInput in) throws IOException {
|
|
|
path = in.readOptionalString();
|
|
|
mount = in.readOptionalString();
|
|
|
- dev = in.readOptionalString();
|
|
|
type = in.readOptionalString();
|
|
|
total = in.readLong();
|
|
|
free = in.readLong();
|
|
|
available = in.readLong();
|
|
|
- diskReads = in.readLong();
|
|
|
- diskWrites = in.readLong();
|
|
|
- diskReadBytes = in.readLong();
|
|
|
- diskWriteBytes = in.readLong();
|
|
|
- diskQueue = in.readDouble();
|
|
|
- diskServiceTime = in.readDouble();
|
|
|
spins = in.readOptionalBoolean();
|
|
|
}
|
|
|
|
|
@@ -109,17 +84,10 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
out.writeOptionalString(path); // total aggregates do not have a path
|
|
|
out.writeOptionalString(mount);
|
|
|
- out.writeOptionalString(dev);
|
|
|
out.writeOptionalString(type);
|
|
|
out.writeLong(total);
|
|
|
out.writeLong(free);
|
|
|
out.writeLong(available);
|
|
|
- out.writeLong(diskReads);
|
|
|
- out.writeLong(diskWrites);
|
|
|
- out.writeLong(diskReadBytes);
|
|
|
- out.writeLong(diskWriteBytes);
|
|
|
- out.writeDouble(diskQueue);
|
|
|
- out.writeDouble(diskServiceTime);
|
|
|
out.writeOptionalBoolean(spins);
|
|
|
}
|
|
|
|
|
@@ -131,10 +99,6 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
return mount;
|
|
|
}
|
|
|
|
|
|
- public String getDev() {
|
|
|
- return dev;
|
|
|
- }
|
|
|
-
|
|
|
public String getType() {
|
|
|
return type;
|
|
|
}
|
|
@@ -151,38 +115,6 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
return new ByteSizeValue(available);
|
|
|
}
|
|
|
|
|
|
- public long getDiskReads() {
|
|
|
- return this.diskReads;
|
|
|
- }
|
|
|
-
|
|
|
- public long getDiskWrites() {
|
|
|
- return this.diskWrites;
|
|
|
- }
|
|
|
-
|
|
|
- public long getDiskReadSizeInBytes() {
|
|
|
- return diskReadBytes;
|
|
|
- }
|
|
|
-
|
|
|
- public ByteSizeValue getDiskReadSizeSize() {
|
|
|
- return new ByteSizeValue(diskReadBytes);
|
|
|
- }
|
|
|
-
|
|
|
- public long getDiskWriteSizeInBytes() {
|
|
|
- return diskWriteBytes;
|
|
|
- }
|
|
|
-
|
|
|
- public ByteSizeValue getDiskWriteSizeSize() {
|
|
|
- return new ByteSizeValue(diskWriteBytes);
|
|
|
- }
|
|
|
-
|
|
|
- public double getDiskQueue() {
|
|
|
- return diskQueue;
|
|
|
- }
|
|
|
-
|
|
|
- public double getDiskServiceTime() {
|
|
|
- return diskServiceTime;
|
|
|
- }
|
|
|
-
|
|
|
public Boolean getSpins() {
|
|
|
return spins;
|
|
|
}
|
|
@@ -207,17 +139,11 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
return current + other;
|
|
|
}
|
|
|
|
|
|
- public void add(Info info) {
|
|
|
- total = addLong(total, info.total);
|
|
|
- free = addLong(free, info.free);
|
|
|
- available = addLong(available, info.available);
|
|
|
- diskReads = addLong(diskReads, info.diskReads);
|
|
|
- diskWrites = addLong(diskWrites, info.diskWrites);
|
|
|
- diskReadBytes = addLong(diskReadBytes, info.diskReadBytes);
|
|
|
- diskWriteBytes = addLong(diskWriteBytes, info.diskWriteBytes);
|
|
|
- diskQueue = addDouble(diskQueue, info.diskQueue);
|
|
|
- diskServiceTime = addDouble(diskServiceTime, info.diskServiceTime);
|
|
|
- if (info.spins != null && info.spins.booleanValue()) {
|
|
|
+ public void add(Path path) {
|
|
|
+ total = addLong(total, path.total);
|
|
|
+ free = addLong(free, path.free);
|
|
|
+ available = addLong(available, path.available);
|
|
|
+ if (path.spins != null && path.spins.booleanValue()) {
|
|
|
// Spinning is contagious!
|
|
|
spins = Boolean.TRUE;
|
|
|
}
|
|
@@ -226,7 +152,6 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
static final class Fields {
|
|
|
static final XContentBuilderString PATH = new XContentBuilderString("path");
|
|
|
static final XContentBuilderString MOUNT = new XContentBuilderString("mount");
|
|
|
- static final XContentBuilderString DEV = new XContentBuilderString("dev");
|
|
|
static final XContentBuilderString TYPE = new XContentBuilderString("type");
|
|
|
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
|
|
static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes");
|
|
@@ -234,17 +159,6 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
static final XContentBuilderString FREE_IN_BYTES = new XContentBuilderString("free_in_bytes");
|
|
|
static final XContentBuilderString AVAILABLE = new XContentBuilderString("available");
|
|
|
static final XContentBuilderString AVAILABLE_IN_BYTES = new XContentBuilderString("available_in_bytes");
|
|
|
- static final XContentBuilderString DISK_READS = new XContentBuilderString("disk_reads");
|
|
|
- static final XContentBuilderString DISK_WRITES = new XContentBuilderString("disk_writes");
|
|
|
- static final XContentBuilderString DISK_IO_OP = new XContentBuilderString("disk_io_op");
|
|
|
- static final XContentBuilderString DISK_READ_SIZE = new XContentBuilderString("disk_read_size");
|
|
|
- static final XContentBuilderString DISK_READ_SIZE_IN_BYTES = new XContentBuilderString("disk_read_size_in_bytes");
|
|
|
- static final XContentBuilderString DISK_WRITE_SIZE = new XContentBuilderString("disk_write_size");
|
|
|
- static final XContentBuilderString DISK_WRITE_SIZE_IN_BYTES = new XContentBuilderString("disk_write_size_in_bytes");
|
|
|
- static final XContentBuilderString DISK_IO_SIZE = new XContentBuilderString("disk_io_size");
|
|
|
- static final XContentBuilderString DISK_IO_IN_BYTES = new XContentBuilderString("disk_io_size_in_bytes");
|
|
|
- static final XContentBuilderString DISK_QUEUE = new XContentBuilderString("disk_queue");
|
|
|
- static final XContentBuilderString DISK_SERVICE_TIME = new XContentBuilderString("disk_service_time");
|
|
|
static final XContentBuilderString SPINS = new XContentBuilderString("spins");
|
|
|
}
|
|
|
|
|
@@ -257,9 +171,6 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
if (mount != null) {
|
|
|
builder.field(Fields.MOUNT, mount, XContentBuilder.FieldCaseConversion.NONE);
|
|
|
}
|
|
|
- if (dev != null) {
|
|
|
- builder.field(Fields.DEV, dev, XContentBuilder.FieldCaseConversion.NONE);
|
|
|
- }
|
|
|
if (type != null) {
|
|
|
builder.field(Fields.TYPE, type, XContentBuilder.FieldCaseConversion.NONE);
|
|
|
}
|
|
@@ -273,51 +184,6 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
if (available != -1) {
|
|
|
builder.byteSizeField(Fields.AVAILABLE_IN_BYTES, Fields.AVAILABLE, available);
|
|
|
}
|
|
|
-
|
|
|
- long iop = -1;
|
|
|
-
|
|
|
- if (diskReads != -1) {
|
|
|
- iop = diskReads;
|
|
|
- builder.field(Fields.DISK_READS, diskReads);
|
|
|
- }
|
|
|
- if (diskWrites != -1) {
|
|
|
- if (iop != -1) {
|
|
|
- iop += diskWrites;
|
|
|
- } else {
|
|
|
- iop = diskWrites;
|
|
|
- }
|
|
|
- builder.field(Fields.DISK_WRITES, diskWrites);
|
|
|
- }
|
|
|
-
|
|
|
- if (iop != -1) {
|
|
|
- builder.field(Fields.DISK_IO_OP, iop);
|
|
|
- }
|
|
|
-
|
|
|
- long ioBytes = -1;
|
|
|
-
|
|
|
- if (diskReadBytes != -1) {
|
|
|
- ioBytes = diskReadBytes;
|
|
|
- builder.byteSizeField(Fields.DISK_READ_SIZE_IN_BYTES, Fields.DISK_READ_SIZE, diskReadBytes);
|
|
|
- }
|
|
|
- if (diskWriteBytes != -1) {
|
|
|
- if (ioBytes != -1) {
|
|
|
- ioBytes += diskWriteBytes;
|
|
|
- } else {
|
|
|
- ioBytes = diskWriteBytes;
|
|
|
- }
|
|
|
- builder.byteSizeField(Fields.DISK_WRITE_SIZE_IN_BYTES, Fields.DISK_WRITE_SIZE, diskWriteBytes);
|
|
|
- }
|
|
|
-
|
|
|
- if (ioBytes != -1) {
|
|
|
- builder.byteSizeField(Fields.DISK_IO_IN_BYTES, Fields.DISK_IO_SIZE, ioBytes);
|
|
|
- }
|
|
|
-
|
|
|
- if (diskQueue != -1) {
|
|
|
- builder.field(Fields.DISK_QUEUE, Strings.format1Decimals(diskQueue, ""));
|
|
|
- }
|
|
|
- if (diskServiceTime != -1) {
|
|
|
- builder.field(Fields.DISK_SERVICE_TIME, Strings.format1Decimals(diskServiceTime, ""));
|
|
|
- }
|
|
|
if (spins != null) {
|
|
|
builder.field(Fields.SPINS, spins.toString());
|
|
|
}
|
|
@@ -328,36 +194,36 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
}
|
|
|
|
|
|
long timestamp;
|
|
|
- Info total;
|
|
|
- Info[] infos;
|
|
|
+ Path total;
|
|
|
+ Path[] paths;
|
|
|
|
|
|
FsStats() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public FsStats(long timestamp, Info[] infos) {
|
|
|
+ public FsStats(long timestamp, Path[] paths) {
|
|
|
this.timestamp = timestamp;
|
|
|
- this.infos = infos;
|
|
|
+ this.paths = paths;
|
|
|
this.total = null;
|
|
|
}
|
|
|
|
|
|
- public Info getTotal() {
|
|
|
+ public Path getTotal() {
|
|
|
return total();
|
|
|
}
|
|
|
|
|
|
- public Info total() {
|
|
|
+ public Path total() {
|
|
|
if (total != null) {
|
|
|
return total;
|
|
|
}
|
|
|
- Info res = new Info();
|
|
|
- Set<String> seenDevices = new HashSet<>(infos.length);
|
|
|
- for (Info subInfo : infos) {
|
|
|
- if (subInfo.dev != null) {
|
|
|
- if (!seenDevices.add(subInfo.dev)) {
|
|
|
+ Path res = new Path();
|
|
|
+ Set<String> seenDevices = new HashSet<>(paths.length);
|
|
|
+ for (Path subPath : paths) {
|
|
|
+ if (subPath.path != null) {
|
|
|
+ if (!seenDevices.add(subPath.path)) {
|
|
|
continue; // already added numbers for this device;
|
|
|
}
|
|
|
}
|
|
|
- res.add(subInfo);
|
|
|
+ res.add(subPath);
|
|
|
}
|
|
|
total = res;
|
|
|
return res;
|
|
@@ -368,8 +234,8 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Iterator<Info> iterator() {
|
|
|
- return Iterators.forArray(infos);
|
|
|
+ public Iterator<Path> iterator() {
|
|
|
+ return Iterators.forArray(paths);
|
|
|
}
|
|
|
|
|
|
public static FsStats readFsStats(StreamInput in) throws IOException {
|
|
@@ -381,18 +247,18 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
@Override
|
|
|
public void readFrom(StreamInput in) throws IOException {
|
|
|
timestamp = in.readVLong();
|
|
|
- infos = new Info[in.readVInt()];
|
|
|
- for (int i = 0; i < infos.length; i++) {
|
|
|
- infos[i] = Info.readInfoFrom(in);
|
|
|
+ paths = new Path[in.readVInt()];
|
|
|
+ for (int i = 0; i < paths.length; i++) {
|
|
|
+ paths[i] = Path.readInfoFrom(in);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
out.writeVLong(timestamp);
|
|
|
- out.writeVInt(infos.length);
|
|
|
- for (Info info : infos) {
|
|
|
- info.writeTo(out);
|
|
|
+ out.writeVInt(paths.length);
|
|
|
+ for (Path path : paths) {
|
|
|
+ path.writeTo(out);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -410,8 +276,8 @@ public class FsStats implements Iterable<FsStats.Info>, Streamable, ToXContent {
|
|
|
builder.field(Fields.TOTAL);
|
|
|
total().toXContent(builder, params);
|
|
|
builder.startArray(Fields.DATA);
|
|
|
- for (Info info : infos) {
|
|
|
- info.toXContent(builder, params);
|
|
|
+ for (Path path : paths) {
|
|
|
+ path.toXContent(builder, params);
|
|
|
}
|
|
|
builder.endArray();
|
|
|
builder.endObject();
|