gistfile1.txt
· 1.4 KiB · Text
原始文件
log::error "Service not found: ${filter_service}"
return 1
fi
fi
[[ -n "$filter_ip" ]] && service_ip="$filter_ip"
# Fetch aggregated data
local data
data=$(json::activity_aggregate \
"$(ctx::fw_events_log)" \
"$(ctx::events_log)" \
"$(config::interface)" \
"$(ctx::net)" \
"$(ctx::clients)" \
"$(ctx::meta)" \
"$hours" \
"$filter_peer" \
"$service_ip" 2>/dev/null)
if [[ -z "$data" ]]; then
log::wg_warning "No activity data found"
return 0
fi
# Measure column widths
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 column where drop count starts on peer row:
# " " (2) + name (w_peer) + " ↓" (3) + rx (10) + " ↑" (3) + tx (10) + " " (2)
# ↓ and ↑ are multi-byte (3 bytes, 1 visible) — 2 extra bytes each
# Visible: 2 + w_peer + 2+1 + 10 + 2+1 + 10 + 2 = w_peer + 30
local drops_col=$(( w_peer + 30 ))
| 1 | log::error "Service not found: ${filter_service}" |
| 2 | return 1 |
| 3 | fi |
| 4 | fi |
| 5 | [[ -n "$filter_ip" ]] && service_ip="$filter_ip" |
| 6 | |
| 7 | # Fetch aggregated data |
| 8 | local data |
| 9 | data=$(json::activity_aggregate \ |
| 10 | "$(ctx::fw_events_log)" \ |
| 11 | "$(ctx::events_log)" \ |
| 12 | "$(config::interface)" \ |
| 13 | "$(ctx::net)" \ |
| 14 | "$(ctx::clients)" \ |
| 15 | "$(ctx::meta)" \ |
| 16 | "$hours" \ |
| 17 | "$filter_peer" \ |
| 18 | "$service_ip" 2>/dev/null) |
| 19 | |
| 20 | if [[ -z "$data" ]]; then |
| 21 | log::wg_warning "No activity data found" |
| 22 | return 0 |
| 23 | fi |
| 24 | |
| 25 | # Measure column widths |
| 26 | local w_peer=16 w_drops=1 |
| 27 | while IFS='|' read -r type rest; do |
| 28 | case "$type" in |
| 29 | peer) |
| 30 | local name drops |
| 31 | name=$(echo "$rest" | cut -d'|' -f1) |
| 32 | drops=$(echo "$rest" | cut -d'|' -f4) |
| 33 | (( ${#name} > w_peer )) && w_peer=${#name} |
| 34 | (( ${#drops} > w_drops )) && w_drops=${#drops} |
| 35 | ;; |
| 36 | service) |
| 37 | local count |
| 38 | count=$(echo "$rest" | cut -d'|' -f3) |
| 39 | (( ${#count} > w_drops )) && w_drops=${#count} |
| 40 | ;; |
| 41 | esac |
| 42 | done <<< "$data" |
| 43 | |
| 44 | (( w_peer += 2 )) |
| 45 | |
| 46 | # Compute column where drop count starts on peer row: |
| 47 | # " " (2) + name (w_peer) + " ↓" (3) + rx (10) + " ↑" (3) + tx (10) + " " (2) |
| 48 | # ↓ and ↑ are multi-byte (3 bytes, 1 visible) — 2 extra bytes each |
| 49 | # Visible: 2 + w_peer + 2+1 + 10 + 2+1 + 10 + 2 = w_peer + 30 |
| 50 | local drops_col=$(( w_peer + 30 )) |
| 51 |