# Monitoring Containers with Prometheus and cAdviser

## Introduction
In this blog, we will walk through how to monitor containers using Prometheus and cAdviser.

cAdvisor (short for container Advisor) analyzes and exposes resource usage and performance data from running containers. cAdvisor exposes Prometheus metrics out of the box. The container metrics will be collected by cAdvisor and scraped by Prometheus.


# Pre-requisites

- User with `sudo` privileges
- [Docker](https://docs.docker.com/engine/install/) installed

 
# Steps

## Step 1
Configure Prometheus to scrape metrics from cAdvisor. Create a `prometheus.yml` file and paste below code:

```
scrape_configs:
- job_name: cadvisor
  scrape_interval: 5s
  static_configs:
  - targets:
    - cadvisor:8080
```
## Step 2
Now, in the same directory where you have created `prometheus.yml`, create a`docker-compose.yml` file defining both prometheus and cAdviser services. Copy and paste below in the file:
```
version: '3'
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    ports:
      - 9090:9090
    command:
      - --config.file=/etc/prometheus/prometheus.yml
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    depends_on:
      - cadvisor

  cadvisor:
    image: google/cadvisor:latest
    container_name: cadvisor
    ports:
      - 8080:8080
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker:/var/lib/docker:ro
```
## Step 3

Run `docker-compose up -d` to deploy the services and make it running in the background.

To verify the running containers, run `docker ps`. you can also access prometheus web dashboard on `[your-public-ip]:9090` and cAdviser on `[your-public-ip]:8080`
