Commit f73aa239 authored by Vitaly Lipatov's avatar Vitaly Lipatov

router: check all gateways in group for health, not just first

Replace group_monitor_tag (first gateway only) with eval_group_health that checks all gateways. Group is healthy if any gateway is healthy, dead only if all are dead. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent ae0ecdcb
...@@ -84,16 +84,39 @@ gw_monitor_tag() ...@@ -84,16 +84,39 @@ gw_monitor_tag()
echo "$tag" echo "$tag"
} }
# Get monitor tag for a group directory # Evaluate health of all gateways in a group
# Usage: group_monitor_tag GWDIR ROUTES_DIR # Sets: group_status (healthy/degraded/dead), group_detail (display string)
group_monitor_tag() # Usage: eval_group_health GWDIR ROUTES_DIR
eval_group_health()
{ {
local gwdir="$1" routes_dir="$2" local gwdir="$1" routes_dir="$2"
local ipcmd=$(ipcmd_for "$routes_dir") local ipcmd=$(ipcmd_for "$routes_dir")
[ -f "$gwdir/gateway" ] || return group_status="" ; group_detail=""
parse_gw_line "$(read_value "$gwdir/gateway")" "$ipcmd" [ -f "$gwdir/gateway" ] || return 1
[ -n "$gw_ip" ] || return local any_healthy="" all_dead=1 checked=0
find_gw_monitor "$routes_dir" "$gw_ip" "$ipcmd" while IFS= read -r line ; do
[ -z "$line" ] && continue
echo "$line" | grep -q '^#' && continue
parse_gw_line "$line" "$ipcmd"
[ -n "$gw_ip" ] || continue
local tag=$(find_gw_monitor "$routes_dir" "$gw_ip" "$ipcmd")
[ -n "$tag" ] || continue
checked=$((checked + 1))
local st=$(get_health "$tag")
local loss=$(grep "^${tag} " "$HEALTH_DATA" | awk '{print $2}')
local ld="${loss:-no_data}%" ; [ -z "$loss" ] && ld="no_data"
group_detail="${group_detail:+$group_detail, }$tag=$ld($st)"
[ "$st" = "healthy" ] && any_healthy=1
[ "$st" != "dead" ] && all_dead=""
done < "$gwdir/gateway"
[ "$checked" -eq 0 ] && return 1
if [ -n "$any_healthy" ] ; then
group_status="healthy"
elif [ -n "$all_dead" ] ; then
group_status="dead"
else
group_status="degraded"
fi
} }
# Find monitor tag for a gateway IP: first check group monitor files, # Find monitor tag for a gateway IP: first check group monitor files,
...@@ -157,19 +180,13 @@ for routes_dir in "$ROUTES_DIR" "$ROUTES6_DIR" ; do ...@@ -157,19 +180,13 @@ for routes_dir in "$ROUTES_DIR" "$ROUTES6_DIR" ; do
[ -d "$gwdir" ] || continue [ -d "$gwdir" ] || continue
name=$(basename "$gwdir") name=$(basename "$gwdir")
tag=$(group_monitor_tag "$gwdir" "$routes_dir") eval_group_health "$gwdir" "$routes_dir" || continue
[ -n "$tag" ] || continue
status=$(get_health "$tag")
loss=$(grep "^${tag} " "$HEALTH_DATA" | awk '{print $2}')
loss_display="${loss:-no_data}%"
[ -z "$loss" ] && loss_display="no_data"
state_path="$routes_dir/$name" state_path="$routes_dir/$name"
[ -n "$SHOW" ] && log "[$name] $tag: loss=$loss_display -> $status" [ -n "$SHOW" ] && log "[$name] $group_detail -> $group_status"
case "$status" in case "$group_status" in
healthy) healthy)
healthy_count=$((healthy_count + 1)) healthy_count=$((healthy_count + 1))
healthy_groups="${healthy_groups:+$healthy_groups }$state_path" healthy_groups="${healthy_groups:+$healthy_groups }$state_path"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment