feat(dashboard): per-metric sparklines in the Host Agent — Resources widget
Operator ask: show the graphs next to their fields in the fleet widget, like the host page's AGENT panel. Each row now renders cpu/mem/disk/load as a value with a trend sparkline beneath it (1h window), instead of bare numbers. - _fleet_rows fetches a per-host recent series (cpu/mem/load host-level, disk from the root mount) in one 1h query and attaches a sparkline per metric to each row. - widget_table.html lays out a metric cell (label + threshold-coloured value + sparkline) per field, mirroring panel.html. Threshold colour is computed in the loop and passed into the cell macro (keeps Jinja macro scope clean). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
{# host_agent widget — fleet glance, flex rows (no header wrap) #}
|
||||
{# host_agent widget — fleet glance: per-host row with a sparkline beside each
|
||||
metric (cpu/mem/disk/load), mirroring the host-page AGENT panel. #}
|
||||
{% from "_macros.html" import metric_style %}
|
||||
{% if rows %}
|
||||
{% macro metric_cell(label, value, fmt, svg, style="", title="") %}
|
||||
<div style="min-width:74px;flex-shrink:0;" title="{{ title }}">
|
||||
<div style="font-size:0.66rem;color:var(--text-dim);text-transform:uppercase;letter-spacing:0.03em;">{{ label }}</div>
|
||||
<div style="font-weight:600;font-size:0.8rem;font-variant-numeric:tabular-nums;{{ style }}">
|
||||
{% if value is not none %}{{ fmt|format(value) }}{% else %}—{% endif %}
|
||||
</div>
|
||||
<div style="line-height:0;height:16px;">{{ svg | safe }}</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
<div style="display:grid;gap:0.1rem;">
|
||||
{% for r in rows %}
|
||||
{% set stale = r.stale %}
|
||||
<div style="display:flex;align-items:center;gap:0.6rem;font-size:0.82rem;padding:0.3rem 0;border-bottom:1px solid var(--border);">
|
||||
<div style="display:flex;align-items:center;gap:0.75rem;font-size:0.82rem;padding:0.45rem 0;border-bottom:1px solid var(--border);">
|
||||
<span class="dot {% if stale %}dot-dim{% elif (r.cpu_pct or 0) >= 90 or (r.mem_used_pct or 0) >= 90 or (r.disk_worst or 0) >= 90 %}dot-warn{% else %}dot-up{% endif %}"
|
||||
title="{% if stale %}stale / no recent data{% else %}warns at CPU/memory ≥90% or any disk mount ≥90% (the 'disk /' figure shows root only){% endif %}"></span>
|
||||
{% set name_style = "flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:500;" %}
|
||||
@@ -13,21 +23,13 @@
|
||||
{% else %}
|
||||
<span title="{{ r.host.name }}" style="{{ name_style }}">{{ r.host.name }}</span>
|
||||
{% endif %}
|
||||
<span style="display:flex;gap:0.75rem;font-variant-numeric:tabular-nums;color:var(--text-muted);font-size:0.75rem;flex-shrink:0;">
|
||||
{% if r.cpu_pct is not none %}
|
||||
<span title="CPU" style="{{ metric_style(r.cpu_pct) }}"><span style="color:var(--text-dim);">cpu</span> {{ "%.0f"|format(r.cpu_pct) }}%</span>
|
||||
{% endif %}
|
||||
{% if r.mem_used_pct is not none %}
|
||||
<span title="Memory" style="{{ metric_style(r.mem_used_pct) }}"><span style="color:var(--text-dim);">mem</span> {{ "%.0f"|format(r.mem_used_pct) }}%</span>
|
||||
{% endif %}
|
||||
{% if r.disk_root is not none %}
|
||||
<span title="Root filesystem (/) usage" style="{{ metric_style(r.disk_root) }}"><span style="color:var(--text-dim);">disk /</span> {{ "%.0f"|format(r.disk_root) }}%</span>
|
||||
{% endif %}
|
||||
{% if r.load_1m is not none %}
|
||||
<span title="Load average 1m"><span style="color:var(--text-dim);">load</span> {{ "%.2f"|format(r.load_1m) }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span style="min-width:60px;text-align:right;font-size:0.72rem;color:var(--text-dim);flex-shrink:0;">
|
||||
<div style="display:flex;gap:1.1rem;flex-shrink:0;align-items:flex-start;">
|
||||
{{ metric_cell("cpu", r.cpu_pct, "%.0f%%", r.sparks.cpu, metric_style(r.cpu_pct), "Average CPU utilization") }}
|
||||
{{ metric_cell("mem", r.mem_used_pct, "%.0f%%", r.sparks.mem, metric_style(r.mem_used_pct), "Memory in use") }}
|
||||
{{ metric_cell("disk /", r.disk_root, "%.0f%%", r.sparks.disk, metric_style(r.disk_root), "Root filesystem (/) usage") }}
|
||||
{{ metric_cell("load", r.load_1m, "%.2f", r.sparks.load, "", "Load average (1m)") }}
|
||||
</div>
|
||||
<span style="min-width:58px;text-align:right;font-size:0.72rem;color:var(--text-dim);flex-shrink:0;">
|
||||
{{ r.reg.last_seen_at.strftime("%H:%M:%S") if r.reg.last_seen_at else "never" }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user