diff --git a/docs/reference/cat/nodes.asciidoc b/docs/reference/cat/nodes.asciidoc index ba4e6847cd2..72ab7bb842c 100644 --- a/docs/reference/cat/nodes.asciidoc +++ b/docs/reference/cat/nodes.asciidoc @@ -90,10 +90,18 @@ k0zy 192.168.56.10 9300 {version} m |`build` |`b` |No |Elasticsearch Build hash |5c03844 |`jdk` |`j` |No |Running Java version |1.8.0 |`disk.avail` |`d`, `disk`, `diskAvail` |No |Available disk space |1.8gb -|`heap.percent` |`hp`, `heapPercent` |No |Used heap percentage |7 +|`heap.current` |`hc`, `heapCurrent` |No |Used heap |311.2mb +|`heap.percent` |`hp`, `heapPercent` |Yes |Used heap percentage |7 |`heap.max` |`hm`, `heapMax` |No |Maximum configured heap |1015.6mb -|`ram.percent` |`rp`, `ramPercent` |No |Used total memory percentage |47 +|`ram.current` |`rc`, `ramCurrent` |No |Used total memory |513.4mb +|`ram.percent` |`rp`, `ramPercent` |Yes |Used total memory percentage |47 |`ram.max` |`rm`, `ramMax` |No |Total memory |2.9gb +|`file_desc.current` |`fdc`, `fileDescriptorCurrent` |No |Used file +descriptors |123 +|`file_desc.percent` |`fdp`, `fileDescriptorPercent` |Yes |Used file +descriptors percentage |1 +|`file_desc.max` |`fdm`, `fileDescriptorMax` |No |Maximum number of file +descriptors |1024 |`load` |`l` |No |Most recent load average |0.22 |`uptime` |`u` |No |Node uptime |17.3m |`node.role` |`r`, `role`, `dc`, `nodeRole` |Yes |Data node (d); Client diff --git a/rest-api-spec/test/cat.nodes/10_basic.yaml b/rest-api-spec/test/cat.nodes/10_basic.yaml new file mode 100755 index 00000000000..5ff4e67310f --- /dev/null +++ b/rest-api-spec/test/cat.nodes/10_basic.yaml @@ -0,0 +1,39 @@ +--- +"Test cat nodes output": + + - do: + cat.nodes: {} + + - match: + $body: | + / #host ip heap.percent ram.percent load node.role master name + ^ (\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d* \s+ \d* \s+ [-dc] \s+ [-*mx] \s+ \S+ \s+ \n)+ $/ + + - do: + cat.nodes: + v: true + + - match: + $body: | + /^ host \s+ ip \s+ heap\.percent \s+ ram\.percent \s+ load \s+ node\.role \s+ master \s+ name \s+ \n + (\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d* \s+ \d* \s+ [-dc] \s+ [-*mx] \s+ \S+ \s+ \n)+ $/ + + - do: + cat.nodes: + h: heap.current,heap.percent,heap.max + v: true + + - match: + $body: | + /^ heap\.current \s+ heap\.percent \s+ heap\.max \s+ \n + (\s+ \d+(\.\d+)?[ptgmk]?b \s+ \d+ \s+ \d+(\.\d+)?[ptgmk]?b \s+ \n)+ $/ + + - do: + cat.nodes: + h: file_desc.current,file_desc.percent,file_desc.max + v: true + + - match: + $body: | + /^ file_desc\.current \s+ file_desc\.percent \s+ file_desc\.max \s+ \n + (\s+ \d+ \s+ \d+ \s+ \d+ \s+ \n)+ $/ 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 09c5182b2b4..50028897925 100644 --- a/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -73,7 +73,7 @@ public class RestNodesAction extends AbstractCatAction { @Override public void processResponse(final NodesInfoResponse nodesInfoResponse) { NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(); - nodesStatsRequest.clear().jvm(true).os(true).fs(true).indices(true); + nodesStatsRequest.clear().jvm(true).os(true).fs(true).indices(true).process(true); client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener(channel) { @Override public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception { @@ -100,10 +100,15 @@ public class RestNodesAction extends AbstractCatAction { table.addCell("build", "default:false;alias:b;desc:es build hash"); table.addCell("jdk", "default:false;alias:j;desc:jdk version"); table.addCell("disk.avail", "default:false;alias:d,disk,diskAvail;text-align:right;desc:available disk space"); + table.addCell("heap.current", "default:false;alias:hc,heapCurrent;text-align:right;desc:used heap"); table.addCell("heap.percent", "alias:hp,heapPercent;text-align:right;desc:used heap ratio"); table.addCell("heap.max", "default:false;alias:hm,heapMax;text-align:right;desc:max configured heap"); + table.addCell("ram.current", "default:false;alias:rc,ramCurrent;text-align:right;desc:used machine memory"); table.addCell("ram.percent", "alias:rp,ramPercent;text-align:right;desc:used machine memory ratio"); table.addCell("ram.max", "default:false;alias:rm,ramMax;text-align:right;desc:total machine memory"); + table.addCell("file_desc.current", "default:false;alias:fdc,fileDescriptorCurrent;text-align:right;desc:used file descriptors"); + table.addCell("file_desc.percent", "default:false;alias:fdp,fileDescriptorPercent;text-align:right;desc:used file descriptor ratio"); + table.addCell("file_desc.max", "default:false;alias:fdm,fileDescriptorMax;text-align:right;desc:max file descriptors"); table.addCell("load", "alias:l;text-align:right;desc:most recent load avg"); table.addCell("uptime", "default:false;alias:u;text-align:right;desc:node uptime"); @@ -211,10 +216,16 @@ public class RestNodesAction extends AbstractCatAction { table.addCell(info == null ? null : info.getBuild().hashShort()); table.addCell(info == null ? null : info.getJvm().version()); table.addCell(stats == null ? null : stats.getFs() == null ? null : stats.getFs().total().getAvailable()); + table.addCell(stats == null ? null : stats.getJvm().getMem().getHeapUsed()); table.addCell(stats == null ? null : stats.getJvm().getMem().getHeapUsedPrecent()); table.addCell(info == null ? null : info.getJvm().getMem().getHeapMax()); + table.addCell(stats == null ? null : stats.getOs().mem() == null ? null : stats.getOs().mem().used()); table.addCell(stats == null ? null : stats.getOs().mem() == null ? null : stats.getOs().mem().usedPercent()); table.addCell(info == null ? null : info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ + table.addCell(stats == null ? null : stats.getProcess().getOpenFileDescriptors()); + table.addCell(stats == null || info == null ? null : + calculatePercentage(stats.getProcess().getOpenFileDescriptors(), info.getProcess().getMaxFileDescriptors())); + table.addCell(info == null ? null : info.getProcess().getMaxFileDescriptors()); table.addCell(stats == null ? null : stats.getOs() == null ? null : stats.getOs().getLoadAverage().length < 1 ? null : String.format(Locale.ROOT, "%.2f", stats.getOs().getLoadAverage()[0])); table.addCell(stats == null ? null : stats.getJvm().uptime()); @@ -296,4 +307,14 @@ public class RestNodesAction extends AbstractCatAction { return table; } + + /** + * Calculate the percentage of {@code used} from the {@code max} number. + * @param used The currently used number. + * @param max The maximum number. + * @return 0 if {@code max} is 0. Otherwise 100 * {@code used} / {@code max}. + */ + private short calculatePercentage(long used, long max) { + return max == 0 ? 0 : (short)((100d * used) / max); + } }