Personal Development Category (English)728x90

Monitoring Docker containers using Prometheus + cAdvisor + Grafana

Disclosure: This page uses affiliate links.When you click an affliate link,we get a small compensation at no cost to you.Thanks for your support!Learn more

With the increasing adoption of containers and microservices in the enterprises, monitoring utilities have to handle more services and server instances than ever before. Support for multi-dimensional data collection, querying and perfect dashboard visualization tool is a great strength and makes the right fit to be part of your operational toolset. In this post, we take look at  Monitoring Docker containers using Prometheus + cAdvisor + Grafana.

This quickstart assumes basic understanding of Docker concepts, please refer to earlier posts for understanding on Docker & how to install and containerize applications.


We are going to use the following tools to collect, aggregate & visualize metrics.

  1. Container metrics using cAdvisor
  2. Host metrics using Prometheus Node Exporter
  3. Alerting using Prometheus Alert Manager
  4. Visualization using Grafana pre-built dashboards

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloudPrometheus collects metrics from monitored targets by scraping metrics HTTP endpoints, we are going to configure it to scrape metrics for containers from cAdvisor and node metrics from Prometheus Node exporter.

Monitoring Architecture

Image – Monitoring Architecture

#1. Prepare Docker Compose Configuration

Create New Project directory and prepare Docker compose file like the one below

Subscribe to Emails

More than 100,000 subscribers across the world trust & read Upnxtblog articles. Subscribe to emails updates!
* indicates required
version: '3'
    image: 'prom/prometheus:v2.1.0'
    container_name: prometheus
    - '9090:9090'
    - '--config.file=/etc/prometheus/prometheus.yml'
    - '--storage.tsdb.path=/prometheus'
    - '--web.console.libraries=/usr/share/prometheus/console_libraries'
    - '--web.console.templates=/usr/share/prometheus/consoles'
    - './prometheus.yml:/etc/prometheus/prometheus.yml:ro'
    - './alert.rules:/etc/prometheus/alert.rules'
    - cadvisor
    - samplenet
    image: google/cadvisor
    container_name: cadvisor
    - '8081:8081'
    - '/:/rootfs:ro'
    - '/var/run:/var/run:rw'
    - '/sys:/sys:ro'
    - '/var/lib/docker/:/var/lib/docker:ro'
    - samplenet
    image: prom/alertmanager
    - '9093:9093'
    - './alertmanager/:/etc/alertmanager/'
    restart: always
    - '--config.file=/etc/alertmanager/config.yml'
    - '--storage.path=/alertmanager'
    - samplenet
    image: prom/node-exporter
     - '/proc:/host/proc:ro'
     - '/sys:/host/sys:ro'
     - '/:/rootfs:ro'
     - '--path.procfs=/host/proc'
     - '--path.sysfs=/host/sys'
     - '--collector.filesystem.ignored-mount-points'
     - ^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)
     - '9100:9100'
     - samplenet
    restart: always
    image: grafana/grafana
    - prometheus
    - '3000:3000'
    - 'grafana_data:/var/lib/grafana'
    - './grafana/provisioning/:/etc/grafana/provisioning/'
    - ./grafana/config.monitoring
    - samplenet
    restart: always
grafana_data: {}
prometheus_data: {}

#2.Prometheus Node Exporter Configuration

On the compose file, mount the host /proc and /sys directory so that the container has access to the necessary information to report on.

#3.cAdvisor Configuration

On the compose file, mount the var/run, /sys directory /var/lib/docker so that the cAdvisor can collect container metrics and report to Prometheus.

#4.Prometheus Configuration

Create new Prometheus configuration in a file called prometheus.yml . Prometheus server requires a configuration file that defines the endpoints to scrape along with how frequently the metrics should be accessed and to define the servers and ports that Prometheus should scrape data from. In the below example, we have defined 3 targets (1st one for Prometheus itself, 2nd One for collecting container metrics using cAdvisor and last one is for node metrics using Node exporter) running on different ports.

Devops Engineer Masters Program will make you proficient in DevOps principles like CI/CD, Continuous Monitoring and Continuous Delivery, using tools like Puppet, Nagios, Chef, Docker, Git & Jenkins. It includes training on Linux, Python, Docker, AWS DevOps Certification Training and Splunk. The curriculum has been determined by extensive research on 5000+ job descriptions across the globe.
New customer offer! Top courses from $13.99 when you first visit Udemy
- job_name: prometheus
scrape_interval: 5s
- targets:
- prometheus:9090

- job_name: cadvisor
scrape_interval: 5s
- targets:
- cadvisor:8081

- job_name: node-exporter
scrape_interval: 5s
- targets:
- node-exporter:9100

- static_configs:
- targets: 
- alertmanager:9093

- 'alert.rules'

For a complete specification of configuration options, see the configuration documentation.

#5.Alert Manager Configuration

Alert Manager takes care of de-duplicating, grouping, and routing the alerts to the correct receiver integration such as email, slack channels, etc.,

Recover over 700 unique file formats. Fully recover documents, emails, photos, videos, audio files and more. Supports 8 different data lost scenarios: deleted files recovery, recycle bin recovery, formatted drive recovery, lost partition recovery, externa

We are going to make use of default configuration like the example below, create a new folder alertmanager and paste the configuration file (config.yml)

   receiver: 'slack'

   - name: 'slack'
      - send_resolved: true
      username: '<username>'
      channel: '#<channel-name>'
      api_url: '<incomming-webhook-url>'

#6.Grafana Configuration

Grafana would be the dashboard visualization tool of choice for Prometheus users and support for Grafana ships with the tool. For monitoring Docker containers, we are going to import pre-built dashboards from

Create new folder Grafana and copy the contents from the source to automate the provisioning of data sources & dashboards. For the full Grafana installation instructions, see the official Grafana documentation.

Finally, our folder would look like the one below.

Monitoring Folder structure

Image – Monitoring Folder structure

Congrats! we have now configured all tools to monitor our containers, let’s start the compose and check.

#7.View Metrics

Start the Docker compose using docker-compose up -d

Once all the containers are up, Prometheus will now scrape and store the data based on the configuration. Prometheus is configured on port 9090, Go to the dashboard http://localhost:9090 and verify that Prometheus now has information about the time series information on the containers, node.

Career Category (English)640x480

Use the dropdown next to the “Execute” button to see a list of metrics this server is collecting. In the list, you’ll see a number of metrics prefixed with node_, that have been collected by the Node Exporter. For example, you can see the node’s CPU usage via the node_cpu metric.

With this expression browser, you can enter any expression and see its result either in a table or graph over time.

Prometheus Dashboard

Image – Prometheus Dashboard

Grafana will be listening on http://localhost:3000. The default login is "admin" / "admin", once you log in use the “Filter” option to browse for dashboards. From the list, choose “Docker Prometheus Monitoring” to view it.

Node metrics

Image – Host metrics

Google IT Support Professional Certificate by Grow with Google (300x600) - 2
Container Metrics / Alerts

Image – Container Metrics / Alerts

If you want to modify Dashboard or data source, you should manually edit the downloaded JSON files and correct the datasource: entries to reflect the Grafana data source name which you chose for your Prometheus server. Use the “Dashboards” → “Home” → “Import” option to import the edited dashboard file into your Grafana install.

All source files used for this article can be found here.

In this post, we have got introduced on how to set up targets in Prometheus, configure Prometheus, cAdvisor, Node Exporter and Alert Manager to monitor both containers and host resources.

Like this post? Don’t forget to share it!

Additional Resources

Monitoring Docker containers using Prometheus + cAdvisor + Grafana
Article Name
Monitoring Docker containers using Prometheus + cAdvisor + Grafana
In this post,we take look at how to monitoring Docker containers using Prometheus + cAdvisor + Grafana.
Publisher Name
Publisher Logo

2 thoughts on “Monitoring Docker containers using Prometheus + cAdvisor + Grafana”

  1. Pingback: How to Build and run your app with Compose
  2. Trackback: How to Build and run your app with Compose
  3. Pingback: Do you inspect your containers?
  4. Trackback: Do you inspect your containers?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: