feat(alerts): one evaluation path; host-agent ingest fires rules (#5060)
#5060 "One evaluation path: record_metrics batch API; host-agent ingest evaluates rules". - record_metrics(session, rows) writes metric rows and evaluates the rules that watch them, reading rules, states and maintenance windows once per batch. Each rule sees its key's samples oldest first, so an agent catching up after an outage counts consecutive checks as they happened. - Host-agent ingest now goes through it. Before, it wrote plugin_metrics directly and no host_agent rule could ever fire. The catalog gains the per-mount disk_used_pct ("<host>:<mount>"). - MetricBatch gathers a transaction's samples; the docker ingest, traefik, unifi, snmp, monitor and self-monitor writers record one batch each instead of a rule query per sample. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from steward.core.alerts import record_metric
|
||||
from steward.core.alerts import MetricBatch
|
||||
from steward.models.monitors import Monitor, MonitorResult
|
||||
from .runner import run_monitor
|
||||
|
||||
@@ -63,14 +63,16 @@ async def run_due_monitors(app) -> None:
|
||||
db_monitor.last_checked_at = check_time
|
||||
|
||||
# Alert pipeline — keyed by monitor type (source) + name.
|
||||
await record_metric(
|
||||
session=session, source_module=monitor.type,
|
||||
batch = MetricBatch()
|
||||
batch.add(
|
||||
source_module=monitor.type,
|
||||
resource_name=monitor.name, metric_name="is_up",
|
||||
value=1.0 if res["is_up"] else 0.0,
|
||||
)
|
||||
if res["response_ms"] is not None:
|
||||
await record_metric(
|
||||
session=session, source_module=monitor.type,
|
||||
batch.add(
|
||||
source_module=monitor.type,
|
||||
resource_name=monitor.name, metric_name="response_ms",
|
||||
value=res["response_ms"],
|
||||
)
|
||||
await batch.record(session)
|
||||
|
||||
Reference in New Issue
Block a user