feat: add Prometheus metrics endpoint
Los mantenedores suelen responder en 1 día
@cameri ya está trabajando en esto.
Desde el 2/5/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Description
Right now there's no way to know what's happening on a running nostream relay without connecting directly to the database. No connection counts, no event throughput, no latency data. You're flying blind.
Proposal
Two things:
A GET /metrics endpoint that returns standard Prometheus text format. Operators who already run Prometheus + Grafana can point a scrape config at it and get dashboards immediately with no extra work.
Example output:
# HELP nostream_connections_active Current number of active WebSocket connections
# TYPE nostream_connections_active gauge
nostream_connections_active 42
# HELP nostream_connections_total Total WebSocket connections since process start
# TYPE nostream_connections_total counter
nostream_connections_total 18340
# HELP nostream_events_received_total Events received from clients
# TYPE nostream_events_received_total counter
nostream_events_received_total{kind="1"} 52341
nostream_events_received_total{kind="7"} 12032
# HELP nostream_events_accepted_total Events written to the database
# TYPE nostream_events_accepted_total counter
nostream_events_accepted_total 48210
# HELP nostream_events_rejected_total Events rejected before storage
# TYPE nostream_events_rejected_total counter
nostream_events_rejected_total{reason="rate-limited"} 2891
nostream_events_rejected_total{reason="invalid"} 340
nostream_events_rejected_total{reason="blocked"} 900
# HELP nostream_subscriptions_active Current active REQ subscriptions
# TYPE nostream_subscriptions_active gauge
nostream_subscriptions_active 156
# HELP nostream_eose_duration_seconds Time from REQ received to EOSE sent
# TYPE nostream_eose_duration_seconds histogram
nostream_eose_duration_seconds_bucket{le="0.01"} 18200
nostream_eose_duration_seconds_bucket{le="0.05"} 31200
nostream_eose_duration_seconds_bucket{le="0.1"} 38900
nostream_eose_duration_seconds_bucket{le="0.5"} 42100
nostream_eose_duration_seconds_bucket{le="1"} 42800
nostream_eose_duration_seconds_bucket{le="5"} 42990
nostream_eose_duration_seconds_bucket{le="+Inf"} 43001
nostream_eose_duration_seconds_sum 4312.94
nostream_eose_duration_seconds_count 43001
# HELP nostream_db_query_duration_seconds Database query latency
# TYPE nostream_db_query_duration_seconds histogram
nostream_db_query_duration_seconds_bucket{le="0.005"} 39100
nostream_db_query_duration_seconds_bucket{le="0.01"} 45210
nostream_db_query_duration_seconds_bucket{le="0.025"} 47300
nostream_db_query_duration_seconds_bucket{le="0.05"} 48100
nostream_db_query_duration_seconds_bucket{le="0.1"} 48900
nostream_db_query_duration_seconds_bucket{le="0.5"} 49150
nostream_db_query_duration_seconds_bucket{le="+Inf"} 49200
nostream_db_query_duration_seconds_sum 621.33
nostream_db_query_duration_seconds_count 49200
Also a simple GET /stats page for operators who don't run Grafana , just a server-rendered HTML page using the same Bootstrap template pattern as the existing /, /invoices, and /terms pages.
Both endpoints are disabled by default and opt-in via settings.yaml
How it works
A MetricsStore singleton holds all counters and histograms in memory. Each component calls into it directly:
WebSocketServerAdapterincrements connection counters on open/closeWebSocketAdaptertracks active subscription countEventMessageHandlerincrements event counters per kind and per rejection reasonSubscribeMessageHandlerrecords EOSE latencyEventRepositoryrecords query latency
Plan
I'll split this into smaller PRs:
PR 1 : MetricsStore + settings flag + tests. No routes yet, just the data structure.
PR 2 : GET /metrics route + connection and subscription counters wired up. At this point you can actually curl the endpoint.
PR 3 : Event counters: received/accepted/rejected by kind and reason, wired into EventMessageHandler.
PR 4 : Latency histograms: EOSE duration in the subscribe handler, query duration in the event repository.
PR 5 : GET /stats HTML page for operators who prefer a browser over Prometheus.
PR 6 : Docs: metric reference + a docker-compose example with a Prometheus + Grafana sidecar for operators who want to set up the full stack.
- Lenguaje dominante
- TypeScript
- Estrellas
- 829
- Forks
- 234
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 24
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de cameri/nostream
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
Los mantenedores suelen responder en 1 día
-
feat(nip77): advertise NIP-77 in NIP-11 and expose its settings in the admin consolePosiblemente ocupada @Priyanshubhartistm la tomó hoy. Abiertoenhancement
cameri/nostream#819 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
feat(nip77): NEG-OPEN/NEG-MSG/NEG-CLOSE wire protocol for the PostgreSQL backendPosiblemente ocupada @Priyanshubhartistm la tomó hoy. Abiertoenhancement
cameri/nostream#817 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Admin Console] Ops visibility panels (mirror, workers, NIP-05, storage)Posiblemente ocupada @Ferryx349 la tomó hoy. AbiertoAdmin Console enhancement
cameri/nostream#816 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de cameri/nostream
Issues similares
-
status: needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
a2ui-project/a2ui#3158 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
hemilabs/ui-monorepo#2475 ·
Los mantenedores suelen responder en 1 día
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
lingdojo/kana-dojo#32279 · 1 comentario · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
code-quality refactoring
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
github/gh-aw-firewall#9879 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Arrow-key cursor movement in combined diff view doesn't scroll to keep the cursor visibleAbiertoos:macos
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día