Docker Monitoring using Prometheus, cAdvisor, Node Exporter and Grafana

Docker Monitoring using Prometheus, cAdvisor, Node Exporter and Grafana

#Day80 of #90DaysOfDevOps

ยท

4 min read

Introduction:)

Today, we embark on a hands-on journey into the realm of Prometheus, focusing on the creation of a comprehensive Docker monitoring dashboard.

Interi Arc Ghostface GIF - Interi Arc Ghostface Hello GIFs


Prerequisites:

Before we dive into the world of container monitoring, let's ensure we have the necessary prerequisites in place.

  • A EC2 Linux server running Docker with latest version of Docker Compose

  • Ports 9090, 9100 and 3000 accessible from monitoring tools

  • Basic Linux administration and Docker familiarity


Step to monitoring containers

Lets Go Bullish GIF - Lets Go Bullish Car GIFs

1. Grafana Installation:

2. Docker and Docker-Compose:

  • Docker Installation: Install Docker on your EC2 instance by following the official Docker installation guide for Amazon Linux.

  • Docker-Compose Installation: Install Docker-Compose using the following commands:

      sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
      sudo chmod +x /usr/local/bin/docker-compose
      docker-compose --version
    

3. Prometheus, cAdvisor, and Node Exporter:

4. Node Exporter Installation:

  • Node Exporter Download: Download Node Exporter using the following command:

      wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
    
  • Node Exporter Setup: Unzip the downloaded file and run Node Exporter to start collecting system metrics.

      tar xvfz node_exporter-1.0.1.linux-amd64.tar.gz
      cd node_exporter-1.0.1.linux-amd64
      ./node_exporter &
    

5: Create Docker Containers with a Todo App

Step 1: Pull the Docker image from your Docker Hub repository

docker pull simbaa815/node-todo

Step 2: Create a Docker network

  • Create a Docker network to facilitate communication between containers. You can use the following command:

      docker network create todo-net
    

    Using a Docker network is not strictly required, but it is a good practice for creating isolated communication channels between containers.

Step 3: Run two containers

  • Run two containers with a basic todo app, each connected to the previously created network.

      docker run -d --network todo-net --name todo-app-1 your-todo-image
      docker run -d --network todo-net --name todo-app-2 your-todo-image
    

  • You can check the running containers using:

      docker ps
    

6. Integrate Prometheus with Grafana server

Step 1: Access Grafana

Login to the Grafana web console using your browser. The default address is usually http://your_server_ip:3000. Log in with your Grafana credentials.

Step 2: Add Prometheus as a Data Source

  1. In Grafana, navigate to the gear icon ( โ˜ฐ ) on the left sidebar and click on "Data Sources."

  2. Click on the "Add your data source" or the "Add data source" button.

  3. Choose "Prometheus" from the list of available data sources.

  4. Configure the Prometheus data source:

  5. Scroll down and click on "Save & Test" to verify the connection. If the connection is successful, Grafana will display a green "Data source is working" message.

6: Create Dashboards and Visualizations

  1. In Grafana, go to the "+" icon on the left sidebar and select "Dashboard."

  2. Click on "Add new panel" to create a new visualization.

  3. In the panel settings, choose the "Prometheus" data source you just added.

  4. Enter a Prometheus query to retrieve the desired metrics. You can use the Prometheus Query Editor to build your queries.

  5. Customize the visualization settings, such as axes, legends, and visualization type.

  6. Click on "Apply" to save the panel settings.


Conclusion:)

In conclusion, our monitoring journey has been a success. We've established a robust infrastructure, integrating Grafana, Docker, Docker-Compose, and Prometheus to monitor our Docker containers effectively.

Dance Funny GIF - Dance Funny GIFs


Connect with me:)

Thank you for diving into this blog with me! I trust you found the information both helpful and enlightening. To stay updated on the latest in DevOps ๐Ÿš€, make sure to follow me. Remember, staying informed means staying ahead in the dynamic world of DevOps!

Feel free to connect with me on:

LinkedIn

Twitter

GitHub

For more updates and engaging discussions on DevOps, let's connect! ๐Ÿš€ #DevOpsCommunity

ย