Skip to content

Conversation

@Gupta-02
Copy link
Contributor

Description

This PR implements the health and metrics endpoints requested in issue #39 to enable proper monitoring of the service in production.

Changes Made:

Added Prometheus Support

Installed prom-client package for metrics collection
Set up default Prometheus metrics collectors
Enhanced Health Service (health.service.js)

Added custom Prometheus metrics:
http_requests_total (Counter for total HTTP requests)
http_request_duration_seconds (Histogram for request latencies)
active_connections (Gauge for active connections)
memory_usage_bytes (Gauge for memory usage)
cpu_usage_percent (Gauge for CPU usage)
Added getPrometheusMetrics() function for Prometheus format output
Updated Performance Middleware (performance.middleware.js)

Modified to record metrics on each request (method, route, status code, duration)
Added New Endpoints (server.js)

GET /healthz - Lightweight health check endpoint (Kubernetes-style)
GET /metrics - Prometheus metrics endpoint for scraping
Existing Endpoints (Already Available):
GET /health/ - Basic health check with system status and dependencies
GET /health/metrics - Detailed JSON metrics
GET /health/ready - Readiness probe
GET /health/live - Liveness probe

Testing

Health Check:

Metrics:

Prometheus Configuration:

Add to your prometheus.yml:

Dependencies Added:

prom-client: For Prometheus metrics collection and formatting

Notes:

All endpoints return appropriate HTTP status codes (200 for healthy, 503 for unhealthy)
Metrics include request counts, latencies, memory usage, and CPU usage
The /healthz endpoint is a lightweight alias suitable for load balancers and Kubernetes health checks
Closes #39

@Gupta-02
Copy link
Contributor Author

@Yugenjr please merge!

@Yugenjr
Copy link
Owner

Yugenjr commented Jan 24, 2026

Resolve conflicts

@Gupta-02
Copy link
Contributor Author

@Yugenjr resolved

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.

Add /health and basic metrics endpoints for monitoring

2 participants