Skip to content

Commit

Permalink
Node Stats API: Add specific flags for stats, simplified REST paths, c…
Browse files Browse the repository at this point in the history
…loses #1597.
  • Loading branch information
kimchy committed Jan 9, 2012
1 parent f1f2fb2 commit 4464fe1
Show file tree
Hide file tree
Showing 8 changed files with 474 additions and 56 deletions.
Expand Up @@ -89,11 +89,13 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
}

builder.startObject("attributes");
for (Map.Entry<String, String> attr : nodeInfo.node().attributes().entrySet()) {
builder.field(attr.getKey(), attr.getValue());
if (!nodeInfo.node().attributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attr : nodeInfo.node().attributes().entrySet()) {
builder.field(attr.getKey(), attr.getValue());
}
builder.endObject();
}
builder.endObject();


if (nodeInfo.settings() != null) {
Expand Down
Expand Up @@ -36,32 +36,41 @@

/**
* Node statistics (static, does not change over time).
*
*
*/
public class NodeStats extends NodeOperationResponse {

@Nullable
private String hostname;

@Nullable
private NodeIndicesStats indices;

@Nullable
private OsStats os;

@Nullable
private ProcessStats process;

@Nullable
private JvmStats jvm;

@Nullable
private NetworkStats network;

@Nullable
private TransportStats transport;

@Nullable
private HttpStats http;

NodeStats() {
}

public NodeStats(DiscoveryNode node, NodeIndicesStats indices,
OsStats os, ProcessStats process, JvmStats jvm, NetworkStats network,
TransportStats transport, @Nullable HttpStats http) {
public NodeStats(DiscoveryNode node, @Nullable String hostname, @Nullable NodeIndicesStats indices,
@Nullable OsStats os, @Nullable ProcessStats process, @Nullable JvmStats jvm, @Nullable NetworkStats network,
@Nullable TransportStats transport, @Nullable HttpStats http) {
super(node);
this.hostname = hostname;
this.indices = indices;
this.os = os;
this.process = process;
Expand All @@ -71,88 +80,112 @@ public NodeStats(DiscoveryNode node, NodeIndicesStats indices,
this.http = http;
}

@Nullable
public String hostname() {
return this.hostname;
}

@Nullable
public String getHostname() {
return this.hostname;
}

/**
* Indices level stats.
*/
@Nullable
public NodeIndicesStats indices() {
return this.indices;
}

/**
* Indices level stats.
*/
@Nullable
public NodeIndicesStats getIndices() {
return indices();
}

/**
* Operating System level statistics.
*/
@Nullable
public OsStats os() {
return this.os;
}

/**
* Operating System level statistics.
*/
@Nullable
public OsStats getOs() {
return os();
}

/**
* Process level statistics.
*/
@Nullable
public ProcessStats process() {
return process;
}

/**
* Process level statistics.
*/
@Nullable
public ProcessStats getProcess() {
return process();
}

/**
* JVM level statistics.
*/
@Nullable
public JvmStats jvm() {
return jvm;
}

/**
* JVM level statistics.
*/
@Nullable
public JvmStats getJvm() {
return jvm();
}

/**
* Network level statistics.
*/
@Nullable
public NetworkStats network() {
return network;
}

/**
* Network level statistics.
*/
@Nullable
public NetworkStats getNetwork() {
return network();
}

@Nullable
public TransportStats transport() {
return this.transport;
}

@Nullable
public TransportStats getTransport() {
return transport();
}

@Nullable
public HttpStats http() {
return this.http;
}

@Nullable
public HttpStats getHttp() {
return http();
}
Expand All @@ -166,6 +199,9 @@ public static NodeStats readNodeStats(StreamInput in) throws IOException {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.readBoolean()) {
hostname = in.readUTF();
}
if (in.readBoolean()) {
indices = NodeIndicesStats.readIndicesStats(in);
}
Expand All @@ -192,6 +228,12 @@ public void readFrom(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (hostname == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(hostname);
}
if (indices == null) {
out.writeBoolean(false);
} else {
Expand Down
Expand Up @@ -20,14 +20,24 @@
package org.elasticsearch.action.admin.cluster.node.stats;

import org.elasticsearch.action.support.nodes.NodesOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

/**
* A request to get node (cluster) level stats.
*
*
*/
public class NodesStatsRequest extends NodesOperationRequest {

private boolean indices = true;
private boolean os;
private boolean process;
private boolean jvm;
private boolean network;
private boolean transport;
private boolean http;

protected NodesStatsRequest() {
}

Expand All @@ -38,4 +48,148 @@ protected NodesStatsRequest() {
public NodesStatsRequest(String... nodesIds) {
super(nodesIds);
}

/**
* Clears all the request flags.
*/
public NodesStatsRequest clear() {
this.indices = false;
this.os = false;
this.process = false;
this.jvm = false;
this.network = false;
this.transport = false;
this.http = false;
return this;
}

/**
* Should indices stats be returned.
*/
public boolean indices() {
return this.indices;
}

/**
* Should indices stats be returned.
*/
public NodesStatsRequest indices(boolean indices) {
this.indices = indices;
return this;
}

/**
* Should the node OS be returned.
*/
public boolean os() {
return this.os;
}

/**
* Should the node OS be returned.
*/
public NodesStatsRequest os(boolean os) {
this.os = os;
return this;
}

/**
* Should the node Process be returned.
*/
public boolean process() {
return this.process;
}

/**
* Should the node Process be returned.
*/
public NodesStatsRequest process(boolean process) {
this.process = process;
return this;
}

/**
* Should the node JVM be returned.
*/
public boolean jvm() {
return this.jvm;
}

/**
* Should the node JVM be returned.
*/
public NodesStatsRequest jvm(boolean jvm) {
this.jvm = jvm;
return this;
}

/**
* Should the node Network be returned.
*/
public boolean network() {
return this.network;
}

/**
* Should the node Network be returned.
*/
public NodesStatsRequest network(boolean network) {
this.network = network;
return this;
}

/**
* Should the node Transport be returned.
*/
public boolean transport() {
return this.transport;
}

/**
* Should the node Transport be returned.
*/
public NodesStatsRequest transport(boolean transport) {
this.transport = transport;
return this;
}

/**
* Should the node HTTP be returned.
*/
public boolean http() {
return this.http;
}

/**
* Should the node HTTP be returned.
*/
public NodesStatsRequest http(boolean http) {
this.http = http;
return this;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = in.readBoolean();
os = in.readBoolean();
process = in.readBoolean();
jvm = in.readBoolean();
network = in.readBoolean();
transport = in.readBoolean();
http = in.readBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(indices);
out.writeBoolean(os);
out.writeBoolean(process);
out.writeBoolean(jvm);
out.writeBoolean(network);
out.writeBoolean(transport);
out.writeBoolean(http);
}

}

0 comments on commit 4464fe1

Please sign in to comment.