k8s-widget: fix metrics aggregation for multi-replica apps
This commit is contained in:
@@ -84,8 +84,8 @@ while IFS= read -r line; do
|
||||
[[ -z "$app" ]] && continue
|
||||
cpu_m=$(normalize_cpu "$cpu_str")
|
||||
mem_mib=$(normalize_mem "$mem_str")
|
||||
top_cpu["$app"]=$cpu_m
|
||||
top_mem["$app"]=$mem_mib
|
||||
top_cpu["$app"]=$(( ${top_cpu[$app]:-0} + cpu_m ))
|
||||
top_mem["$app"]=$(( ${top_mem[$app]:-0} + mem_mib ))
|
||||
cpu_actual=$(( cpu_actual + cpu_m ))
|
||||
mem_actual=$(( mem_actual + mem_mib ))
|
||||
done <<< "$top_output"
|
||||
@@ -102,7 +102,7 @@ while IFS= read -r line; do
|
||||
pod_metrics+=$(jq -nc --arg app "$app" --argjson cpu "$cpu_m" --argjson mem "$mem_mib" \
|
||||
'{app: $app, cpuM: $cpu, memMi: $mem}')
|
||||
first=0
|
||||
done < <(echo "$pods_json" | jq -c '.items[] | {app: (.metadata.labels["app.kubernetes.io/instance"] // .metadata.name)}')
|
||||
done < <(echo "$pods_json" | jq -c '[.items[] | {app: (.metadata.labels["app.kubernetes.io/instance"] // .metadata.name)}] | unique_by(.app)[]')
|
||||
pod_metrics+="]"
|
||||
|
||||
# ── Parse resourcequota ──────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user