feat: show suffix-matched metric coverage in host info threshold table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 09:18:49 -04:00
parent b64a2a9313
commit 9e389736f8
3 changed files with 72 additions and 2 deletions
+20
View File
@@ -143,6 +143,25 @@ def _build_host_info(host, threshold_checker=None) -> dict:
thresholds = None
if threshold_checker is not None:
raw = threshold_checker.get_thresholds_for_host(host.name)
# Build reverse coverage: which metric paths suffix-match to each threshold.
# Mirrors the logic in ThresholdChecker._find_threshold.
coverage: dict = {}
for plugin_name, samples in host.plugin_data.items():
if not samples:
continue
_, pdata = samples[-1]
for field_name in pdata:
full_path = f"{plugin_name}.{field_name}"
if full_path in raw:
continue # exact match — the threshold IS this metric
parts = field_name.split("_")
for i in range(1, len(parts)):
candidate = f"{plugin_name}." + "_".join(parts[i:])
if candidate in raw:
coverage.setdefault(candidate, []).append(full_path)
break
thresholds = sorted(
[
{
@@ -150,6 +169,7 @@ def _build_host_info(host, threshold_checker=None) -> dict:
"warning": tc.warning,
"critical": tc.critical,
"operator": tc.operator.value,
"covers": sorted(coverage.get(tc.metric_path, [])),
}
for tc in raw.values()
],
+6 -1
View File
@@ -411,6 +411,7 @@
}
.info-note { color: #888; font-style: italic; }
.info-loading { color: #bbb; font-style: italic; }
.threshold-covers { font-size: 0.85em; color: #777; font-style: italic; }
</style>
<body>
@@ -588,8 +589,12 @@
for (const t of data.thresholds) {
const w = t.warning != null ? escHtml(String(t.warning)) : '—';
const c = t.critical != null ? escHtml(String(t.critical)) : '—';
let metricCell = escHtml(t.metric);
if (t.covers && t.covers.length > 0) {
metricCell += `<br><span class="threshold-covers">↳ ${t.covers.map(escHtml).join(', ')}</span>`;
}
html += `<tr>
<td class="key">${escHtml(t.metric)}</td>
<td class="key">${metricCell}</td>
<td>${escHtml(t.operator)}</td>
<td>${w}</td>
<td>${c}</td>