Added a time stamp to the cluster stats response

Making it consistent with NodeStats
This commit is contained in:
Boaz Leskes 2013-12-17 16:04:55 +01:00
parent d97a00d4a7
commit 33bb2ecfa8
3 changed files with 13 additions and 3 deletions

View File

@ -37,22 +37,27 @@ import java.util.Map;
*/ */
public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNodeResponse> implements ToXContent { public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNodeResponse> implements ToXContent {
ClusterStatsNodes nodesStats; ClusterStatsNodes nodesStats;
ClusterStatsIndices indicesStats; ClusterStatsIndices indicesStats;
String clusterUUID; String clusterUUID;
long timestamp;
ClusterStatsResponse() { ClusterStatsResponse() {
} }
public ClusterStatsResponse(ClusterName clusterName, String clusterUUID, ClusterStatsNodeResponse[] nodes) { public ClusterStatsResponse(long timestamp, ClusterName clusterName, String clusterUUID, ClusterStatsNodeResponse[] nodes) {
super(clusterName, null); super(clusterName, null);
this.timestamp = timestamp;
this.clusterUUID = clusterUUID; this.clusterUUID = clusterUUID;
nodesStats = new ClusterStatsNodes(nodes); nodesStats = new ClusterStatsNodes(nodes);
indicesStats = new ClusterStatsIndices(nodes); indicesStats = new ClusterStatsIndices(nodes);
} }
public long getTimestamp() {
return this.timestamp;
}
public ClusterStatsNodes getNodesStats() { public ClusterStatsNodes getNodesStats() {
return nodesStats; return nodesStats;
} }
@ -84,6 +89,7 @@ public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNod
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
timestamp = in.readVLong();
clusterUUID = in.readString(); clusterUUID = in.readString();
nodesStats = ClusterStatsNodes.readNodeStats(in); nodesStats = ClusterStatsNodes.readNodeStats(in);
indicesStats = ClusterStatsIndices.readIndicesStats(in); indicesStats = ClusterStatsIndices.readIndicesStats(in);
@ -92,6 +98,7 @@ public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNod
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeVLong(timestamp);
out.writeString(clusterUUID); out.writeString(clusterUUID);
nodesStats.writeTo(out); nodesStats.writeTo(out);
indicesStats.writeTo(out); indicesStats.writeTo(out);
@ -106,6 +113,7 @@ public class ClusterStatsResponse extends NodesOperationResponse<ClusterStatsNod
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("timestamp", getTimestamp());
builder.field(Fields.CLUSTER_NAME, getClusterName().value()); builder.field(Fields.CLUSTER_NAME, getClusterName().value());
if (params.paramAsBoolean("output_uuid", false)) { if (params.paramAsBoolean("output_uuid", false)) {
builder.field(Fields.UUID, clusterUUID); builder.field(Fields.UUID, clusterUUID);

View File

@ -86,7 +86,8 @@ public class TransportClusterStatsAction extends TransportNodesOperationAction<C
nodeStats.add((ClusterStatsNodeResponse) resp); nodeStats.add((ClusterStatsNodeResponse) resp);
} }
} }
return new ClusterStatsResponse(clusterName, clusterService.state().metaData().uuid(), nodeStats.toArray(new ClusterStatsNodeResponse[nodeStats.size()])); return new ClusterStatsResponse(System.currentTimeMillis(), clusterName,
clusterService.state().metaData().uuid(), nodeStats.toArray(new ClusterStatsNodeResponse[nodeStats.size()]));
} }
@Override @Override

View File

@ -112,6 +112,7 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest {
index("test1", "type", "1", "f", "f"); index("test1", "type", "1", "f", "f");
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get(); ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
assertThat(response.getTimestamp(), Matchers.greaterThan(946681200000l)); // 1 Jan 2000
assertThat(response.indicesStats.getStore().getSizeInBytes(), Matchers.greaterThan(0l)); assertThat(response.indicesStats.getStore().getSizeInBytes(), Matchers.greaterThan(0l));
assertThat(response.nodesStats.getFs().getTotal().bytes(), Matchers.greaterThan(0l)); assertThat(response.nodesStats.getFs().getTotal().bytes(), Matchers.greaterThan(0l));