add refresh interval to os/process/network info api which represents the refresh interval of their respective stats

This commit is contained in:
kimchy 2011-01-16 12:33:23 +02:00
parent c0e2e14c36
commit 285afe8053
6 changed files with 44 additions and 2 deletions

View File

@ -35,8 +35,18 @@ public class NetworkInfo implements Streamable, Serializable, ToXContent {
public static final Interface NA_INTERFACE = new Interface(); public static final Interface NA_INTERFACE = new Interface();
long refreshInterval;
Interface primary = NA_INTERFACE; Interface primary = NA_INTERFACE;
public long refreshInterval() {
return this.refreshInterval;
}
public long getRefreshInterval() {
return this.refreshInterval;
}
public Interface primaryInterface() { public Interface primaryInterface() {
return primary; return primary;
} }
@ -47,6 +57,7 @@ public class NetworkInfo implements Streamable, Serializable, ToXContent {
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("network"); builder.startObject("network");
builder.field("refresh_interval", refreshInterval);
if (primary != NA_INTERFACE) { if (primary != NA_INTERFACE) {
builder.startObject("primary_interface"); builder.startObject("primary_interface");
builder.field("address", primary.address()); builder.field("address", primary.address());
@ -65,10 +76,12 @@ public class NetworkInfo implements Streamable, Serializable, ToXContent {
} }
@Override public void readFrom(StreamInput in) throws IOException { @Override public void readFrom(StreamInput in) throws IOException {
refreshInterval = in.readLong();
primary = Interface.readNetworkInterface(in); primary = Interface.readNetworkInterface(in);
} }
@Override public void writeTo(StreamOutput out) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException {
out.writeLong(refreshInterval);
primary.writeTo(out); primary.writeTo(out);
} }

View File

@ -54,6 +54,7 @@ public class NetworkService extends AbstractComponent {
logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval); logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);
this.info = probe.networkInfo(); this.info = probe.networkInfo();
this.info.refreshInterval = refreshInterval.millis();
this.cachedStats = probe.networkStats(); this.cachedStats = probe.networkStats();
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {

View File

@ -34,6 +34,8 @@ import java.io.Serializable;
*/ */
public class OsInfo implements Streamable, Serializable, ToXContent { public class OsInfo implements Streamable, Serializable, ToXContent {
long refreshInterval;
Cpu cpu = null; Cpu cpu = null;
Mem mem = null; Mem mem = null;
@ -43,6 +45,14 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
OsInfo() { OsInfo() {
} }
public long refreshInterval() {
return this.refreshInterval;
}
public long getRefreshInterval() {
return this.refreshInterval;
}
public Cpu cpu() { public Cpu cpu() {
return this.cpu; return this.cpu;
} }
@ -69,6 +79,7 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("os"); builder.startObject("os");
builder.field("refresh_interval", refreshInterval);
if (cpu != null) { if (cpu != null) {
builder.startObject("cpu"); builder.startObject("cpu");
builder.field("vendor", cpu.vendor()); builder.field("vendor", cpu.vendor());
@ -104,6 +115,7 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
} }
@Override public void readFrom(StreamInput in) throws IOException { @Override public void readFrom(StreamInput in) throws IOException {
refreshInterval = in.readLong();
if (in.readBoolean()) { if (in.readBoolean()) {
cpu = Cpu.readCpu(in); cpu = Cpu.readCpu(in);
} }
@ -116,6 +128,7 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
} }
@Override public void writeTo(StreamOutput out) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException {
out.writeLong(refreshInterval);
if (cpu == null) { if (cpu == null) {
out.writeBoolean(false); out.writeBoolean(false);
} else { } else {

View File

@ -45,9 +45,10 @@ public class OsService extends AbstractComponent {
this.probe = probe; this.probe = probe;
this.timerService = timerService; this.timerService = timerService;
this.info = probe.osInfo();
this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5));
this.info = probe.osInfo();
this.info.refreshInterval = refreshInterval.millis();
this.cachedStats = probe.osStats(); this.cachedStats = probe.osStats();
logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval); logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);

View File

@ -33,6 +33,8 @@ import java.io.Serializable;
*/ */
public class ProcessInfo implements Streamable, Serializable, ToXContent { public class ProcessInfo implements Streamable, Serializable, ToXContent {
long refreshInterval;
private long id; private long id;
ProcessInfo() { ProcessInfo() {
@ -43,6 +45,14 @@ public class ProcessInfo implements Streamable, Serializable, ToXContent {
this.id = id; this.id = id;
} }
public long refreshInterval() {
return this.refreshInterval;
}
public long getRefreshInterval() {
return this.refreshInterval;
}
/** /**
* The process id. * The process id.
*/ */
@ -59,6 +69,7 @@ public class ProcessInfo implements Streamable, Serializable, ToXContent {
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("process"); builder.startObject("process");
builder.field("refresh_interval", refreshInterval);
builder.field("id", id); builder.field("id", id);
builder.endObject(); builder.endObject();
return builder; return builder;
@ -71,10 +82,12 @@ public class ProcessInfo implements Streamable, Serializable, ToXContent {
} }
@Override public void readFrom(StreamInput in) throws IOException { @Override public void readFrom(StreamInput in) throws IOException {
refreshInterval = in.readLong();
id = in.readLong(); id = in.readLong();
} }
@Override public void writeTo(StreamOutput out) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException {
out.writeLong(refreshInterval);
out.writeLong(id); out.writeLong(id);
} }
} }

View File

@ -48,6 +48,7 @@ public class ProcessService extends AbstractComponent {
this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5));
this.info = probe.processInfo(); this.info = probe.processInfo();
this.info.refreshInterval = refreshInterval.millis();
this.cachedStats = probe.processStats(); this.cachedStats = probe.processStats();
logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval); logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);