Add frontend performance metrics pipeline to Prometheus

Collect browser-side worker round-trips, computation times, main-thread
operations, and feature counts, batch them client-side, and expose as
Prometheus histograms via a new POST /api/perf endpoint.
This commit is contained in:
Viktor Barzin 2026-02-22 17:30:29 +00:00
parent c24c3a545c
commit d90fa38776
No known key found for this signature in database
GPG key ID: 0EB088298288D958
10 changed files with 188 additions and 5 deletions

View file

@ -56,6 +56,14 @@ celery_tasks_total: Counter
celery_task_duration_seconds: Histogram
celery_tasks_active: UpDownCounter
# ---------------------------------------------------------------------------
# Frontend performance metrics
# ---------------------------------------------------------------------------
frontend_worker_roundtrip: Histogram
frontend_worker_compute: Histogram
frontend_main_thread: Histogram
frontend_feature_count: Histogram
def init_metrics(service_name: str = "realestate-crawler") -> PrometheusMetricReader:
"""Initialise the OTel MeterProvider and define all instruments.
@ -70,6 +78,8 @@ def init_metrics(service_name: str = "realestate-crawler") -> PrometheusMetricRe
global geojson_cache_operations
global ocr_attempts, ocr_successes
global celery_tasks_total, celery_task_duration_seconds, celery_tasks_active
global frontend_worker_roundtrip, frontend_worker_compute
global frontend_main_thread, frontend_feature_count
if _reader is not None:
return _reader
@ -144,6 +154,24 @@ def init_metrics(service_name: str = "realestate-crawler") -> PrometheusMetricRe
description="Currently active Celery tasks",
)
# -- Frontend performance --
frontend_worker_roundtrip = _meter.create_histogram(
"frontend_worker_roundtrip_seconds",
description="Browser worker message round-trip time",
)
frontend_worker_compute = _meter.create_histogram(
"frontend_worker_compute_seconds",
description="Computation time inside the web worker",
)
frontend_main_thread = _meter.create_histogram(
"frontend_main_thread_seconds",
description="Main-thread blocking operation duration",
)
frontend_feature_count = _meter.create_histogram(
"frontend_feature_count",
description="Number of features per heatmap load",
)
return _reader