aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2023-05-21 12:56:29 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-05-21 12:56:29 +0200
commit5cd8b678013e810e53e71f12a64067a30efe5300 (patch)
treee345049b7c8f21f1dae0a4e8ba1f1becc82b11d7
parent108f9685059c0aeae0e4cfdb538597902bd59b5e (diff)
Add storage to top
-rw-r--r--lib/subcommands/top.bash22
1 files 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
}