check_concentrator: Power(N) ON count; per-port mA, V, W columns.

- Summary line uses Power(N) where N is ports with metrics power ON.
- Port table drops Pwr column; add W column; widen mA; remove executable bit drift.

Made-with: Cursor
This commit is contained in:
Robert McMahon 2026-04-03 15:01:03 -07:00
parent 3ea65d9271
commit 442774b976
1 changed files with 19 additions and 12 deletions

View File

@ -5,8 +5,8 @@ metrics tables covering **this machine** and each configured **remote**. The con
has **Location** (``local`` or remote IP/hostname, plus **tty** names when known) and **USB**
(Bus/Device, VID:PID, product from sysfs). The per-port table starts with **Panel** (``fiber_ports``
key / rack position when ``hub``, ``port``, and optional ``ssh`` match this run), rows sorted by panel
number; a **Power: Total W / mA (per port follows)** line heads the section, then the column header
and rows.
number; a **Power(N): Total W / mA (per port follows)** line heads the section (``N`` = ports with
``power`` ON), then columns **mA**, **V**, **W**, and **Location**.
(no USB column).
Adnacom PCIe catalog last.
@ -55,8 +55,8 @@ _CONSOLIDATED_HUB_HDR = (
f"{'#':<4} | {'Serial':<12} | {'Ports':<10} | {'Location':<28} | USB (Bus / ID / product)"
)
_PER_PORT_PWR_HDR = (
f"{'Panel':<8} | {'Hub#':<4} | {'Serial':<12} | {'Pt':<3} | {'Pwr':<5} | "
f"{'mA':>8} | {'V':>8} | Location"
f"{'Panel':<8} | {'Hub#':<4} | {'Serial':<12} | {'Pt':<3} | "
f"{'mA':>10} | {'V':>8} | {'W':>10} | Location"
)
_HUB_TABLE_ROW_RE = re.compile(
@ -693,7 +693,8 @@ def _print_per_port_power_table(
base_rc: int,
) -> int:
"""
``Power: Total `` line, then per-port current (mA), voltage (V), and Location (sorted by panel).
``Power(N): Total `` line (``N`` = count of ports reporting power ON), then per-port **mA**, **V**,
**W**, and Location (sorted by panel).
Returns ``base_rc`` ORd with failure if any ``port-metrics-json`` remote call fails.
"""
rc = base_rc
@ -729,6 +730,7 @@ def _print_per_port_power_table(
n_ma = 0
total_power_w = 0.0
n_power = 0
n_on = 0
for row in hub_rows:
sn_key = _norm_hub_serial(row.serial)
if row.ssh_target is None:
@ -740,10 +742,12 @@ def _print_per_port_power_table(
m = by_port.get(port)
cur_f: float | None = None
v_f: float | None = None
w_s = ""
if m is None:
pwr, ma_s, v_s = "?", "", ""
ma_s, v_s = "", ""
else:
pwr = str(m.get("power", "?"))
if m.get("power") == "ON":
n_on += 1
cur = m.get("current_ma")
if cur is None:
ma_s = ""
@ -767,22 +771,25 @@ def _print_per_port_power_table(
if cur_f is not None and v_f is not None:
total_power_w += v_f * (cur_f / 1000.0)
n_power += 1
w_s = f"{v_f * cur_f / 1000.0:.3f}"
pnl = _panel_cell(panel_lookup, hub_rows, row, port)
st = _panel_sort_tuple(pnl, row.idx, port)
line = (
f"{pnl:<8} | {row.idx:<4} | {row.serial:<12} | {port:<3} | {pwr:<5} | "
f"{ma_s:>8} | {v_s:>8} | {_location_cell(row)}"
f"{pnl:<8} | {row.idx:<4} | {row.serial:<12} | {port:<3} | "
f"{ma_s:>10} | {v_s:>8} | {w_s:>10} | {_location_cell(row)}"
)
lines_out.append((st, line))
if n_ma and n_power:
summary = (
f"Power: Total {total_power_w:.3f} W / {total_ma:.2f} mA (per port follows)"
f"Power({n_on}): Total {total_power_w:.3f} W / {total_ma:.2f} mA (per port follows)"
)
elif n_ma:
summary = f"Power: Total — W / {total_ma:.2f} mA (per port follows)"
summary = (
f"Power({n_on}): Total — W / {total_ma:.2f} mA (per port follows)"
)
else:
summary = "Power: — (per port follows)"
summary = f"Power({n_on}): — (per port follows)"
print(summary, flush=True)
print("-" * len(_PER_PORT_PWR_HDR), flush=True)