Grafana with Prometheus Node Exporter
By Taha • 5 minutes read •
In this guide, I will use Fedora 41 Cloud Edition as the base operating system. Some steps may vary depending on the distribution you are using.
- Grafana is a multi-platform open-source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources. Prometheus Node Exporter is a Prometheus exporter for hardware and OS metrics exposed by *NIX kernels, written in Go with pluggable metric collectors. In this guide, we will install and configure Grafana and Prometheus Node Exporter
Step 1: Install Prometheus and Node Exporter
The first step, we need to install Prometheus and Node Exporter. We will install it from the official repository. Run the following commands to install them:
For Debian/Ubuntu:
For CentOS/RHEL:
For Fedora:
After installing this packages, start and enable the services:
Step 2: Install Grafana
Method 1: Install Grafana from Repository
In the next step, we will install Grafana from the official repository. If you want to use Grafana in Docker, you can skip this method. Run the following commands to install Grafana:
For Debian/Ubuntu:
First, install the required packages:
Then, add the Grafana repository key and repository:
| | |
For CentOS/RHEL:
First, install the required packages:
Then, add the Grafana repository key:
Create a file called
grafana.repo
in the/etc/yum.repos.d/
directory and add the following content:[] =grafana =https://rpm.grafana.com =1 =1 =1 =https://rpm.grafana.com/gpg.key =1 =/etc/pki/tls/certs/ca-bundle.crt
Then, install Grafana:
Method 2: Install Grafana in Docker
If you want to use Grafana in Docker, you can follow this step. Run the following commands to install Grafana in Docker:
First, install Docker:
|
Then, start and enable the Docker service:
After installing Docker, create a data directory for Grafana:
Change the directory to
/opt/grafana
and create a file calleddocker-compose.yml
:services: grafana: image: grafana/grafana:latest container_name: grafana restart: unless-stopped ports: - 3000:3000 volumes: - /opt/grafana/data:/var/lib/grafana
Save the file and set the ownership of the directory:
Then run the following command to start Grafana:
If all the steps are successful, you can detach from the container by pressing
Ctrl + C
and run the following command to start Grafana in the background:
Step 3: Access Grafana
- Once you have installed Grafana, you can access it by opening your web browser and navigating to
http://<server-ip>:3000
. The default user name and password areadmin
. You will be asked to change the password after logging in.
Method 1: Using IP Address
If you are not using a reverse proxy and are using a firewall, you can access Grafana using the IP address of the server. Run the following command to allow port 3000
For UFW:
For FirewallD:
Method 2: Using Reverse Proxy
- To use Grafana behind a reverse proxy, you need to configure your web server to forward requests to the Grafana service. Here is a sample configuration for web servers:
Apache
Create a new Apache configuration file for your domain:
Add the following configuration to the file:
<VirtualHost *:80> ServerName your-domain.com Redirect permanent / https://your-domain.com/ </VirtualHost> <VirtualHost *:443> ServerName your-domain.com SSLEngine on SSLCertificateFile /etc/letsencrypt/live/your-domain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.com/privkey.pem ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Save the configuration file and reload Apache:
Caddy
Note: If you don’t have Caddy installed, you can follow this guide to install it.
Open the Caddyfile for editing:
Add the following configuration to the file:
your-domain.com { ... reverse_proxy localhost:3000 }
Note: Replace
your-domain.com
with your actual domain name.Note: If you want to use authorization with Caddy, you can follow this guide.
Save the Caddyfile and reload Caddy:
Nginx
Create a new Nginx configuration file for your domain:
Add the following configuration to the file:
server { listen 80; listen [::]:80; server_name your-domain.com; rewrite ^ https://$host$request_uri? permanent; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name your-domain.com; ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Save the configuration file and enable the site:
Step 4: Add Prometheus Node Exporter to Grafana
After accessing Grafana, you can add Prometheus Node Exporter as a data source.
Click on the left sidebar and navigate to
Connection > Data Sources
.Then click
Add data source
and selectPrometheus
from the list.In the
Connection
section, enter the URL of the Prometheus Node Exporter. The default URL ishttp://localhost:9090
.Note: If you are using the docker method, you can use
http://<MACHINE-IP>:9090
as the URL.Then click
Save & Test
to save the data source.After adding the data source, back to the
Dashboard
and click onCreate Dashboard
.Then click
Import
and enter1860
in theGrafana.com Dashboard
field.Then click
Load
and select the Prometheus data source from the list.Then click
Import
to import the dashboard. You can now see the metrics of Prometheus Node Exporter in Grafana.You can customize the dashboard by adding more panels and changing the settings.
Conclusion
- By using Grafana and the Prometheus Node Exporter, you can monitor your system performance in real time, identify potential problems early and make data-driven decisions. This powerful duo makes it easier than ever to improve operational efficiency. In addition, customisable dashboards allow you to visualise your systems according to your specific needs.