Skip to main content

MikroTik Telemetry API

Machine-readable spec: openapi/mikrotik-telemetry.yaml (generated from the live FastAPI app).

The MikroTik telemetry endpoints (router in server/app/api/mikrotik.py, prefix /api/admin/router) expose router health and network interface traffic data collected by the background collect_metrics_loop thread. All endpoints require admin auth (get_current_user_admin).


Endpoints at a glance

MethodPathAuthSummary
GET/api/admin/router/health/latestAdminReturn the single most recent RouterHealth snapshot.
GET/api/admin/router/health/historyAdminReturn recent RouterHealth snapshots, most recent first. Query param: limit (default 50).
GET/api/admin/router/traffic/{interface}AdminReturn InterfaceTraffic history for a specific interface, most recent first. Query param: limit (default 100).
GET/api/admin/router/dashboardAdminReturn the latest health snapshot plus all traffic rows, combined.

None of these routes declare a response_model, so the generated YAML's 200 response schema is empty ({}) for all four — the shapes below are the only documented response structure.

EndpointResponse 200
GET /api/admin/router/health/latestA single RouterHealth object, or null if no snapshot has been collected yet (not a 404).
GET /api/admin/router/health/historyArray of RouterHealth objects, most recent first (limit query param, default 50).
GET /api/admin/router/traffic/{interface}Array of InterfaceTraffic objects for the given interface (path param, e.g. ether1), most recent first (limit query param, default 100).
GET /api/admin/router/dashboard{ "health": <RouterHealth>, "traffic": [<InterfaceTraffic>] } — the latest health snapshot plus all traffic rows, combined.

Background collection

Metrics are collected by db_operations/router_metrics_collector.py (collect_metrics_loop), which runs as a daemon thread started at server startup (see lifespan in server/app/main.py). It polls the MikroTik router via the RouterOS-api Python library and writes snapshots to the RouterHealth and InterfaceTraffic tables.

Router connection parameters (IP, username, password) are configured via environment variables. See environment-config.md.

For full request/response schemas, see openapi/mikrotik-telemetry.yaml or the live server's /docs / /openapi.json.