This project sets up a complete lightweight observability and monitoring setup using Node.js, Prometheus, Grafana, and Node Exporter via Docker Compose.
- Node.js App: A simple Express app exposing a
/metricsendpoint using prom-client for Prometheus metrics. - Prometheus: Scrapes metrics from the app and Node Exporter, evaluates alert rules.
- Node Exporter: Exports system metrics (CPU, memory, etc.) from the host.
- Grafana: Visualizes metrics with a custom dashboard.
- Alert Dispatcher: Bash script to fetch and log active alerts from Prometheus API.
The setup includes:
- Metrics collection from app and system
- Alerting on high CPU usage (>70%) and app unavailability
- Visualization dashboard for CPU, memory, and request latency
- Local logging of alerts
- Docker
- Docker Compose
-
Clone or navigate to the project directory.
-
Start all services:
docker-compose up -d
-
Access the services:
- App: http://localhost:3000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3001 (admin/admin)
- Node Exporter: http://localhost:9100
-
View metrics at http://localhost:3000/metrics
-
Run alert dispatcher (optional):
./alert_dispatcher.sh
Check
alerts.logfor logged alerts. -
Stop services:
docker-compose down
docker-compose.yml: Service definitionsprometheus.yml: Prometheus configurationalert.rules.yml: Alert rulesgrafana-dashboard.json: Grafana dashboard configurationapp/: Node.js applicationserver.js: Main app with metricspackage.json: DependenciesDockerfile: App container
alert_dispatcher.sh: Alert logging scriptdashboard_screenshot_placeholder.txt: Sample dashboard description
- HighCPUUsage: Triggers when CPU > 70% for 5 minutes
- AppDown: Triggers when app is unreachable for 1 minute
The Grafana dashboard includes panels for:
- CPU Usage (%)
- Memory Usage (%)
- Request Latency (95th percentile)
Import grafana-dashboard.json into Grafana if needed.
- Ensure ports 3000-9100 are free.
- Check Docker logs:
docker-compose logs <service> - For alerts, ensure Prometheus is scraping correctly.
See dashboard_screenshot_placeholder.txt for a description of the dashboard with triggered alerts.