Skip to content
dev1lsconf edited this page Nov 28, 2026 · 1 revision

API

TinyTop expone una API HTTP JSON, exportación, métricas Prometheus y el dashboard embebido.

Endpoints

Método Ruta Descripción
GET / Dashboard web
GET /api/health Estado/readiness
GET /api/metrics/latest Últimas métricas de sistema y targets
GET /api/metrics/history?range=24&target=system|<name> Histórico (downsampling/rollups en rangos largos)
GET /api/config Config efectiva (sensible redactado)
GET /api/alerts?status=&limit= Alertas/incidentes
GET /api/events?limit= Eventos recientes
GET /api/export?target=system|<name>&format=json|csv&range=24 Exportación
GET /metrics Prometheus text format

Health

curl -s http://localhost:9090/api/health

Campos relevantes: status, ready, db.ok, shutting_down, runtime.last_collection_ok, runtime.last_collection_error, version.

Latest metrics

curl -s http://localhost:9090/api/metrics/latest

Devuelve:

{ "system": { ... }, "targets": [ ... ] }

system incluye CPU, memoria, disco, red, load, swap, uptime y top procesos (best-effort). targets incluye status, latency_ms, detail, check_type, cert_days_left cuando aplica.

History

curl -s "http://localhost:9090/api/metrics/history?target=system&range=24"
curl -s "http://localhost:9090/api/metrics/history?target=api&range=24"
  • range se acota a max_history_hours y retention_hours.
  • Rangos largos pueden usar rollups/downsampling (downsampled, bucket_seconds).
  • Targets incluyen latencia, up_ratio y cert_days_left cuando aplica.

Export

curl -s "http://localhost:9090/api/export?target=system&format=json&range=24"
curl -s "http://localhost:9090/api/export?target=system&format=csv&range=24" -o system.csv

Alerts / Events

curl -s "http://localhost:9090/api/alerts?status=firing&limit=100"
curl -s "http://localhost:9090/api/events?limit=100"

Prometheus

curl -s http://localhost:9090/metrics

Métricas expuestas incluyen tinytop_up, gauges de sistema y por target (tinytop_target_up, tinytop_target_latency_ms, tinytop_target_cert_days_left).

Errores

La API responde con JSON de error consistente:

{ "error": { "code": "target_not_found", "message": "unknown target: nope" } }

Auth

Si [auth] está habilitado, envía credenciales por cabecera:

  • Authorization: Bearer <token>
  • X-API-Key: <token>
  • Authorization: Basic ...

/api/health puede quedar exento con allow_health_unauth = true. /api/config redacta secretos.

Clone this wiki locally