DEV Community

Cover image for Monitoring Linux Servers with Node Exporter, Prometheus, and Grafana: A Comprehensive Guide
Noble Mutuwa  Mulaudzi
Noble Mutuwa Mulaudzi

Posted on

Monitoring Linux Servers with Node Exporter, Prometheus, and Grafana: A Comprehensive Guide

Server monitoring is a critical aspect of managing a robust infrastructure. In this comprehensive guide, we'll explore how to set up an efficient and versatile monitoring system for Linux servers using Node Exporter, Prometheus, and Grafana. This combination of tools allows you to collect, store, and visualize performance metrics, providing valuable insights into your server's health and performance.

Article By Noble Mutuwa Mulaudzi

Architecture diagram

Image description

Prerequisites

Before we dive into the setup, here are the prerequisites you'll need:

  • An AWS EC2 instance running a Linux distribution (e.g., Ubuntu).

  • SSH access to the instance.

  • Basic knowledge of Linux command-line operations.

Step 1: Install Node Exporter

Node Exporter is a tool for collecting system-level metrics. Here's how to install it:

  • Download and install Node Exporter:
wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
tar xvfz node_exporter-1.2.2.linux-amd64.tar.gz
sudo mv node_exporter-1.2.2.linux-amd64/node_exporter /usr/local/bin/

Enter fullscreen mode Exit fullscreen mode
  • Create a systemd service unit file for Node Exporter:
sudo nano /etc/systemd/system/node_exporter.service

Enter fullscreen mode Exit fullscreen mode

Add the following content to the file:

[Unit]
Description=Node Exporter
After=network.target

[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=always

[Install]
WantedBy=multi-user.target

Enter fullscreen mode Exit fullscreen mode
  • Reload systemd and start Node Exporter:
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter

Enter fullscreen mode Exit fullscreen mode

Step 2: Install Prometheus

Prometheus is a monitoring and alerting system. Here's how to install it:

  • Download and install Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.30.2/prometheus-2.30.2.linux-amd64.tar.gz
tar xvfz prometheus-2.30.2.linux-amd64.tar.gz
sudo mv prometheus-2.30.2.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.30.2.linux-amd64/promtool /usr/local/bin/

Enter fullscreen mode Exit fullscreen mode
  • Create a Prometheus configuration file:
sudo nano /etc/prometheus/prometheus.yml

Enter fullscreen mode Exit fullscreen mode

Add the following basic configuration:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['your-instance-ip:9100']

Enter fullscreen mode Exit fullscreen mode
  • Create a systemd service unit file for Prometheus:
sudo nano /etc/systemd/system/prometheus.service

Enter fullscreen mode Exit fullscreen mode

Add the following content to the file:

[Unit]
Description=Prometheus
After=network.target

[Service]
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml
Restart=always

[Install]
WantedBy=multi-user.target

Enter fullscreen mode Exit fullscreen mode
  • Reload systemd and start Prometheus:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus

Enter fullscreen mode Exit fullscreen mode

Step 3: Install Grafana

Grafana is a visualization and dashboarding tool for monitoring. Here's how to install it:

  • Add the Grafana APT repository and install Grafana:
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana

Enter fullscreen mode Exit fullscreen mode
  • Start and enable the Grafana service:
sudo systemctl start grafana-server
sudo systemctl enable grafana-server

Enter fullscreen mode Exit fullscreen mode

Access Grafana:

  • Grafana's web interface is available at http://your-instance-ip:3000. You can log in with the default username and password: admin/admin. It's recommended to change the password after the initial login.

  • You can now configure your data source and dashboards to monitor your infrastructure

Image description

  • Above is our Grafana GUI, with beautiful dashboard showing CPU usage of our target machines

Article By Noble Mutuwa Isaya Mulaudzi

***************Thank you*************

Top comments (0)