Skip to content

Commit

Permalink
Expand /_cat/nodes to return information about hard drive (#21775)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
agebhar1 authored and javanna committed Jun 28, 2017
1 parent 5f8be0e commit a156ccd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 4 additions & 1 deletion docs/reference/cat/nodes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a156ccd

Please sign in to comment.