A bundled prometheus plugin, on by default like the other protocol plugins. Targets are rows edited on its page: address, bearer token (encrypted), interval, keep/leave-out name patterns and a series cap. Steward does the filtering; the endpoint serves everything (Archives' ruling). - A 5 s tick scrapes due targets at once, each within a 30 s deadline, and writes the outcome to its row and its series through record_metrics, so alert rules can watch any of them. - Gauges are stored as they are; counters (and a histogram's or summary's _sum/_count) as <name>_per_sec rates from the second scrape. Buckets and quantiles are skipped. A labelled series is stored under "<target>:k=v,…". Each target also records is_up, scrape_ms, series_kept and series_capped. - Pages: targets not answering first, with why; a target's series grouped by metric with their newest values; a chart per series; the editor with Test, which scrapes once and says what would be stored. - The counter-to-rate keeper moves to steward/core/counter_rates.py; SNMP's RateKeeper now scales its rate on top of it. - metric_value reads Prometheus's _seconds as a span and _per_sec as a rate. - The catalog guard treats an empty list as a dynamic source (snmp, prometheus), as the rule form does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
# plugins/prometheus/__init__.py
|
|
from __future__ import annotations
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from quart import Quart
|
|
|
|
_app: "Quart | None" = None
|
|
|
|
|
|
def setup(app: "Quart") -> None:
|
|
global _app
|
|
_app = app
|
|
from .models import PrometheusTarget # noqa: F401 — registers the table
|
|
|
|
|
|
def get_scheduled_tasks() -> list:
|
|
from .scheduler import make_scrape_task
|
|
return [make_scrape_task(_app)]
|
|
|
|
|
|
def get_blueprint():
|
|
from .routes import prometheus_bp
|
|
return prometheus_bp
|
|
|
|
|
|
def get_nav() -> list[dict]:
|
|
# Surfaces in the sidebar's Infrastructure group (scraped endpoints).
|
|
return [{"label": "Prometheus", "href": "/plugins/prometheus/"}]
|
|
|
|
|
|
def get_alert_metrics() -> dict[str, list[str]]:
|
|
"""The metric names are whatever each endpoint exposes, so the list is
|
|
empty here and the rule form offers the names recorded so far."""
|
|
return {"prometheus": []}
|
|
|
|
|
|
def get_audit_entities() -> dict:
|
|
"""Audit rows about a target name it and link to its page."""
|
|
from .models import PrometheusTarget
|
|
return {"prometheus_target": (PrometheusTarget, "/plugins/prometheus/targets/{}")}
|