This repository provides a complete, out-of-the-box monitoring solution for a Node.js application. With a single command, you can launch a full stack including:
- A Node.js/Express server that exposes custom metrics.
- Prometheus to scrape and store those metrics.
- Grafana to visualize metrics with a pre-configured dashboard.
- Loki to collect and query logs from the Node.js server.
The entire stack is orchestrated with Docker Compose for a seamless, cross-platform experience.
All services are containerized and run on a shared Docker network, allowing them to communicate with each other automatically.
- The Node.js server runs, exposing its metrics on the
/metricsendpoint. - Prometheus is configured to automatically discover and scrape the
nodeservertarget. - Loki is ready to receive logs pushed from the Node.js application's Winston logger.
- Grafana is pre-configured with Prometheus as a data source, ready for you to build dashboards to visualize your application's performance.
- Single-Command Setup: Launch the entire stack with
docker-compose. - Metrics Collection: Gathers default metrics and custom business metrics from the Node.js app.
- Log Aggregation: Centralizes Node.js application logs in Loki for easy searching.
- Automated Discovery: Services find each other automatically, no manual IP configuration needed.
- Pre-configured Grafana: Prometheus data source is already set up on launch.
Before you begin, ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/AkashBhadana/Nodeserver-Prometheus-Grafana.git cd Nodeserver-Prometheus-Grafana -
Start all services: Run the following command to build the images and start all containers in the background.
docker-compose up -d
That's it! The entire monitoring stack is now running.
- Node.js Application: http://localhost:8000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
- Loki: Not directly accessed, used as a data source by Grafana.
- Grafana:
- Username:
admin - Password:
admin
- Username:
The Node.js application exposes the following custom metrics:
http_express_req_res_time: A histogram tracking the distribution of request-response times.total_req: A counter for the total number of requests received by the server.
You can view these by navigating to Prometheus and querying the metric names.
The Winston logger in the Node.js application is configured to send logs to Loki. You can add Loki as a data source in Grafana to explore, query, and visualize your application logs alongside your metrics.
- Issues: Feel free to open an issue for any bugs or feature requests.
- Pull Requests: Contributions are welcome! Please submit a pull request for any improvements.
