_cat/nodes improvements.

* Handle info/stats null possibilities if cluster is in duress.

* Shorten node id.
This commit is contained in:
Andrew Raines 2013-11-01 17:33:54 -05:00
parent 928ac2e3b7
commit 7d2c4afa98
1 changed files with 27 additions and 24 deletions

View File

@ -117,7 +117,7 @@ public class RestNodesAction extends BaseRestHandler {
Table table = new Table(); Table table = new Table();
table.startHeaders(); table.startHeaders();
table.addCell("id"); table.addCell("nodeId");
table.addCell("pid"); table.addCell("pid");
table.addCell("ip"); table.addCell("ip");
table.addCell("port"); table.addCell("port");
@ -133,23 +133,25 @@ public class RestNodesAction extends BaseRestHandler {
table.addCell("uptime", "text-align:right;"); table.addCell("uptime", "text-align:right;");
table.addCell("data/client"); table.addCell("data/client");
table.addCell("master"); table.addCell("master");
table.addCell("node"); table.addCell("name");
table.endHeaders(); table.endHeaders();
for (DiscoveryNode node : state.getState().nodes()) { for (DiscoveryNode node : state.getState().nodes()) {
NodeInfo info = nodesInfo.getNodesMap().get(node.id()); NodeInfo info = nodesInfo.getNodesMap().get(node.id());
NodeStats stats = nodesStats.getNodesMap().get(node.id()); NodeStats stats = nodesStats.getNodesMap().get(node.id());
long availableDisk = -1;
long heapUsed = stats.getJvm().mem().heapUsed().bytes(); long heapUsed = -1;
long heapMax = info.getJvm().mem().heapMax().bytes(); long heapMax = -1;
float heapRatio = -1.0f; float heapRatio = -1.0f;
if (null != stats && null != info) {
heapUsed = stats.getJvm().mem().heapUsed().bytes();
heapMax = info.getJvm().mem().heapMax().bytes();
if (heapMax > 0) { if (heapMax > 0) {
heapRatio = heapUsed / (heapMax * 1.0f); heapRatio = heapUsed / (heapMax * 1.0f);
} }
long availableDisk = -1;
if (!(stats.getFs() == null)) { if (!(stats.getFs() == null)) {
availableDisk = 0; availableDisk = 0;
Iterator<FsStats.Info> it = stats.getFs().iterator(); Iterator<FsStats.Info> it = stats.getFs().iterator();
@ -157,21 +159,22 @@ public class RestNodesAction extends BaseRestHandler {
availableDisk += it.next().getAvailable().bytes(); availableDisk += it.next().getAvailable().bytes();
} }
} }
}
table.startRow(); table.startRow();
table.addCell(node.id()); table.addCell(node.id().substring(0, 4));
table.addCell(info.getProcess().id()); table.addCell(info == null ? null : info.getProcess().id());
table.addCell(((InetSocketTransportAddress) node.address()).address().getAddress().getHostAddress()); table.addCell(((InetSocketTransportAddress) node.address()).address().getAddress().getHostAddress());
table.addCell(((InetSocketTransportAddress) node.address()).address().getPort()); table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
table.addCell(info.getVersion().number()); table.addCell(info == null ? null : info.getVersion().number());
table.addCell(info.getJvm().version()); table.addCell(info == null ? null : info.getJvm().version());
table.addCell(availableDisk < 0 ? null : ByteSizeValue.parseBytesSizeValue(new Long(availableDisk).toString())); table.addCell(availableDisk < 0 ? null : ByteSizeValue.parseBytesSizeValue(new Long(availableDisk).toString()));
table.addCell(new ByteSizeValue(heapUsed)); table.addCell(heapUsed < 0 ? null : new ByteSizeValue(heapUsed));
table.addCell(new ByteSizeValue(heapMax)); table.addCell(heapMax < 0 ? null : new ByteSizeValue(heapMax));
table.addCell(heapRatio < 0 ? null : String.format(Locale.ROOT, "%.1f%%", heapRatio*100.0)); table.addCell(heapRatio < 0 ? null : String.format(Locale.ROOT, "%.1f%%", heapRatio*100.0));
table.addCell(info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ table.addCell(info == null ? null : info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ
table.addCell(stats.getJvm().uptime()); table.addCell(stats == null ? null : stats.getJvm().uptime());
table.addCell(node.clientNode() ? "c" : node.dataNode() ? "d" : null); table.addCell(node.clientNode() ? "c" : node.dataNode() ? "d" : null);
table.addCell(masterId.equals(node.id()) ? "*" : node.masterNode() ? "m" : null); table.addCell(masterId.equals(node.id()) ? "*" : node.masterNode() ? "m" : null);
table.addCell(node.name()); table.addCell(node.name());