feat(status): unified Status page + widget across ping/DNS/HTTP monitors
Adds a Kuma-style "is everything up?" surface that aggregates heterogeneous monitor types via a status-source registry (steward/core/status.py): each type registers an async source(db) -> [StatusEntry]. Core registers ping/DNS; the http plugin registers its own from setup() so core never imports plugin tables. Per entry: current up/down, last-30 heartbeat bar, uptime % (24h/7d/30d), latest latency + response sparkline, and TLS expiry countdown (HTTP). New /status page (live htmx refresh) + a status_overview dashboard widget + nav link. Pure-function unit tests for registry + sparkline. First deliverable of milestone #68 (task #866). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# steward/status/ — unified monitor-status surface (page + dashboard widget)
|
||||
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
from quart import Blueprint, current_app, render_template, request
|
||||
|
||||
from steward.auth.middleware import require_role
|
||||
from steward.core.status import collect_status, sparkline_svg
|
||||
from steward.models.users import UserRole
|
||||
|
||||
status_bp = Blueprint("status", __name__, url_prefix="/status")
|
||||
|
||||
|
||||
def _summarize(entries) -> tuple[int, int, int]:
|
||||
up = sum(1 for e in entries if e.status == "up")
|
||||
down = sum(1 for e in entries if e.status == "down")
|
||||
pending = sum(1 for e in entries if e.status == "pending")
|
||||
return up, down, pending
|
||||
|
||||
|
||||
@status_bp.get("/")
|
||||
@require_role(UserRole.viewer)
|
||||
async def index():
|
||||
poll_interval = current_app.config.get("MONITORS_POLL_INTERVAL", 60)
|
||||
return await render_template("status/index.html", poll_interval=poll_interval)
|
||||
|
||||
|
||||
@status_bp.get("/rows")
|
||||
@require_role(UserRole.viewer)
|
||||
async def rows():
|
||||
"""HTMX fragment — the full status list + summary, refreshed on poll."""
|
||||
async with current_app.db_sessionmaker() as db:
|
||||
entries = await collect_status(db)
|
||||
for e in entries:
|
||||
if e.spark:
|
||||
e.spark_svg = sparkline_svg(e.spark)
|
||||
up, down, pending = _summarize(entries)
|
||||
return await render_template(
|
||||
"status/rows.html", entries=entries, up=up, down=down, pending=pending
|
||||
)
|
||||
|
||||
|
||||
@status_bp.get("/widget")
|
||||
@require_role(UserRole.viewer)
|
||||
async def widget():
|
||||
"""HTMX dashboard widget — compact up/down/pending summary + problem list."""
|
||||
async with current_app.db_sessionmaker() as db:
|
||||
entries = await collect_status(db)
|
||||
up, down, pending = _summarize(entries)
|
||||
return await render_template(
|
||||
"status/widget.html",
|
||||
entries=entries, up=up, down=down, pending=pending,
|
||||
widget_id=request.args.get("wid", "0"),
|
||||
)
|
||||
Reference in New Issue
Block a user