From 256605f065b7f9b876b5831c52a6bf554c474dd9 Mon Sep 17 00:00:00 2001 From: Andrew Raines Date: Wed, 30 Oct 2013 13:47:29 -0500 Subject: [PATCH] Add heap used percentage to _cat/nodes. Closes #4020. --- .../rest/action/cat/RestNodesAction.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index 52d096727bf..0f9d070423d 100644 --- a/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -41,6 +41,7 @@ import org.elasticsearch.rest.action.support.RestTable; import java.io.IOException; import java.util.Iterator; +import java.util.Locale; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -122,9 +123,11 @@ public class RestNodesAction extends BaseRestHandler { table.addCell("port"); table.addCell("jdk"); - table.addCell("diskfree", "text-align:right;"); - table.addCell("heapmax", "text-align:right;"); - table.addCell("memmax", "text-align:right;"); + table.addCell("diskAvail", "text-align:right;"); + table.addCell("heapUsed", "text-align:right;"); + table.addCell("heapMax", "text-align:right;"); + table.addCell("heapRatio", "text-align:right;"); + table.addCell("ramMax", "text-align:right;"); table.addCell("uptime", "text-align:right;"); table.addCell("data/client"); @@ -135,6 +138,15 @@ public class RestNodesAction extends BaseRestHandler { for (DiscoveryNode node : state.getState().nodes()) { NodeInfo info = nodesInfo.getNodesMap().get(node.id()); NodeStats stats = nodesStats.getNodesMap().get(node.id()); + + long heapUsed = stats.getJvm().mem().heapUsed().bytes(); + long heapMax = info.getJvm().mem().heapMax().bytes(); + float heapRatio = -1.0f; + + if (heapMax > 0) { + heapRatio = heapUsed / (heapMax * 1.0f); + } + long availableDisk = -1; if (!(stats.getFs() == null)) { @@ -153,7 +165,9 @@ public class RestNodesAction extends BaseRestHandler { table.addCell(((InetSocketTransportAddress) node.address()).address().getPort()); table.addCell(info.getJvm().version()); table.addCell(availableDisk < 0 ? null : ByteSizeValue.parseBytesSizeValue(new Long(availableDisk).toString())); - table.addCell(info.getJvm().mem().heapMax()); + table.addCell(new ByteSizeValue(heapUsed)); + table.addCell(new ByteSizeValue(heapMax)); + 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(stats.getJvm().uptime()); table.addCell(node.clientNode() ? "c" : node.dataNode() ? "d" : null);