atlasbot: add per-hardware extremes

This commit is contained in:
Brad Stein 2026-01-28 01:07:13 -03:00
parent 2fe3d5b932
commit 6001876409

View File

@ -1145,6 +1145,33 @@ def facts_context(
rate=metric in ("net", "io"),
)
lines.append(f"- lowest_{metric}: {node} ({value_fmt})")
for metric in ("cpu", "ram"):
hottest_parts: list[str] = []
lowest_parts: list[str] = []
for hw, nodes_list in sorted(by_hardware.items()):
entries = []
for entry in usage_table:
node = entry.get("node")
if node in nodes_list and entry.get(metric) is not None:
try:
value = float(entry.get(metric))
except (TypeError, ValueError):
continue
entries.append((node, value))
if not entries:
continue
max_node, max_val = max(entries, key=lambda item: item[1])
min_node, min_val = min(entries, key=lambda item: item[1])
hottest_parts.append(
f"{hw}={max_node} ({_format_metric_value(str(max_val), percent=True)})"
)
lowest_parts.append(
f"{hw}={min_node} ({_format_metric_value(str(min_val), percent=True)})"
)
if hottest_parts:
lines.append(f"- hottest_{metric}_by_hardware: {', '.join(hottest_parts)}")
if lowest_parts:
lines.append(f"- lowest_{metric}_by_hardware: {', '.join(lowest_parts)}")
if nodes_in_query:
lines.append("- node_details:")