From a156ccd80ed7ef2dcc26b2ff1e9b6c9d5a831092 Mon Sep 17 00:00:00 2001 From: Andreas Gebhardt Date: Wed, 28 Jun 2017 18:20:20 +0200 Subject: [PATCH] Expand `/_cat/nodes` to return information about hard drive (#21775) Expand `/_cat/nodes` with already present information about available disk space `diskAvail` (alias: `d`, `disk`) by: * `diskTotal` (alias `dt`): total disk space * `diskUsed` (alias `du`): used disk space (`diskTotal - diskAvail`) * `diskUsedPercent` (alias `dup`): used disk space percentage Note: The available disk space is the number of bytes available to the node's Java virtual machine. The size might be smaller than the real one. That means the used disk space (percentage) is larger. Closes #21679 --- .../rest/action/cat/RestNodesAction.java | 14 +++++++- docs/reference/cat/nodes.asciidoc | 5 ++- .../rest-api-spec/test/cat.nodes/10_basic.yml | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index 104ffe420abde..07f39b54f613a 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.http.HttpInfo; import org.elasticsearch.index.cache.query.QueryCacheStats; import org.elasticsearch.index.cache.request.RequestCacheStats; @@ -124,7 +125,10 @@ protected Table getTableWithHeader(final RestRequest request) { table.addCell("version", "default:false;alias:v;desc:es version"); 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("disk.total", "default:false;alias:dt,diskTotal;text-align:right;desc:total disk space"); + table.addCell("disk.used", "default:false;alias:du,diskUsed;text-align:right;desc:used disk space"); + table.addCell("disk.avail", "default:false;alias:d,da,disk,diskAvail;text-align:right;desc:available disk space"); + table.addCell("disk.used_percent", "default:false;alias:dup,diskUsedPercent;text-align:right;desc:used disk space percentage"); 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"); @@ -267,7 +271,15 @@ private Table buildTable(boolean fullId, RestRequest req, ClusterStateResponse s table.addCell(node.getVersion().toString()); table.addCell(info == null ? null : info.getBuild().shortHash()); table.addCell(jvmInfo == null ? null : jvmInfo.version()); + + long diskTotal = fsInfo.getTotal().getTotal().getBytes(); + long diskUsed = diskTotal - fsInfo.getTotal().getAvailable().getBytes(); + double diskUsedRatio = diskTotal == 0 ? 1.0 : (double) diskUsed / diskTotal; + table.addCell(fsInfo == null ? null : fsInfo.getTotal().getTotal()); + table.addCell(fsInfo == null ? null : new ByteSizeValue(diskUsed)); table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable()); + table.addCell(fsInfo == null ? null : String.format(Locale.ROOT, "%.2f", 100.0 * diskUsedRatio)); + table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed()); table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsedPercent()); table.addCell(jvmInfo == null ? null : jvmInfo.getMem().getHeapMax()); diff --git a/docs/reference/cat/nodes.asciidoc b/docs/reference/cat/nodes.asciidoc index 1dbcd4553512a..95621110916f0 100644 --- a/docs/reference/cat/nodes.asciidoc +++ b/docs/reference/cat/nodes.asciidoc @@ -71,7 +71,10 @@ veJR 127.0.0.1 59938 {version} * |`version` |`v` |No |Elasticsearch version |{version} |`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 +|`disk.total` |`dt`, `diskTotal` |No |Total disk space| 458.3gb +|`disk.used` |`du`, `diskUsed` |No |Used disk space| 259.8gb +|`disk.avail` |`d`, `disk`, `diskAvail` |No |Available disk space |198.4gb +|`disk.used_percent` |`dup`, `diskUsedPercent` |No |Used disk space percentage |56.71 |`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 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yml index f48f73cb478ef..e1225ef5da681 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yml @@ -58,6 +58,38 @@ $body: | /^ http \n ((\d{1,3}\.){3}\d{1,3}:\d{1,5}\n)+ $/ +--- +"Additional disk information": + - skip: + version: " - 5.5.99" + reason: additional disk info added in 5.6.0 + + - do: + cat.nodes: + h: diskAvail,diskTotal,diskUsed,diskUsedPercent + v: true + + - match: + # leading whitespace on columns and optional whitespace on values is necessary + # because `diskAvail` is right aligned and text representation of disk size might be + # longer so it's padded with leading whitespace + $body: | + /^ \s* diskAvail \s+ diskTotal \s+ diskUsed \s+ diskUsedPercent \n + (\s* \d+(\.\d+)?[ptgmk]?b \s+ \d+(\.\d+)?[ptgmk]?b \s+ \d+(\.\d+)?[ptgmk]?b\s+ (100\.00 | \d{1,2}\.\d{2}) \n)+ $/ + + - do: + cat.nodes: + h: disk,dt,du,dup + v: true + + - match: + # leading whitespace on columns and optional whitespace on values is necessary + # because `disk` is right aligned and text representation of disk size might be + # longer so it's padded with leading whitespace + $body: | + /^ \s* disk \s+ dt \s+ du \s+ dup \n + (\s* \d+(\.\d+)?[ptgmk]?b \s+ \d+(\.\d+)?[ptgmk]?b \s+ \d+(\.\d+)?[ptgmk]?b\s+ (100\.00 | \d{1,2}\.\d{2}) \n)+ $/ + --- "Test cat nodes output with full_id set": - skip: