nuno hat die Gist bearbeitet 1 month ago. Zu Änderung gehen
1 file changed, 62 insertions
gistfile1.txt(Datei erstellt)
| @@ -0,0 +1,62 @@ | |||
| 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" | |
Neuer
Älter