How to Download and Run Node Exporter Using Docker

Prometheus Node Exporter is a popular open-source exporter of machine metrics that can be used with Prometheus, a monitoring toolkit. It provides a wide array of system metrics including, but not limited to, CPU, disk I/O, memory, network, and more. This guide will walk you through the process of downloading and running Node Exporter within a Docker container.

If you are new to Prometheus, check out our detailed article on what is Prometheus.

Prerequisites

  1. Make sure you have Docker installed on your system. If you don't, you can download it from the official Docker website here. Follow the instructions based on your operating system (Windows, MacOS, or Linux).

  2. Basic knowledge of command-line interface.

Step-by-step Guide

Step 1: Pull the Node Exporter Docker image

The first step is to pull the official Prometheus Node Exporter Docker image from Docker Hub. Run the following command in your terminal:

docker pull prom/node-exporter

This command will download the latest version of Node Exporter. If you need a specific version, append :<version> at the end of the image name, like prom/node-exporter:v1.1.2.

Step 2: Run the Node Exporter container

After pulling the image, the next step is to run the Node Exporter within a Docker container. The following command will create and run a new Docker container named node_exporter, mapping the container's port 9100 to the host's port 9100. This is the default port Node Exporter uses to expose metrics.

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

Here is a breakdown of the command:

  • -d: This option runs the container in the background (detached mode).

  • -p 9100:9100: This maps the host's port 9100 to the container's port 9100.

  • --name=node_exporter: This assigns a name to the container. In this case, it's node_exporter.

  • prom/node-exporter: This is the image that we pulled in the previous step.

Step 3: Verify that Node Exporter is running

You can verify that Node Exporter is running and exposing metrics by navigating to http://localhost:9100/metrics in your browser. If Node Exporter is running properly, you should see a list of metrics being exposed.

Alternatively, you can use the curl command in the terminal:

curl http://localhost:9100/metrics

Step 4: Configuring Prometheus to scrape Node Exporter metrics

If you want to set up Prometheus using Docker, check out our guide.

Now that Node Exporter is running and exposing metrics, you need to configure Prometheus to scrape these metrics. In your Prometheus configuration file (prometheus.yml), add the following job:

scrape_configs:
  - job_name: 'node'
    scrape_interval: 5s
    static_configs:
      - targets: ['<IP_ADDRESS>:9100']

Replace <IP_ADDRESS> with the IP address of the machine where Node Exporter is running. If Prometheus and Node Exporter are running on the same machine, you can use localhost or 127.0.0.1.

Restart your Prometheus server to apply these changes.

That's it! Prometheus should now be scraping metrics from Node Exporter. You can verify this by navigating to the Prometheus expression browser (http://<PROMETHEUS_IP_ADDRESS>:9090/graph) and querying for any metric that Node Exporter exposes.

Conclusion

In this guide, we've learned how to pull and run the Node Exporter Docker image, verify that Node Exporter is running and exposing metrics, and configure Prometheus to scrape these metrics. With these steps, you should be able to monitor machine metrics with Prometheus and Node Exporter.