From 5cd8b678013e810e53e71f12a64067a30efe5300 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Sun, 21 May 2023 12:56:29 +0200 Subject: Add storage to top --- lib/subcommands/top.bash | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/subcommands/top.bash b/lib/subcommands/top.bash index bef8bca..7763eba 100644 --- a/lib/subcommands/top.bash +++ b/lib/subcommands/top.bash @@ -11,9 +11,10 @@ subcommand() declare -A results declare -A widths=( - [node]=0 - [memory]=0 [load]=0 + [memory]=0 + [node]=0 + [storage]=0 [uptime]=0 ) @@ -57,11 +58,13 @@ subcommand() do node_load="$(grep '^load' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" node_memory="$(grep '^memory' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" + node_storage="$(grep '^storage' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" node_uptime="$(grep '^uptime' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" width_load="$(wc -c <<< "$node_load")" width_memory="$(wc -c <<< "$node_memory")" width_node="$(wc -c <<< "$node")" + width_storage="$(wc -c <<< "$node_storage")" width_uptime="$(wc -c <<< "$node_uptime")" if (( widths[load] < width_load )) @@ -79,27 +82,32 @@ subcommand() widths[node]=$width_node fi + if (( widths[storage] < width_storage )) + then + widths[storage]=$width_storage + fi + if (( widths[uptime] < width_uptime )) then widths[uptime]=$width_uptime fi done - printstr="%-${widths[node]}s %${widths[load]}s %${widths[memory]}s %${widths[uptime]}s\n" - # Print results - printf "$printstr" \ + printf "%-${widths[node]}s %-${widths[load]}s %-${widths[memory]}s %-${widths[storage]}s %-${widths[uptime]}s\n" \ "Node" \ "Load" \ "Memory" \ + "Storage" \ "Uptime" for node in "${!results[@]}" do - printf "$printstr" \ + printf "%-${widths[node]}s %-${widths[load]}s %${widths[memory]}s %${widths[storage]}s %${widths[uptime]}s\n" \ "$node" \ "$(grep '^load' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" \ "$(grep '^memory' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" \ + "$(grep '^storage' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" \ "$(grep '^uptime' <<< "${results["$node"]}" | sed 's/[^ ]* *//')" - done + done | sort } -- cgit v1.1