Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
How to Provide the Static IP to a Docker Container?
Next article icon

How to use Prometheus to Monitor Docker Containerized Applications

Last Updated : 29 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Containerization has transformed software development by providing portability and consistency through platforms like Docker. Yet ensuring the health of those containerized applications requires monitoring. Prometheus is a monitoring tool that uses its powerful features to monitor the application and make sure that the application is in good health. In this article first, you will understand what is, and then I will guide you through the steps to monitor your Docker container by using Prometheus.

What is Prometheus Exporter?

Prometheus is an open-source monitoring and alerting toolkit, which collects time series data from various sources, allowing users to monitor and analyze metrics related to system performance. It also monitors resource utilization and application location.

What is Docker Prometheus Grafana?

  • Docker: Imagine it as a magic box containing all the parts that an app needs to function. It makes arranging apps simple and neat without creating any issues with your PC.
  • Prometheus: Think of it as an inquiring acquaintance who monitors the efficiency of your apps. It collects information about their internal states, such as their acceleration rate and level of overloading.
  • Grafana: This is comparable to a cool artist creating colorful graphs and visuals out of all the Prometheus data. It allows you to quickly assess how well your apps are functioning.

Steps to use Prometheus to Monitor Docker Applications

Step 1: Setup Prometheus on Linux and Windows

  • Install Prometheus on Ubuntu by using the below command. If you want the latest version, you can get a link from the official page.
wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
tar xvfz prometheus-2.48.1.linux-amd64.tar.gz

install-prometheus-on-ubuntu

  • If you are using windows then use these commands to install Prometheus.
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.49.1/prometheus-2.49.1.windows-amd64.zip
unzip prometheus-2.49.1.windows-amd64.zip

after-install-prometheus

  • Then you have to configure the daemon.json on Ubuntu . This will ensure docker daemon as a Prometheus target .
  • In Ubuntu daemon.json is present in /etc/docker/ directory.
vi /etc/docker/daemon.json
{
"metrics-addr": "0.0.0.0:9323",
"experimental":true
}

Adding metrics in docker daemon.json file

  • After editing the daemon.json you have to save and restart your docker service.
sudo service docker restart
  • If you are using docker desktop on windows then you first have to open Docker desktop and then edit docker engine file .
  {
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": true,
"metrics-addr": "0.0.0.0:9323"
}

Editing docker-engine

Then you can save and restart the docker desktop .

What is Node Exporter and configure

A small application called Node Exporter is installed on your PC or server. It functions similar to a detective who is always monitoring the system and collecting information about things like CPU, RAM, disk space, and other things. subsequently, it propagates this data to Prometheus and other monitoring tools.

Setup Node Exporter (Optional)

Here are the steps to set up Node Exporter on Linux:

  • Download Node Exporter: Go to the Prometheus GitHub releases page and download the latest version of Node Exporter for Linux.
  • Extract the Downloaded File: Once downloaded, extract the Node Exporter file using a tool like tar.
  • Move Node Exporter to a Folder: Move the extracted Node Exporter folder to a location like /usr/local/bin/ for easy access.
  • Create a Service File: Create a service file for Node Exporter using a text editor like nano or vim. This file tells Linux how to manage Node Exporter.
  • Add Service Configuration: In the service file, specify the command to start Node Exporter.
  • Reload systemd and Start the Service: Reload systemd to recognize the new service file and start Node Exporter using systemctl commands.
  • Enable Auto-Start on Boot: Enable Node Exporter to start automatically whenever the system boots up.
  • Check Node Exporter Status: Verify that Node Exporter is running without errors by checking its status.
  • Access Metrics: You can now access Node Exporter metrics through a web browser using http://<your_server_ip>:9100/metrics.

Run the Node Exporter Container: Node Exporter image, run the container with the following command:

docker run -d --name=node-exporter -p 9100:9100 prom/node-exporter
dockercon

List the container by using the below command

docker ps
docker-nodeex

Step 2: Scrape Container Metrics

  • For Ubuntu Users: Edit the prometheus.yml to scrape all your container metrics from http://localhost:9323/metrics.
cd prometheus-2.48.1.linux-amd64
vi prometheus.yml

Here is the simple and sample scrap config file. Based on your requirements update the scrap config file.

global:
scrape_interval: 10s
scrape_configs:
- job_name: promethheus
static_configs:
- targets:
- localhost:9090
- job_name: docker
static_configs:
- targets:
- localhost:9323

Configuring prometheus.yml

  • For Windows Users: Edit the configuration file to scrape all your container metrics as shown in the below.
cd prometheus-2.49.1.windows-amd64
vi prometheus.yml

editing prometheusyml-on-windows

  • For Ubuntu Users: Now start the Prometheus server and connect it on.
./prometheus

run-prometheus-server-on-ubuntu

  • For Windows UsersBased: Now start the Prometheus server and connect it as shown in the image below.
./prometheus.exe

run-prometheus-server

Step 3: Setup Alertmanager (Optional)

  • Download Alertmanager: Go to the Prometheus website and download the Alertmanager binary that matches your operating system. For Linux, you'll typically download a tarball.
  • Extract the Tarball: Once downloaded, extract the contents of the tarball to a location on your Linux system using the tar command. For example:
tar -xzf alertmanager-*.tar.gz
  • Configure Alertmanager: Inside the extracted directory, you'll find a configuration file named alertmanager.yml or alertmanager. yaml. Customize this file according to your requirements. You'll typically define the notification integrations (like email, Slack, etc.) and their configurations here.
  • Start Alertmanager: After configuring Alertmanager, you can start it by running the Alertmanager binary. You can do this from the directory where you extracted the tarball.
./alertmanager --config.file=alertmanager.yml

You may want to run Alertmanager as a background service or use tools like Systemd to manage it as a service.

  • Verify Alertmanager is Running: You can verify that Alertmanager is running by accessing its web interface. By default, it runs on port 9093. Open your web browser and navigate to http://localhost:9093 to access the Alertmanager interface. You should see the Alertmanager UI, indicating that it's up and running.
  • Integrate with Prometheus: Lastly, you need to configure Prometheus to send alerts to Alertmanager. This is typically done by configuring Prometheus's prometheus.yml file to include an alerting rule file (alerting.rules.yml), where you define the conditions for triggering alerts. In this file, specify the alertmanager_url parameter to point to your Alertmanager instance.

Step 4: Output

There are many metrics exposed in http://localhost:9323/metrics. You can choose any query and execute it on the Prometheus server. For example, to see the number of containers in stop state use this query "engine_daemon_container_states_containers{state="stopped"}"
Viewing the containers in-stopped-state

To know more about the Installation of Docker, Read this Article.

Docker Metrics: We can visit this URL to see all the exposed metrics of your Docker service.

http://localhost:9323/metrics
metrics

What is Push Gateway?

Consider Pushgateway as a metrics mailbox. Prometheus typically gathers metrics from your various services and machines on its own. Yet, some objects, like temporary jobs, are not always capable of sending measures directly to Prometheus.

Basically, Pushgateway acts as a mailbox for these jobs to deposit their measurements. Prometheus then visits, checks the mailbox and gets those metrics. In this manner, your monitoring system incorporates even difficult metrics from contract work!

People also Ask

Article

Link

Installation of Docker on Ubuntu

Read

Installation of Docker on Windows

Read

Conclusion

You have first understood what is Prometheus. Then you have then learned about how to install Prometheus and configure Prometheus to extract metrics from your Docker containers. At the end, you have also executed a PromQL query to see a number of containers in the stopped state. You have now successfully completed all the steps to use Prometheus to monitor docker containers.


Next Article
How to Provide the Static IP to a Docker Container?

P

pranitrout72
Improve
Article Tags :
  • Docker
  • Geeks Premier League
  • DevOps
  • Geeks Premier League 2023

Similar Reads

  • How to Use AWS Fargate to Deploy Containerized Applications without Managing Servers?
    Fargate provides a server-less architecture, where we do not need to worry about the backend infrastructure on which our application gets deployed. Fargate provides of a simple provisioned infrastructure that is entirely managed and taken care by aws. Application deployment becomes easy and efficien
    4 min read
  • How to Provide the Static IP to a Docker Container?
    Docker is an open-source project that makes it easier to create, deploy and run applications. It provides a lightweight environment to run your applications.It is a tool that makes an isolated environment inside your computer. Think of Docker as your private room in your house. Living with your fami
    2 min read
  • How To Use Docker For IoT Applications?
    Docker is a super tool that makes our lives much less complicated by providing us with standardization, productivity, performance, maintainability, and compatibility of our code. It lets us continuously and hastily install and test our code, and it is platform-impartial. Docker provides the ability
    8 min read
  • How to Use Ansible for Docker Container Management
    Containerization has become one of the foundations for realizing scalable, reliable, and efficient application deployments in modern DevOps practice. Docker, as a leading containerization platform, enables developers to package applications and all dependencies into containers for consistency across
    9 min read
  • How to Run GUI Based Applications inside Docker?
    A Docker Container is an isolated application platform that contains everything needed to run an application built from one or more images. Docker is an Open Source project that provides an open platform to run any number of applications inside a container according to your requirements and you can
    7 min read
  • How to Monitor Containers with the Podman "ps" Command
    In the realm of containerization, where applications are bundled into units, for deployment it's crucial to have insight into the operational status of these containers. The Podman 'ps command provides a perspective, on this landscape enabling you to oversee and control your active containers. Termi
    5 min read
  • How to Use ELK Stack to Log Docker Containerized Events
    Creating and delivering applications today requires packaging. Docker is one of the most popular container systems that allows developers to separate applications and their container dependencies. However, monitoring and logging events in the Docker container is important for the system's security,
    5 min read
  • How to Use AWS CLI in Docker Container ?
    The AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. Integrating AWS CLI within a Docker container can significantly streamline workflows, especially for development and deployment processes that rely on cloud infrastruct
    4 min read
  • Docker Compose Tool To Run aMulti Container Applications
    The article talks about how to run multi-container applications using a single command. Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you can configure a file (YAML file) to configure your docker containers. Then Once you configured the Yaml fil
    8 min read
  • Containerizing Applications with Docker Compose: Step-by-Step Tutorial
    In the present quickly developing scene of software development and deployment, containerization has arisen as a unique advantage. It offers a solution for the perpetual test of ensuring consistency in software conditions across different phases of the development lifecycle and different sending tar
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences