Monitoring Real-Time Development with Docker Compose
Now that you have Prometheus configured in your Docker Compose setup, you can start monitoring your application's real-time development.
Visualizing Metrics with Grafana
To get a more comprehensive view of your application's performance, you can integrate Grafana, a popular data visualization tool, with Prometheus. Here's how you can add Grafana to your docker-compose.yml
file:
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
environment:
- POSTGRES_DB=myapp
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypassword
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
volumes:
- grafana-storage:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=password
volumes:
grafana-storage:
In this example, we've added a grafana
service that uses the official Grafana Docker image. We've also created a named volume called grafana-storage
to persist Grafana's configuration and data.
Connecting Grafana to Prometheus
Once you've started your Docker Compose application, you can access the Grafana UI by navigating to http://localhost:3000
in your web browser. You'll need to log in using the default username and password (admin/password
).
To connect Grafana to Prometheus, follow these steps:
- Click on the "Configuration" icon in the left-hand menu and select "Data Sources".
- Click on the "Add data source" button and select "Prometheus".
- Configure the Prometheus data source by setting the URL to
http://prometheus:9090
.
- Click "Save & Test" to verify the connection.
Creating Dashboards
With Grafana connected to Prometheus, you can now create custom dashboards to visualize your application's metrics. Grafana provides a wide range of built-in visualization options, as well as the ability to create your own custom panels and dashboards.
By leveraging Docker Compose, Prometheus, and Grafana, you can effectively monitor the real-time development of your application and gain valuable insights into its performance and behavior.