Collecting Linux Server Metrics with Prometheus

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Prometheus uses a pull model to periodically scrape metric data from targets. In order to collect data, you will need to set up an entity that is able to provide metric data, and then configure the Prometheus server to scrape it. In this lab, you will walk through the process of configuring Prometheus monitoring for a Linux server.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Install and Configure Node Exporter on the LimeDrop Web Server
  1. Log in to the LimeDrop web server to perform the following steps.

  2. Create a user and group that will be used to run Node Exporter:

    sudo useradd -M -r -s /bin/false node_exporter
  3. Download and extract the Node Exporter binary:

    tar xvfz node_exporter-0.18.1.linux-amd64.tar.gz
  4. Copy the Node Exporter binary to the appropriate location and set ownership:

    sudo cp node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/
    sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
  5. Create a systemd unit file for Node Exporter:

    sudo vi /etc/systemd/system/node_exporter.service
  6. Define the Node Exporter service in the unit file:

    Description=Prometheus Node Exporter
  7. Start and enable the service:

    sudo systemctl daemon-reload
    sudo systemctl start node_exporter
    sudo systemctl enable node_exporter
  8. Test that your Node Exporter is working by making a request to it from localhost. You should get some metric data on the screen in response to this request:

    curl localhost:9100/metrics
Configure Prometheus to Scrape Metrics from the LimeDrop Web Server
  1. Log in to the Prometheus server to perform the following steps.

  2. Edit the Prometheus config file:

    sudo vi /etc/prometheus/prometheus.yml
  3. Locate the scrape_configs section and add a new entry under that section:

      - job_name: 'LimeDrop Web Server'
        - targets: ['']
  4. Restart Prometheus to load the new config:

    sudo systemctl restart prometheus
  5. Navigate to the Prometheus expression browser in your web browser using the public IP address of your Prometheus server: <PROMETHEUS_SERVER_PUBLIC_IP>:9090.

  6. Run the following query to verify you are able to get some metric data from the LimeDrop web server:

    node_filesystem_avail_bytes{job="LimeDrop Web Server"}

Additional Resources

You recently started a new job at LimeDrop, a subscription service that provides weekly shipments of limes to customers. Earlier, you set up a Prometheus server to help provide monitoring for the company's infrastructure. One Linux web server might benefit particularly from this monitoring, as it has recently had some stability problems.

Your task is to configure Prometheus to collect metric data from this Linux server. Install Node Exporter on the server, and then configure the Prometheus server to scrape metrics from that exporter.

If you get stuck, feel free to check out the solution video or the detailed instructions under each objective. Good luck!

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?