White Birch Technologies

Introduction

Welcome to this comprehensive guide on setting up node_exporter and Prometheus to efficiently collect, aggregate, and store metrics from Linux endpoints. In the ever-evolving landscape of IT infrastructure management, understanding how to gather and utilise performance data is crucial for maintaining optimal system health and performance.

In this tutorial, we will walk you through the process of deploying and configuring these essential monitoring tools on Ubuntu 22.04 servers. While we will focus on Ubuntu for demonstration purposes, the concepts discussed can be applied to other Linux distributions as well.

It’s important to note that while we’ll cover the installation and configuration of node_exporter and Prometheus, securing these applications is beyond the scope of this article. However, stay tuned, as we plan to delve into securing node_exporter, Prometheus, and the connection between them in future articles.

Prometheus, on its own, provides metrics solely about its own performance. To extend its capabilities to monitor other systems, we’ll leverage Prometheus to scrape metrics from various endpoints. Once scraped, these metrics are collected and stored within Prometheus, providing a centralised repository for analysis and visualisation.

To enable Prometheus to scrape metrics from external systems, we’ll need to install exporters. These exporters serve as bridges between Prometheus and the target systems, exposing specific metrics for collection.

Prerequisites

Before we dive into the installation and configuration process, let’s ensure we have the necessary prerequisites in place:

  • An Ubuntu 22.04 LTS server for installing node_exporter.
  • An Ubuntu 22.04 LTS server for installing Prometheus.
  • An Ubuntu 22.04 LTS server for installing Grafana, which we’ll use for visualisation purposes.

With these prerequisites fulfilled, let’s embark on this journey to empower your infrastructure monitoring capabilities with node_exporter and Prometheus.

Step 1 - Preparing the Prometheus server

It is important that we create designated user accounts for both Prometheus and node_exporter. We do not want to run both these services as the root user. Therefore we will be creating secure accounts, by disabling their home directory and shell, we can accomplish this.

Perform the following command(s) on the Prometheus server:
				
					sudo useradd --no-create-home --shell /bin/false prometheus

				
			

Now that we have a secure Linux user account for Prometheus, we have to create the directories to store the Prometheus configuration.

Perform the following command(s) on the Prometheus server:
				
					# Create the Prometheus configuration directory.
sudo mkdir /etc/prometheus

# Change the directory ownership to the Prometheus user and group.
sudo chown prometheus:prometheus /etc/prometheus

# Change the directory permissions accordingly.
sudo chmod 750 /etc/prometheus
				
			

Last but not least, let’s create the necessary firewall rules to allow the required connection between our Prometheus and node_exporter server.

Perform the following command(s) on the Prometheus server:
				
					# Create a UFW rule that allows traffic on port 9090.
sudo ufw allow 9090/tcp comment 'Allow Prometheus traffic on port 9090/tcp'

# Create a UFW rule that allows traffic on port 9100.
sudo ufw allow 9100/tcp comment 'Allow node_exporter traffic on port 9100/tcp'

# (Optional) Create a UFW rule that allows traffic on port 22.
# If you forget this UFW rule, it is possible that you will lock yourself out
# from your own server, make sure that this UFW rule exists before you enable
# the firewall.
sudo ufw allow 22/tcp comment 'Allow SSH traffic on port 22/tcp'

# Enable the Firewall
sudo ufw enable
				
			

Last but not least, let’s create the necessary firewall rules to allow the required connection between our Prometheus and node_exporter server.

Step 2 - Installing Prometheus