I have a docker-compose as the following:
version: '2'
services:
rabbitmq:
image: rabbitmq:management
ports:
- 5672:5672
- 15672:15672
networks:
- my-network
zipkin:
image: openzipkin/zipkin
ports:
- 9411:9411
networks:
- my-network
redis:
image: redis
ports:
- 6379:6379
networks:
- my-network
ts-ui-dashboard:
build: ts-ui-dashboard
image: ts/ts-ui-dashboard
restart: always
ports:
- 80:8080
networks:
- my-network
ts-route-service:
build: ts-route-service
image: ts/ts-route-service
restart: always
ports:
- 11178:11178
networks:
- my-network
ts-route-mongo:
image: mongo
networks:
- my-network
...
networks:
my-network:
# driver: overlay
driver: bridge
It contains 68 containers and I want to use Prometheus to monitor all of them.
I follow the docker official tutorial to deploy the Prometheus service but it only shows two targets(i.e., docker and prometheus).
I guess here "docker" refers to the whole docker-desktop but what I need is the detailed metrics of each container in my docker-compose
.
What’s the potential way to implement it? Ans as mentioned above there are some containers that are MongoDB, do I need to config Prometheus for them?
2
Answers
It can be solved by using cadvisor+prometheus. I follow the tutorial here and deploy it successfully.
To monitor all containers in your Docker Compose setup using Prometheus, you need to configure Prometheus to scrape metrics from each individual container. Here’s a general outline of the steps you can take:
Instrument Your Containers:
Ensure that the containers you want to monitor expose Prometheus-compatible metrics. This typically involves configuring the applications within your containers to expose metrics in a format that Prometheus can understand. Many applications have built-in metrics endpoints, and for others, you might need to use exporters.
Configure Prometheus:
In your Prometheus configuration file (usually named
prometheus.yml
), you will define your targets and scraping configuration. Each service/container you want to monitor will have its own scrape job configuration. Here’s an example of how you can configure Prometheus to scrape metrics from your services:Container Hostnames:
The target hostnames (
ts-ui-dashboard
,ts-route-service
, etc.) in the Prometheus configuration should match the service names defined in your Docker Compose file. Docker’s built-in DNS resolution will ensure that Prometheus can reach these containers.MongoDB and Other Databases:
For databases like MongoDB, you can use exporters that expose database-specific metrics in a Prometheus-compatible format. For MongoDB, you can use the
mongodb_exporter
exporter. Similar to other services, you’ll need to define a scrape job for the MongoDB exporter in yourprometheus.yml
file.Scrape Interval:
Adjust the
scrape_interval
in the global section of your Prometheus configuration to control how often Prometheus scrapes metrics from the configured targets.Start Prometheus:
Run Prometheus with the configuration you created using a command like
prometheus --config.file=prometheus.yml
.Access Prometheus UI:
After starting Prometheus, you can access its web interface at
http://localhost:9090
(if you’re running Prometheus locally).Explore and Build Queries:
Use the Prometheus UI to explore metrics and build queries to monitor your services. You can create graphs, alerts, and dashboards to visualize the collected data.
Remember that each container you want to monitor needs to have the necessary metrics available and accessible over the network. You might need to adjust your application configurations to enable metrics endpoints or use exporters for some services.
Additionally, make sure that the ports you use for metrics scraping are exposed and reachable within your Docker network.
Note: The Prometheus configuration file and the setup might vary based on your specific setup and the metrics endpoints provided by the services you are using. Always refer to the official documentation of your applications and Prometheus for detailed setup instructions.