Skip to content

How to install prometheus node-exporter on aws amazon linux ec2 instance?

Published: at 12:00 AM

As you deploy and manage your applications on AWS EC2 instances, monitoring their performance and reliability is crucial.

Prometheus, a popular open-source monitoring system, helps you collect metrics from your infrastructure and applications.

Node-Exporter, a lightweight agent, collects system metrics from your instances and exposes them to Prometheus for analysis.

In this blog post, we will guide you through the step-by-step process of installing Prometheus Node-Exporter on an AWS Amazon Linux EC2 instance.

By the end of this tutorial, you will have a fully functional Node-Exporter setup, providing valuable insights into your instance’s performance.

Table of Contents

Open Table of Contents

Understanding Prometheus Exporters

Before we dive into the installation process, it’s essential to understand the different types of exporters provided by Prometheus.

Exporters are agents that collect metrics from your infrastructure and applications, exposing them to Prometheus for analysis. Prometheus offers a wide range of exporters, each designed to collect specific metrics from various sources.

Different exporters provided by Prometheus

Probes endpoints over HTTP, HTTPS, DNS, TCP, and ICMP.

Collects system metrics such as CPU usage, memory, disk usage, and network statistics from your instances.

Exposes Consul metrics, including service discovery and health checks.

Exposes Graphite metrics, including metrics from Graphite’s carbon cache.

Collects metrics from Memcached, including cache hits, misses, and eviction rates.

Exposes MySQL database metrics, including query performance, connection statistics, and replication status.

Exposes metrics from StatsD, including metrics from the StatsD daemon.

Installation Steps

  1. Download the node-exporter binary

Visit the Prometheus website and download the binary for the node-exporter utility on you ec2 instance. Execute the below command on you ec2 terminal. This will download a tar file on you instance.

wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
  1. Unzip the installation files

Now extract the installation files from the compressed package which you just downloaded. Post this step you will see a folder created.

ls
tar -xzf node_exporter-1.8.2.linux-amd64.tar.gz
  1. Move inside the extracted folder

Now move inside the extracted folder by ececuting the folllowing command.

ls
cd node_exporter-1.8.2.linux-amd64/
  1. Execute the binary

You will find an executable file present. Just simple execute it and the node-exporter utility will be in a running state.

ls
./node_exportera
  1. Test the exporter

Once you execute the above command you can find the exporter running on the port 9100. You can view the metrics by visiting the below url from any of your web browser

http://<instance-public-ip>:9100

NOTE: Make sure you open port 9100 in your ec2 security group

Running prometheus node-exporter screenshot

Problem with this approach

Our node-exporter is running but as we have a problem here. As soon as we close the ec2 terminal the exporter will stop, but we want the exporter to be running along with the instance. And also the exporter should start automatically when the ec2 is turned on.

We can achieve the above functionality by creating a service for the node-exporter.

Create a service for exporter

  1. Copy binary to /usr/local/bin

Copy the node-exporter executable to this path /usr/local/bin. I am assuming that you are already in the folder which contains the executable.

sudo cp node_exporter /usr/local/bin
  1. Create a user for node exporter.

Create a user for the exporter.

sudo useradd node_exporter --no-create-home --shell /bin/false
  1. Change permissions for the executable file.
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
  1. Create service file
sudo vi /etc/systemd/system/node_exporter.service
  1. Add the following content in the service file
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target
  1. Reload the system daemon

Reload the deamon to detech new service files

sudo systemctl daemon-reload
  1. Now, we can start and enable node exporter as a service
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
  1. Check the status of the service
sudo systemctl status node_exporter

Congratulations! The service is running

Summary

In this blog post, we walked through the step-by-step process of installing Prometheus Node-Exporter on an AWS Amazon Linux EC2 instance.

We started by understanding the different types of exporters provided by Prometheus and then downloaded and installed the Node-Exporter binary.

We also created a service for the Node-Exporter to ensure it runs automatically when the EC2 instance is turned on. By the end of this tutorial, you should have a fully functional Node-Exporter setup, providing valuable insights into your instance’s performance.

FAQs

  1. How do I access the Node-Exporter metrics?

You can access the Node-Exporter metrics by visiting the URL http://<instance-public-ip>:9100/metrics in your web browser. Make sure you have opened port 9100.

  1. Why do I need to create a service for Node-Exporter?

Creating a service for Node-Exporter ensures that it runs automatically when the EC2 instance is turned on and continues to run even after you close the terminal.

  1. What are some common issues I may encounter during the installation process?

Some common issues you may encounter during the installation process include permission errors, incorrect file paths, and issues with the EC2 security group configuration.

  1. Can I use Node-Exporter with other monitoring tools?

Yes, Node-Exporter can be used with other monitoring tools, such as Grafana, to provide a more comprehensive monitoring solution.

  1. How often does Node-Exporter collect metrics?

Node-Exporter collects metrics at regular intervals, which can be configured to suit your specific needs.


Next Post
Amazon GuardDuty EC2 Runtime Monitoring is Now Available