A comprehensive API health checker built with TypeScript and Express.js that monitors the health of HTTP endpoints, databases, and system resources.
- π HTTP Health Checks: Monitor REST APIs, websites, and web services
- ποΈ Database Health Checks: Support for PostgreSQL, MySQL, MongoDB, and Redis
- π₯οΈ System Health Checks: Monitor CPU, memory, and disk usage
- π Metrics Collection: Track uptime, response times, and success rates
- π Periodic Monitoring: Automated health checks with configurable intervals
- π¨ Retry Logic: Configurable retry attempts with backoff
- π Structured Logging: Winston-based logging with health check events
- π‘οΈ Security: Helmet.js security headers and CORS support
- βοΈ Configuration: JSON file and environment variable configuration
-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Start the server:
npm start
For development with auto-reload:
npm run dev
-
Access the API:
- Health status:
GET http://localhost:3000/api/health - Detailed health:
GET http://localhost:3000/api/health/detailed - API documentation:
GET http://localhost:3000/
- Health status:
GET /api/health- Quick health status overviewGET /api/health/detailed- Detailed health status with all check results
GET /api/health/checks- List all registered health checksGET /api/health/checks/:id- Get specific health check statusPOST /api/health/checks/:id/execute- Execute a health check manuallyPOST /api/health/checks- Register a new health checkDELETE /api/health/checks/:id- Unregister a health checkPUT /api/health/checks/:id/toggle- Enable/disable a health check
GET /api/health/metrics- Get metrics for all health checksGET /api/health/metrics/:id- Get metrics for a specific health check
# Server configuration
PORT=3000
HOST=0.0.0.0
NODE_ENV=development
# Health check defaults
HEALTH_CHECK_TIMEOUT=5000
HEALTH_CHECK_INTERVAL=30000
MAX_RETRIES=3
# Logging
LOG_LEVEL=info
LOG_FORMAT=json
# Configuration directory
HEALTH_CHECKS_CONFIG_DIR=./configYou can define health checks using environment variables:
# HTTP check example
HEALTH_CHECK_API_URL=https://api.example.com/health
HEALTH_CHECK_API_NAME="API Service"
HEALTH_CHECK_API_METHOD=GET
HEALTH_CHECK_API_TIMEOUT=5000
HEALTH_CHECK_API_INTERVAL=30000Health checks can be defined in JSON files in the config/ directory:
{
"id": "api-service",
"name": "API Service Health",
"type": "http",
"enabled": true,
"interval": 30000,
"timeout": 5000,
"retries": 3,
"metadata": {
"url": "https://api.example.com/health",
"method": "GET",
"expectedStatusCodes": [200],
"headers": {
"Authorization": "Bearer token"
}
}
}{
"id": "postgres-main",
"name": "PostgreSQL Main Database",
"type": "database",
"enabled": true,
"interval": 60000,
"timeout": 8000,
"retries": 2,
"metadata": {
"connectionString": "postgresql://user:password@localhost:5432/maindb",
"databaseType": "postgresql",
"query": "SELECT 1 as health_check"
}
}{
"id": "system-performance",
"name": "System Performance Check",
"type": "system",
"enabled": true,
"interval": 120000,
"timeout": 15000,
"metadata": {
"checks": [
{ "type": "memory", "threshold": 85 },
{ "type": "cpu", "threshold": 90 },
{ "type": "disk", "threshold": 90, "path": "/" }
]
}
}- Monitor REST APIs and web endpoints
- Support for custom headers and authentication
- Configurable expected status codes and response body validation
- Follow redirects option
- PostgreSQL: Connection and query execution
- MySQL: Connection and query execution
- MongoDB: Connection and ping operations
- Redis: Connection and ping operations
- Memory: Monitor RAM usage percentage
- CPU: Monitor CPU load average
- Disk: Monitor disk usage by path
healthy- Check passed successfullydegraded- Check passed but performance is poor (slow response)unhealthy- Check failedunknown- Check status could not be determined
200- All checks healthy206- Some checks degraded (partial content)503- One or more checks unhealthy (service unavailable)500- Internal server error
npm run build- Build the TypeScript projectnpm run dev- Start development server with auto-reloadnpm start- Start production servernpm test- Run testsnpm run lint- Run ESLintnpm run format- Format code with Prettier
src/
βββ checkers/ # Health check implementations
β βββ http.ts # HTTP endpoint checker
β βββ database.ts # Database connectivity checker
β βββ system.ts # System resource checker
βββ routes/ # Express routes
β βββ health.ts # Health check API routes
βββ services/ # Core services
β βββ health-check-orchestrator.ts # Main orchestrator
β βββ logger.ts # Logging service
βββ types.ts # TypeScript type definitions
βββ index.ts # Application entry point
MIT License - see LICENSE file for details.