8af297670e
plugin_metrics grows by (sources × resources × ~30s cadence); keeping 90d of raw
is a large table. Add a raw→hourly rollup (mirroring the Docker plugin) so only a
short raw window is kept at full resolution, with hourly averages archived longer.
- PluginMetricHourly model + core migration 0024 (plugin_metrics_hourly: avg/max/
count per source/resource/metric/hour, unique bucket constraint + lookup index).
- steward/core/metrics_retention.rollup_plugin_metrics: date_trunc('hour') agg of
raw older than the hour-aligned raw window, idempotent pg upsert into hourly,
delete the rolled raw, prune hourly beyond the rollup window.
- cleanup.py: plugin_metrics is no longer blanket-deleted at data.retention_days;
_run_metrics_retention drives the rollup with windows read live from settings.
- Settings: metrics.retention.raw_days (7) + rollup_days (90), tunable on the
Thresholds & Retention page (new "Host metrics retention" card).
- Chart read: _history_for_host merges the hourly rollup (older part of the range)
with raw date_bin (recent part, capped ≤1h), so 30d charts keep working —
recent at full resolution, older at hourly. Route passes raw_days from settings.
- Tests: unit (cutoff helpers) + integration (rollup aggregates/prunes; history
merges hourly + raw) against Postgres.
Speed was already handled by the indexes + SQL aggregation; this is the storage
lever (raw window ~10x smaller).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Jg27rgypiW2efULXJDtMC
94 lines
5.7 KiB
HTML
94 lines
5.7 KiB
HTML
{# steward/templates/settings/thresholds.html — tunable degraded/critical cutoffs #}
|
|
{% extends "base.html" %}
|
|
{% block title %}Settings — Thresholds & Retention — Steward{% endblock %}
|
|
{% block content %}
|
|
{% set active_tab = "thresholds" %}
|
|
{% include "settings/_tabs.html" %}
|
|
|
|
{% macro pair(label, warn_field, warn_key, crit_field, crit_key, unit, hint, step="1") %}
|
|
<div class="form-group" style="margin-bottom:1.1rem;">
|
|
<label>{{ label }} <span style="color:var(--text-muted);font-size:0.8rem;">({{ unit }})</span></label>
|
|
<div style="display:flex;gap:1.25rem;flex-wrap:wrap;margin-top:0.25rem;">
|
|
<span style="display:flex;align-items:center;gap:0.4rem;">
|
|
<span style="color:var(--yellow);font-size:0.8rem;font-weight:600;">warn</span>
|
|
<input type="number" name="{{ warn_field }}" step="{{ step }}"
|
|
value="{{ settings[warn_key] }}" style="max-width:110px;">
|
|
</span>
|
|
<span style="display:flex;align-items:center;gap:0.4rem;">
|
|
<span style="color:var(--red);font-size:0.8rem;font-weight:600;">crit</span>
|
|
<input type="number" name="{{ crit_field }}" step="{{ step }}"
|
|
value="{{ settings[crit_key] }}" style="max-width:110px;">
|
|
</span>
|
|
</div>
|
|
{% if hint %}<div style="font-size:0.78rem;color:var(--text-muted);margin-top:0.3rem;">{{ hint }}</div>{% endif %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
<form method="post" action="/settings/thresholds/">
|
|
<div class="card" style="max-width:640px;">
|
|
<h2 class="section-title" style="margin-bottom:0.5rem;">Monitoring thresholds</h2>
|
|
<p style="font-size:0.82rem;color:var(--text-muted);margin-bottom:1.25rem;">
|
|
Values at or beyond <span style="color:var(--yellow);">warn</span> show amber; at or beyond
|
|
<span style="color:var(--red);">crit</span> show red — across dashboard widgets and host views.
|
|
Higher is worse for everything except uptime, where the cutoffs are floors.
|
|
</p>
|
|
|
|
{{ pair("CPU usage", "cpu_warn", "thresholds.cpu_warn", "cpu_crit", "thresholds.cpu_crit", "%", "Average CPU utilization per host.") }}
|
|
{{ pair("Memory usage", "mem_warn", "thresholds.mem_warn", "mem_crit", "thresholds.mem_crit", "%", "Memory in use per host.") }}
|
|
{{ pair("Disk usage", "disk_warn", "thresholds.disk_warn", "disk_crit", "thresholds.disk_crit", "%", "Filesystem usage.") }}
|
|
{{ pair("Load", "load_warn", "thresholds.load_warn", "load_crit", "thresholds.load_crit", "% per core", "Load average normalized by core count (100% = one full core per core).") }}
|
|
{{ pair("Temperature", "temp_warn", "thresholds.temp_warn", "temp_crit", "thresholds.temp_crit", "°C", "Hottest reported sensor per host.") }}
|
|
{{ pair("Ping latency", "latency_warn", "ping.threshold.good_ms", "latency_crit", "ping.threshold.warn_ms", "ms", "Round-trip time. Shared with the Ping widget's good/warn colouring.") }}
|
|
{{ pair("Uptime / SLA", "uptime_warn", "thresholds.uptime_warn", "uptime_crit", "thresholds.uptime_crit", "%", "Lower is worse — amber below warn, red below crit.", step="0.1") }}
|
|
</div>
|
|
|
|
{% macro days(label, field, key, hint) %}
|
|
<div class="form-group" style="margin-bottom:1.1rem;">
|
|
<label>{{ label }} <span style="color:var(--text-muted);font-size:0.8rem;">(days)</span></label>
|
|
<div style="margin-top:0.25rem;">
|
|
<input type="number" name="{{ field }}" min="1" step="1"
|
|
value="{{ settings[key] }}" style="max-width:110px;">
|
|
</div>
|
|
{% if hint %}<div style="font-size:0.78rem;color:var(--text-muted);margin-top:0.3rem;">{{ hint }}</div>{% endif %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
<div class="card" style="max-width:640px;margin-top:1.5rem;">
|
|
<h2 class="section-title" style="margin-bottom:0.5rem;">Docker data retention</h2>
|
|
<p style="font-size:0.82rem;color:var(--text-muted);margin-bottom:1.25rem;">
|
|
Bounds how much Docker history is stored. Raw per-sample container metrics are
|
|
kept for the raw window, then rolled up into hourly averages kept for the
|
|
rollup window; lifecycle events are kept for the events window. Applied by the
|
|
hourly cleanup task — a change takes effect on its next run.
|
|
</p>
|
|
|
|
{{ days("Raw metrics", "docker_metrics_raw_days", "docker.retention.metrics_raw_days",
|
|
"Keep per-sample container CPU/memory points this long, then roll up to hourly.") }}
|
|
{{ days("Rolled-up metrics", "docker_metrics_rollup_days", "docker.retention.metrics_rollup_days",
|
|
"Keep the hourly-averaged series this long for multi-day history.") }}
|
|
{{ days("Lifecycle events", "docker_events_days", "docker.retention.events_days",
|
|
"Keep container start/stop/die/health history this long.") }}
|
|
</div>
|
|
|
|
<div class="card" style="max-width:640px;margin-top:1rem;">
|
|
<h2 class="section-title" style="margin-bottom:0.5rem;">Host metrics retention</h2>
|
|
<p style="font-size:0.82rem;color:var(--text-muted);margin-bottom:1.25rem;">
|
|
Bounds how much host-agent metric history is stored (CPU, memory, disk, network,
|
|
temps, …). Raw per-sample points are kept for the raw window, then rolled up
|
|
into hourly averages kept for the rollup window. Host charts read raw for the
|
|
recent part of a range and hourly for older data. Applied by the hourly cleanup.
|
|
</p>
|
|
|
|
{{ days("Raw metrics", "metrics_raw_days", "metrics.retention.raw_days",
|
|
"Keep per-sample host metrics this long, then roll up to hourly averages.") }}
|
|
{{ days("Rolled-up metrics", "metrics_rollup_days", "metrics.retention.rollup_days",
|
|
"Keep the hourly-averaged series this long for multi-week history.") }}
|
|
</div>
|
|
|
|
<div style="margin-top:1rem;display:flex;align-items:center;gap:1rem;">
|
|
<button type="submit" class="btn">Save</button>
|
|
<span style="font-size:0.82rem;color:var(--text-muted);">Takes effect immediately — no restart.</span>
|
|
</div>
|
|
</form>
|
|
{% endblock %}
|