Day75 ---> 90DaysOfDevOps Challenge @TWS

Day75 ---> 90DaysOfDevOps Challenge @TWS

Monitor Docker Containers 🐳 with Grafana Dashboard📊

Pre-requisites:

  1. Grafana server is up and running with data source Prometheus configured.

  2. One Linux instance to serve as a Docker Engine.

image

image

image

image

Let's get started--->

  • Install Docker and start the docker service on your Linux EC2 instance (Ubuntu 20.04 LTS) and configure docker to send metrics to prometheus.
sudo apt install docker.io -y
sudo usermod -aG docker $USER
sudo reboot
sudo systemctl enable docker
sudo systemctl status docker

image

image

Create this file "/etc/docker/daemon.json" and Add the below contents

{
    "metrics-addr" : "0.0.0.0:9323",
    "experimental" : true
}

image

Create 2 Docker containers and run any basic application on those containers.

image

image

image

image

image

Now integrate the docker containers and share the real-time logs with Grafana.

Add your "Target machine details" to this Prometheus configuration file

image

Check your Prometheus server's Target section for updates

image

image

Create a dashboard for your Docker Engine to monitor containers

image

image

image

image

image

image

image

image

Check the logs or docker container names on Grafana UI.

To retrieve more detailed docker container logs you need another exporter like Cadvisor to send data to Prometheus.

image

Let's install Cadvisor first on your target servers--->

sudo apt install cadvisor

image

image

Configure your Prometheus to scrap data from Cadvisor's metrics--->

sudo vim /etc/prometheus/prometheus.yml

Add the below data to the above prometheus.yml file

global:
  scrape_interval: 10s

scrape_configs:
  - job_name: 'prometheus_metrics'
    scrape_interval: 5s
    static_configs:
      - targets: ['3.237.177.101:9090']

  - job_name: 'Cadvisor'
    scrape_interval: 5s
    static_configs:
      - targets: ['44.211.96.219:8080']

image

Check Prometheus targets updated with Cadvisor

image

Now let's build our dashboard to see running container names--->

image

Create a new panel and use "container_tasks_state" metrics--->

image

image

Give proper visualization to the table with some background colour--->

image

Add some metrics check for Prometheus Server and Docker host server memory utilization

image

Arrange the layout of the dashboard as per your ease to monitor--->

image

That's great to monitor your resources with such a wonderful dashboard ✨

Happy Learning :)

Day 75 task is complete!

90DaysOfDevOps Tasks👇

github.com/Chaitannyaa/90DaysOfDevOps.git

Chaitannyaa Gaikwad | LinkedIn