Skip to content

feat(metrics): implement Prometheus metrics collection & /metrics endpoint#342

Merged
OthmanImam merged 1 commit into
StellAIverse:mainfrom
prismn:feat/issue-311-prometheus-metrics-integration
Jun 23, 2026
Merged

feat(metrics): implement Prometheus metrics collection & /metrics endpoint#342
OthmanImam merged 1 commit into
StellAIverse:mainfrom
prismn:feat/issue-311-prometheus-metrics-integration

Conversation

@prismn

@prismn prismn commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements full Prometheus metrics integration for the StellAIverse backend, satisfying all acceptance criteria from issue #311.

Implementation Details

MetricsModule (src/metrics/)

  • MetricsController — exposes GET /metrics (public, no auth required) returning Prometheus text format
  • MetricsInterceptor — global NestJS interceptor that automatically tracks every HTTP request (latency, total count, in-progress, errors)
  • MetricsModule — registers the controller and wires the interceptor as APP_INTERCEPTOR in AppModule

Custom Metrics (src/config/metrics.ts)

20+ custom metrics implemented with the stellaiverse_ prefix:

Category Metrics
HTTP http_request_duration_seconds (histogram), http_requests_total (counter), http_requests_in_progress (gauge), http_errors_total (counter)
Auth auth_attempts_total, auth_success_total, auth_failures_total, user_signups_total, active_users
Database database_query_duration_seconds (histogram), active_connections (gauge)
Job Queue job_duration_seconds, job_success_total, job_failure_total, queue_length
Application errors_total

Node.js default metrics (CPU, memory, event loop, GC, file descriptors, etc.) are also collected via collectDefaultMetrics.

Grafana Dashboard

Pre-built dashboard template at docs/dashboards/stellaiverse-backend.json — importable directly into Grafana. Panels cover HTTP traffic, latency percentiles (p50/p95), error rate, auth rate, DB query latency, Node.js heap, and event loop lag.

Documentation

docs/METRICS.md — complete reference for all metrics, adding new metrics, Prometheus scrape config, and Grafana import instructions.

Validation Results

Build:npm run build — webpack compiled successfully

New tests (10 passing):

  • src/metrics/metrics.interceptor.spec.ts — 4 tests (success path, error path, default 500, no-request passthrough)
  • src/metrics/metrics.controller.spec.ts — 6 tests (endpoint format, default metrics, HTTP metrics, auth metrics, DB metrics, schema prefix validation)

Pre-existing failures (unrelated, confirmed on main before this branch):
10 test suites fail with Cannot find module 'src/...' — a module path resolution issue in Jest config that predates this PR.

Closes

Closes #311

…ndpoint

- Add MetricsModule with global HTTP interceptor for request tracking
- Expose /metrics endpoint (GET, public, Prometheus text format)
- Define 20+ custom metrics: HTTP, auth, DB, job queue, business
- Add auth-specific counters: attempts, success, failures
- Wire MetricsModule into AppModule
- Add Grafana dashboard template (docs/dashboards/stellaiverse-backend.json)
- Add metrics documentation (docs/METRICS.md)
- 10 unit/integration tests for interceptor and controller

Closes StellAIverse#311
@OthmanImam
OthmanImam merged commit 3981c9c into StellAIverse:main Jun 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Metrics Collection & Prometheus Integration

2 participants