Skip to main content

Command Palette

Search for a command to run...

Monitoring Containers with Prometheus and cAdvisor πŸ³πŸ“Š

Published
β€’3 min read
Monitoring Containers with Prometheus and cAdvisor πŸ³πŸ“Š
P

πŸ‘‹ Hello! I'm passionate about DevOps and have over 1+ years of experience in the field. I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together!

SKILLS:

πŸ”Ή Languages & Runtimes: Python, Shell Scripting, HCL, YAML πŸ”Ή Cloud Technologies: AWS, Microsoft Azure, GCP πŸ”Ή Infrastructure Tools: Docker, Terraform, AWS CloudFormation πŸ”Ή Other Tools: Linux, Git and GitHub Actions, Jenkins, Jira, GitLab (beginner), Docker, AWS DevOps πŸ”Ή Web Development: HTML, CSS, Bootstrap, Python, SQL

Job & Responsibilities:

πŸš€ Improved development efficiency by implementing CI/CD pipelines, resulting in a 30% reduction in deployment time on the test server. πŸ”’ Strengthened deployment and testing reliability by utilizing Docker containers and optimizing Dockerfile, reducing development issues on the test server by 20%. βš™οΈ Automated S3 bucket log creation with Shell scripting, eliminating 100% of manual search and saving 2 hours per week. πŸ“… Scheduled EC2 instance start/stop using Lambda functions and Event Bridge, leading to a 25% decrease in infrastructure costs. πŸ”§ Utilized AWS, Linux, Python, Docker, Shell scripting, Terraform, Jenkins Pipelines, and automation to streamline workflows and improve overall system performance.

I'm very detail-oriented and possess strong written and verbal communication skills. As a high performer with a possibility mindset, I strive to solve problems using efficient approaches.

Let's Connect & Grow:

If you find my profile suitable for the role you are searching for, please feel free to reach out to me at sumanprasad9766@gmail.com.

Introduction:

In the world of containerized applications, monitoring and gathering performance data is essential to ensure the reliability and efficiency of your services. cAdvisor, short for Container Advisor, is a powerful tool that allows you to analyze and expose resource usage and performance data from running containers. This article will guide you through setting up a monitoring stack using Prometheus, cAdvisor, and Grafana to help you gain insights into your containerized applications. πŸš€

What is cAdvisor? 🧐

cAdvisor is a container monitoring tool developed by Google. It provides real-time information about resource usage, performance metrics, and container statistics. One of its significant advantages is that it exposes metrics in a format compatible with Prometheus, a popular open-source monitoring and alerting toolkit. πŸ“ˆ

Setting Up Prometheus πŸ› οΈ

To get started with Prometheus, follow these steps:

  • Download the Prometheus Configuration File πŸ“₯:

  •       wget https://raw.githubusercontent.com/prometheus/prometheus/main/documentation/examples/prometheus.yml
    
  • Install Prometheus Using Docker πŸ‹:

    Run Prometheus in a Docker container, using the configuration file you downloaded:

  •       docker run -d --name=prometheus -p 9090:9090 -v <PATH_TO_prometheus.yml_FILE>:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml
    

Adding cAdvisor as a Target 🎯

To start collecting metrics from cAdvisor, add it as a scrape target in your Prometheus configuration. Edit the prometheus.yml file you downloaded earlier and append the following configuration:

scrape_configs:
- job_name: cadvisor
  scrape_interval: 5s
  static_configs:
  - targets:
    - cadvisor:8080

Using Docker Compose 🐳🀝

For a more streamlined setup, you can use Docker Compose. Create a docker-compose.yaml file with the following content:

version: '3.2'
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:ro
    depends_on:
    - cadvisor
  cadvisor:
    image: gcr.io/cadvisor/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
    depends_on:
    - redis
  redis:
    image: redis:latest
    container_name: redis
    ports:
    - 6379:6379

Run Prometheus and cAdvisor with Docker Compose:

docker-compose up -d

You can check the status of the containers using:

docker-compose ps

Visualizing Metrics with Grafana πŸ“ŠπŸ“ˆ

To visualize the collected metrics, you can use Grafana, a popular open-source dashboard and visualization platform.

Installing Grafana on Debian or Ubuntu πŸ“ŠπŸ§

  1. Install the required dependencies:
  •       sudo apt-get install -y apt-transport-https
          sudo apt-get install -y software-properties-common wget
    
  • Add the Grafana GPG key and repository:

sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key

For the stable release, add:

echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

Or for the beta release, add:

  •       echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com beta main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
    
  • Update the package list:

  •       sudo apt-get update
    
  • Install Grafana:

  •       sudo apt-get install grafana
    
  • Start Grafana:

  •      sudo /bin/systemctl start grafana-server
    

Now, you can access Grafana at http://localhost:3000 and set up dashboards to visualize the metrics collected by Prometheus from cAdvisor.

Conclusion πŸŽ‰

By setting up Prometheus with cAdvisor and Grafana, you have created a robust container monitoring stack. You can now effectively monitor the resource usage and performance metrics of your containerized applications, helping you to make data-driven decisions and ensure the health and performance of your services. Happy monitoring! πŸš€πŸ³πŸ“ˆ

More from this blog

D

DeployToCloud

405 posts

πŸ‘‹ Welcome to my Hashnode blog! I'm a DevOps Engineer with 2+ years of experience. Join ~5k followers and explore 320+ blogs on Python, AWS, Docker, Jenkins, Linux, and more. Let's connect & grow πŸš€