gistfile1.txt
· 1.9 KiB · Text
Ham
sed -n '/^ local w_peer/,/^function cmd::/p' \
/etc/wireguard/wgctl/commands/activity.command.sh | head -60
local w_peer=16 w_drops=1
while IFS='|' read -r type rest; do
case "$type" in
peer)
local name drops
name=$(echo "$rest" | cut -d'|' -f1)
drops=$(echo "$rest" | cut -d'|' -f4)
(( ${#name} > w_peer )) && w_peer=${#name}
(( ${#drops} > w_drops )) && w_drops=${#drops}
;;
service)
local count
count=$(echo "$rest" | cut -d'|' -f3)
(( ${#count} > w_drops )) && w_drops=${#count}
;;
esac
done <<< "$data"
(( w_peer += 2 ))
# Compute exact column where drop count starts on peer row:
# " " (2) + name (w_peer) + " ↓" (3) + rx (10) + " ↑" (3) + tx (10) + " " (2)
# Note: ↓ and ↑ are multi-byte (3 bytes) but display as 1 char — account for 2 extra bytes each
# Visible: 2 + w_peer + 2+1 + 10 + 2+1 + 10 + 2 = w_peer + 30
local drops_col=$(( w_peer + 30 ))
local hours_display="${hours}h"
[[ "$hours" == "0" ]] && hours_display="all time"
log::section "Activity Monitor (last ${hours_display})"
echo ""
local first_peer=true skip_peer=false
while IFS='|' read -r record_type rest; do
case "$record_type" in
peer)
local name rx tx drops
IFS='|' read -r name rx tx drops <<< "$rest"
skip_peer=false
if $dropped_only && [[ "$drops" -eq 0 ]]; then
skip_peer=true
continue
fi
$first_peer || echo ""
first_peer=false
local rx_fmt tx_fmt
rx_fmt=$(cmd::activity::_fmt_bytes "$rx")
tx_fmt=$(cmd::activity::_fmt_bytes "$tx")
local name_pad rx_pad tx_pad
name_pad=$(printf "%-${w_peer}s" "$name")
rx_pad=$(printf "%-10s" "$rx_fmt")
tx_pad=$(printf "%-10s" "$tx_fmt")
local drop_word="drops"
[[ "$drops" -eq 1 ]] && drop_word="drop"
| 1 | sed -n '/^ local w_peer/,/^function cmd::/p' \ |
| 2 | /etc/wireguard/wgctl/commands/activity.command.sh | head -60 |
| 3 | local w_peer=16 w_drops=1 |
| 4 | while IFS='|' read -r type rest; do |
| 5 | case "$type" in |
| 6 | peer) |
| 7 | local name drops |
| 8 | name=$(echo "$rest" | cut -d'|' -f1) |
| 9 | drops=$(echo "$rest" | cut -d'|' -f4) |
| 10 | (( ${#name} > w_peer )) && w_peer=${#name} |
| 11 | (( ${#drops} > w_drops )) && w_drops=${#drops} |
| 12 | ;; |
| 13 | service) |
| 14 | local count |
| 15 | count=$(echo "$rest" | cut -d'|' -f3) |
| 16 | (( ${#count} > w_drops )) && w_drops=${#count} |
| 17 | ;; |
| 18 | esac |
| 19 | done <<< "$data" |
| 20 | |
| 21 | (( w_peer += 2 )) |
| 22 | |
| 23 | # Compute exact column where drop count starts on peer row: |
| 24 | # " " (2) + name (w_peer) + " ↓" (3) + rx (10) + " ↑" (3) + tx (10) + " " (2) |
| 25 | # Note: ↓ and ↑ are multi-byte (3 bytes) but display as 1 char — account for 2 extra bytes each |
| 26 | # Visible: 2 + w_peer + 2+1 + 10 + 2+1 + 10 + 2 = w_peer + 30 |
| 27 | local drops_col=$(( w_peer + 30 )) |
| 28 | |
| 29 | local hours_display="${hours}h" |
| 30 | [[ "$hours" == "0" ]] && hours_display="all time" |
| 31 | |
| 32 | log::section "Activity Monitor (last ${hours_display})" |
| 33 | echo "" |
| 34 | |
| 35 | local first_peer=true skip_peer=false |
| 36 | |
| 37 | while IFS='|' read -r record_type rest; do |
| 38 | case "$record_type" in |
| 39 | peer) |
| 40 | local name rx tx drops |
| 41 | IFS='|' read -r name rx tx drops <<< "$rest" |
| 42 | |
| 43 | skip_peer=false |
| 44 | if $dropped_only && [[ "$drops" -eq 0 ]]; then |
| 45 | skip_peer=true |
| 46 | continue |
| 47 | fi |
| 48 | |
| 49 | $first_peer || echo "" |
| 50 | first_peer=false |
| 51 | |
| 52 | local rx_fmt tx_fmt |
| 53 | rx_fmt=$(cmd::activity::_fmt_bytes "$rx") |
| 54 | tx_fmt=$(cmd::activity::_fmt_bytes "$tx") |
| 55 | |
| 56 | local name_pad rx_pad tx_pad |
| 57 | name_pad=$(printf "%-${w_peer}s" "$name") |
| 58 | rx_pad=$(printf "%-10s" "$rx_fmt") |
| 59 | tx_pad=$(printf "%-10s" "$tx_fmt") |
| 60 | |
| 61 | local drop_word="drops" |
| 62 | [[ "$drops" -eq 1 ]] && drop_word="drop" |
| 63 |