Monitoring Infrastructure and Containers with Prometheus

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Prometheus is able to monitor our infrastructure and applications at multiple levels: on the host itself, on any containers, and on the application. In this hands-on lab, we’re going to address the first two options for monitoring: our virtual machine host and our containers. We’ll first set up monitoring for our virtual machine by using Prometheus’s Node Exporter, and then we’ll set up container monitoring for the provided container using Google’s cAdvisor. By the time we’re done, we’ll be able to view metrics across two levels of our system in Prometheus to track changes and view trends on our systems.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set up the Node Exporter.

Work on the application server.

  1. Create a system user:

    $ sudo useradd –no-create-home –shell /bin/false node_exporter

  2. Download the Node Exporter from Prometheus’s download page:

    $ cd /tmp/
    $ wget

  3. Extract its contents:

    $ tar -xvf node_exporter-0.17.0.linux-amd64.tar.gz

  4. Move into the newly-created directory:

    $ cd node_exporter-0.17.0.linux-amd64/

  5. Move the provided binary:

    $ sudo mv node_exporter /usr/local/bin/

  6. Set the ownership:

    $ sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

  7. Create a systemd service file:

    $ sudo vim /etc/systemd/system/node_exporter.service

    Description=Node Exporter



    Save and exit when done.

  8. Start the Node Exporter:

    $ sudo systemctl start node_exporter

Set up cAdvisor.

Work on the application server.

  1. Launch cAdvisor:

    $ sudo docker run

  2. List available containers to confirm it’s working:

    $ docker ps

Add the new endpoints to Prometheus.

Work on the monitoring server.

  1. Open the Prometheus configuration file:

    $ sudo vim /etc/prometheus/prometheus.yml

  2. Add the Node Exporter and cAdvisor endpoints:

    - job_name: 'node_exporter'
      - targets: ['']
    - job_name: 'cadvisor'
      - targets: ['']
  3. Save and exit.

  4. Restart Prometheus:

    $ sudo systemctl restart prometheus

  5. Check the Targets page on the web UI to ensure the endpoints are working.

Additional Resources

Your company has recently implemented Prometheus to monitor all facets of the infrastructure — from virtual machines to containers to the applications sitting in those containers. As part of this initiative, you have been tasked with ensuring any virtual machines and containers running on those virtual machines have been set to export metrics we can use with Prometheus.

You have been provided with access to the monitoring server that houses our Prometheus setup, as well as an application server. Add the Node Exporter to the application server, and also ensure cAdvisor is deployed on a container on that same server to monitor any applications running on Docker. Make sure cAdvisor is using port 8000 when viewed on the host. When finished, add the Node Exporter and cAdvisor endpoints to Prometheus and ensure everything is working.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?