diff --git a/METRICS.md b/METRICS.md new file mode 100644 index 0000000..dde52a2 --- /dev/null +++ b/METRICS.md @@ -0,0 +1,107 @@ +# ZeaVis Edu — Metrics Endpoints + +This document lists every Prometheus metrics endpoint exposed by the ZeaVis Edu +application stack and the payload each service provides. + +--- + +## Overview + +| Service | Host (prod) | Metrics Endpoint | Port (local) | +|-----------------------|-----------------------------------|----------------------------|--------------| +| Web (Vite dev) | `zeavisedu.asepharyana.my.id` | `GET /metrics` | 5173 | +| API (Elysia) | `api-zeavisedu.asepharyana.my.id` | `GET /metrics` | 3000 | +| ML Service (Axum) | `ml-zeavisedu.asepharyana.my.id` | `GET /metrics` | 8000 | +| Prometheus Collector | — | `GET /metrics` (self) | 9090 | + +> In production all metrics are scraped by the Prometheus collector running in the +> Telemetry stack. See [`telemetry/prometheus/targets/`](./telemetry/prometheus/targets/) +> for the auto‑discovery configuration. + +--- + +## 1. Web App — `GET /metrics` + +| Endpoint | Description | +|-------------------|--------------------------------------------------| +| `/metrics` | Vite dev‑server middleware + client‑side snapshot | + +### Metrics + +| Metric Name | Type | Labels | Description | +|-------------------------------------|---------|-------------------------------|------------------------------------------| +| `zeavis_web_page_views_total` | counter | — | Total page views this session | +| `zeavis_web_vital_bucket` | gauge | `name`, `rating` | Last‑seen Web Vitals (CLS, FCP, INP…) | + +**Development:** served inline by the Vite plugin `vite-plugin-metrics.ts`. +**Production:** the static frontend serves no `/metrics` endpoint — consider +forwarding the Vite dev server, or use the Telemetry collector to scrape +client‑side beacons. + +--- + +## 2. API (Elysia/Bun) — `GET /metrics` + +| Endpoint | Description | +|-------------------|--------------------------------------------------| +| `/metrics` | Prometheus text format via `prom-client` | + +### Metrics + +| Metric Name | Type | Labels | Description | +|--------------------------------------------|-----------|--------------------------------|------------------------------------------| +| `zeavis_api_http_requests_total` | counter | `method`, `path`, `status` | Total HTTP requests | +| `zeavis_api_http_request_duration_seconds` | histogram | `method`, `path` | Request latency buckets | +| `zeavis_api_http_requests_active` | gauge | — | Concurrently‑handled requests | +| `zeavis_api_classifications_total` | counter | `result` | AI image classifications | +| `zeavis_api_diagnoses_total` | counter | `disease` | Created diagnoses | +| `zeavis_api_auth_operations_total` | counter | `operation`, `success` | Login / register attempts | +| Default Node.js metrics | various | — | CPU, memory, event‑loop lag, GC … | + +**Source:** `apps/api/src/lib/telemetry.ts`, instrumented in `routes/`. + +--- + +## 3. ML Service (Rust/Axum) — `GET /metrics` + +| Endpoint | Description | +|-------------------|--------------------------------------------------| +| `/metrics` | Prometheus text format via `prometheus` crate | + +### Metrics + +| Metric Name | Type | Labels | Description | +|--------------------------------------------|-----------|--------------------------------|------------------------------------------| +| `zeavis_ml_http_requests_total` | counter | — | Total HTTP requests | +| `zeavis_ml_http_request_duration_seconds` | histogram | — | Request latency buckets | +| `zeavis_ml_http_requests_active` | gauge | — | Concurrently‑handled requests | +| `zeavis_ml_predictions_total` | counter | — | Successful ONNX predictions | +| `zeavis_ml_model_load_status` | gauge | — | 1 = loaded, 0 = not loaded | +| Process metrics (libc/procfs) | various | — | RSS, CPU, fd count … | + +**Source:** `apps/ml-service/src/telemetry.rs`, instrumented in `routes.rs`. + +--- + +## Prometheus Auto‑Discovery (Telemetry Stack) + +The Telemetry submodule includes a Prometheus instance that uses +`file_sd_configs` to discover targets. Place a target file under +`telemetry/prometheus/targets/` with content such as: + +```json +[ + { + "targets": ["zeavis-api:3000"], + "labels": { "service": "zeavis-api", "component": "backend" } + }, + { + "targets": ["zeavis-ml:8000"], + "labels": { "service": "zeavis-ml", "component": "inference" } + } +] +``` + +The Prometheus config (in `telemetry/prometheus/prometheus.yml`) will +automatically pick up new files within its 15‑second scrape interval — +no restart required. diff --git a/docker-compose.yml b/docker-compose.yml index 699f03f..7a70dcd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,9 @@ networks: app-shared-net: external: true name: app-shared-net + telemetry-net: + external: true + name: telemetry-net services: web: @@ -10,6 +13,7 @@ services: restart: always networks: - app-shared-net + - telemetry-net env_file: - .env labels: @@ -26,6 +30,7 @@ services: restart: always networks: - app-shared-net + - telemetry-net env_file: - .env environment: @@ -47,6 +52,7 @@ services: restart: always networks: - app-shared-net + - telemetry-net env_file: - .env environment: