Grafana is an open-source and multi-platform data visualization platform developed by Grafana Labs. Grafana provides an interactive data visualization web application that includes charts, graphs, and alerts. With Grafana, you can query, visualize, set up alerts, and explore metrics, logs, and traces of TSDB. It is a powerful tool that turns time-series database (TSDB) data into an insightful graph and visualization.

In Grafana, you can add your time-series database data via the ‘Data Source’. Grafana supports multiple data sources such as Prometheus, InfluxDB, PostgreSQL, Loki, Jaeger, Graphite, Google Cloud Monitoring, AWS CloudWatch, Azure Monitor, and many more.

In this tutorial, you’ll learn how to install Grafana, Prometheus, and node_exporter on Ubuntu 24.04 servers. You’ll also install Nginx as a reverse proxy for Grafana, integrate node_exporter and Prometheus, and then add Prometheus as a data source to the Grafana dashboard.

Prerequisites

Before you begin, make sure you have:

  • Two or three Ubuntu 24.04 servers.
  • A non-root user with administrator privileges.

Installing Grafana on Ubuntu

Grafana is a web application for data visualization. To install Grafana, you need to add the Grafana repository. In this example, you’ll also install Nginx as a reverse proxy for Grafana.

Installing dependencies and adding a repository

In this section, you’ll install dependencies including Nginx, then add the Grafana repository.

First, run the command below to install dependencies for Grafana. Type Y to confirm the installation.

sudo apt install gnupg2 apt-transport-https software-properties-common wget nginx

<img alt="install deps" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/1-install-deps.png66746c244449c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="306" loading="lazy" src="data:image/svg xml,” width=”750″>

Now add Grafana GPG key and repository with the following command.

wget -q -O - https://packages.grafana.com/gpg.key > grafana.key cat grafana.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/grafana.gpg > /dev/null
echo ‘deb [signed-by=/etc/apt/trusted.gpg.d/grafana.gpg] https://packages.grafana.com/oss/deb stable main’ | sudo tee /etc/apt/sources.list.d/grafana.list

Then, update and refresh your package index with the command below:

sudo apt update

<img alt="add repo and update" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/2-add-grafana-repo.png66746c2494053.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="218" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing and configuring Grafana

After adding the Grafana repository, you’ll install the Grafana package with the APT package manager. And then configure Grafana to run at localhost with the domain such as hwdomain.io.

To install Grafana, run the following apt command. Type Y to proceed with the installation.

sudo apt install grafana

<img alt="install grafana" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/3-install-grafana.png66746c24ea15f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="307" loading="lazy" src="data:image/svg xml,” width=”750″>

After the installation is finished, reload the systemd manager with the command below:

sudo systemctl daemon-reload

Now you can start and enable the grafana-server with the following systemctl command. Then, verify to ensure the service is running.

sudo systemctl enable --now grafana-server

sudo systemctl status grafana-server

In the following output, you can see the grafana-server is running and enabled.

<img alt="start enable verify grafana" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/4-start-enable-check-grafana.png66746c2551ad4.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="280" loading="lazy" src="data:image/svg xml,” width=”750″>

With the grafana-server running, you’ll configure it to run at localhost.

Open the Grafana configuration /etc/grafana/grafana.ini with nano editor.

sudo nano /etc/grafana/grafana.ini

Change the default configuration with the following. Make sure to change the domain option with your local domain name for Grafana. For this example, you’ll run Grafana within the domain hwdomain.io.

[server]

# The IP address to bind to, empty will bind to all interfaces
http_addr = localhost

# The http port  to use
http_port = 3000

# The public facing domain name used to access grafana from a browser
domain = hwdomain.io

When finished, save the file and exit the editor.

Now run the command below to restart grafana-server and apply your changes. With this, Grafana should be running on localhost with the default HTTP port 3000.

sudo systemctl restart grafana-server

Setting up Nginx as a reverse proxy

In this section, you’ll create a new Nginx server block as a reverse proxy for the grafana-server that is running on localhost with port 3000.

Create a new Nginx server block configuration /etc/nginx/sites-available/grafana.conf with nano editor.

sudo nano /etc/nginx/sites-available/grafana.conf

Add the following configuration to set up Nginx as a reverse proxy for Grafana. Make sure to change the server_name option with your Grafana domain name.

# this is required to proxy Grafana Live WebSocket connections.
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
    listen      80;
    server_name hwdomain.io;

  root /usr/share/nginx/html;
  index index.html index.htm;


  access_log /var/log/nginx/grafana-access.log;
  error_log /var/log/nginx/grafana-error.log;

  location / {
    proxy_set_header Host $http_host;
    proxy_pass http://localhost:3000/;
  }

  # Proxy Grafana Live WebSocket connections.
  location /api/live {
    rewrite  ^/(.*)  /$1 break;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $http_host;
    proxy_pass http://localhost:3000/;
  }
}

Save the file and exit the editor.

Now run the following command to activate the grafana.conf server block and verify your Nginx syntax. If you’ve proper syntax, you’ll see an output test is Successful - syntax is OK.

sudo ln -s /etc/nginx/sites-available/grafana.conf /etc/nginx/sites-enabled/

sudo nginx -t

<img alt="setup nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/5-setup-nginx-reverse-proxy.png66746c258a3bd.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="179" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, run the systemctl command below to restart and verify the Nginx web server status.

sudo systemctl restart nginx

sudo systemctl status nginx

You’ll see the Nginx web server is running:

<img alt="check nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/6-check-nginx.png66746c25d2210.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="219" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, visit your Grafana domain name such as http://hwdomain.io/. If your installation is successful, you will be prompted with the Grafana login page.

Log in with the default user admin and password admin.

<img alt="login grafana" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/7-login-grafana.png66746c262a182.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="550" loading="lazy" src="data:image/svg xml,” width=”531″>

Once logged in, enter new password for your Grafana installation and click Submit to confirm.

<img alt="change password" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/8-change-password-grafana.png66746c267166c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="658" loading="lazy" src="data:image/svg xml,” width=”521″>

You’ll see the Grafana dashboard like the following:

<img alt="dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/9-grafana-dashboard.png66746c26bcb03.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="388" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing and configuring Prometheus

Prometheus is a monitoring and alerting platform. With the Grafana running, you’ll install Prometheus on the server 192.168.5.16.

Installing Prometheus

In this section, you’ll install Prometheus manually by downloading the binary of Prometheus to your system. Before that, you’ll also create a new system user and prometheus.

First, run the command below to add a new user and group prometheus.

sudo groupadd --system prometheus

sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Create a new data directory /var/lib/prometheus and configuration directories /etc/prometheus.

sudo mkdir -p /var/lib/prometheus

for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done

Download Prometheus latest version for Linux with the following command.

curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest|grep browser_download_url|grep linux-amd64|cut -d ‘"’ -f 4|wget -qi -

Once downloaded, extract the Prometheus binary file with tar command and go into it.

tar xvf prometheus*.tar.gz

cd prometheus*/

Move binary file prometheus and promtool to the /usr/local/bin directory. And then move configuration directories and the file prometheus.yml to /etc/prometheus directory.

sudo mv prometheus promtool /usr/local/bin/

sudo mv consoles console_libraries prometheus.yml /etc/prometheus/

Lastly, run the command below to change the permission and ownership of the Prometheus configuration and data directory to the user prometheus.

for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done

for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done

sudo chown -R prometheus:prometheus /var/lib/prometheus/

<img alt="install promethes" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/11-install-prometheus.png66746c2720a90.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="118" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring Prometheus

After you’ve installed Prometheus, you’ll secure Prometheus using the basic_auth or basic authentication.

Install the apache2-utils package with the following apt command.

sudo apt install apache2-utils -y

<img alt="install apache2-utils" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/12-install-apache-utils.png66746c276cde9.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="303" loading="lazy" src="data:image/svg xml,” width=”750″>

Now run the htpasswd command below to generate bcrypt password for user admin. Type your password and repeat, and then copy the generated password.

htpasswd -nB admin

Next, run nano command below to create a new file /etc/prometheus/web.yml.

sudo nano /etc/prometheus/web.yml

Add the following configuration and make sure to change the bcrypt password below.

# basic_auth
basic_auth_users:
  admin: $2y$05$s8U/BrE5JhSO31XKSbtj8u8cPECULs3emEhlDfCB2GW1UefQ9x00C

Save and exit the file when finished.

Now open the default Prometheus configuration /etc/prometheus/prometheus.yml with nano.

sudo nano /etc/prometheus/prometheus.yml

Change the default job_name for prometheus like the following and make sure to change the basic_auth user and password.

scrape_configs:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    # add settings for certificate and authentication
    scheme: http
    basic_auth:
      username: "admin"
      password: "password"

    static_configs:
      # if using a valid certificate, set the same hostname in the certificate
      - targets: ["localhost:9090"]

Save and exit the file.

Lastly, run the command below to change the ownership of files prometheus.yml and web.yml to the user prometheus.

sudo chown prometheus: /etc/prometheus/{prometheus.yml,web.yml}

Running Prometheus as a systemd service

Create a new systemd service file /etc/systemd/system/prometheus.service with the following nano editor.

sudo nano /etc/systemd/system/prometheus.service

Add the following lines to the file. With this, you’ll run Prometheus in the background as a systemd service and secure web console through the web.yml file.

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus 
 --config.file=/etc/prometheus/prometheus.yml 
 --storage.tsdb.path=/var/lib/prometheus 
 --web.console.templates=/etc/prometheus/consoles 
 --web.console.libraries=/etc/prometheus/console_libraries 
 --web.listen-address=0.0.0.0:9090 
 --web.config.file=/etc/prometheus/web.yml 

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

Save the file and exit the editor.

Now run the command below to reload the systemd manager and apply your changes.

sudo systemctl daemon-reload

<img alt="configure prometheus" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/13-configure-prometheus.png66746c27c7a0c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="351" loading="lazy" src="data:image/svg xml,” width=”750″>

Then, start and enable prometheus service using the systemctl command below, and make sure that the service is running.

sudo systemctl enable --now prometheus

sudo systemctl status prometheus

In the following output, you can see the prometheus service is running and enabled.

<img alt="check prometheus" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/14-check-prometheus.png66746c28182a6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="235" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing node_exporter

Now that Grafana and Prometheus are running, you’ll download and install node_exporter. The node_exporter allows you to scrape data for basic system monitoring.

Download the node_exporter binary file with the curl command below.

curl -s https://api.github.com/repos/prometheus/node_exporter/releases/latest| grep browser_download_url|grep linux-amd64|cut -d ‘"’ -f 4|wget -qi -

Once downloaded, extract the node_exporter and go into it.

tar -xvf node_exporter*.tar.gz cd node_exporter*/

Now copy the node_exporter binary file to the /usr/local/bin directory.

sudo cp node_exporter /usr/local/bin

After that, run the following command to create a new systemd service file /etc/systemd/system/node_exporter.service for the node_exporter.

sudo tee /etc/systemd/system/node_exporter.service <<EOF

[Unit]

Description=Node Exporter

Wants=network-online.target

After=network-online.target[Service]

User=prometheus

ExecStart=/usr/local/bin/node_exporter

[Install]

WantedBy=default.target

EOF

<img alt="install node exporter" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/15-install-node-exporter.png66746c286a0ee.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="432" loading="lazy" src="data:image/svg xml,” width=”750″>

Reload the systemd manager with the following:

sudo systemctl daemon-reload

Now you can start and enable the node_exporter service with the command below. And then, check the node_exporter service status.

sudo systemctl enable --now node_exporter sudo systemctl status node_exporter

You’ll see the node_exporter service is running and will start collecting and populating data. The node_exporter service is running on the default port 9100.

<img alt="start check node_exporter" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/16-run-check-node-exporter.png66746c28b7698.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="310" loading="lazy" src="data:image/svg xml,” width=”750″>

Integrating node_exporter to Prometheus

In this section, you’ll integrate and add node_exporter to the Prometheus.

Open the default Prometheus configuration /etc/prometheus/prometheus.yml.

sudo nano /etc/prometheus/prometheus.yml

Add a new job_name with the name node_exporter and point the target to the target such as 192.168.5.16:9100.

  - job_name: "node_exporter"

    static_configs:
      - targets: ["192.168.5.100:9100"]

Save and exit the file when you’re done.

Now run the command below to restart the prometheus service and apply the changes.

sudo systemctl restart prometheus

Next, access the Prometheus server http://192.168.5.16:9090 through your web browser and you’ll be prompted for basic authentication.

Enter your username and password and click Sign In.

<img alt="Log in prometheus" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/17-login-prometheus.png66746c28e6f34.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="326" loading="lazy" src="data:image/svg xml,” width=”589″>

After logged in to the Prometheus dashboard, enter node_memory_Active_bytes in the query and click Execute. You’ll see the graph of current active memory like the following:

<img alt="prometheus dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/18-prometheus-dashboard.png66746c29264a7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="387" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, click Status > Targets and make sure both prometheus and node_exporter targets is active and running like the following:

<img alt="list targets" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/19-list-targets.png66746c298788e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="264" loading="lazy" src="data:image/svg xml,” width=”750″>

Integrating Prometheus with Grafana as a data source

Now that Prometheus is ready, you’ll add and integrate Promethues to the Grafana as a data source. Then, you’ll create a new dashboard system for monitoring.

Within the Grafana dashboard, click Connections > Data Sources > Add data source to add a new data source in Grafana.

<img alt="add data source" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/20-add-data-source.png66746c29d5e28.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="227" loading="lazy" src="data:image/svg xml,” width=”750″>

Select Prometheus as the data source.

<img alt="prometheus" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/22-prometheus.png66746c2a2b7f9.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="302" loading="lazy" src="data:image/svg xml,” width=”727″>

Enter the Prometheus URL like http://192.168.5.16:9090/ and enter the username and password for your Prometheus server.

<img alt="add prometheus details" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/23-prometheus-details.png66746c2a660af.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="723" loading="lazy" src="data:image/svg xml,” width=”642″>

Scroll to the bottom and click Save & test. If successful, you’ll see the message Successfully queried the Prometheus API.

<img alt="save and test data source" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/24-save-and-test.png66746c2a9434a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="244" loading="lazy" src="data:image/svg xml,” width=”604″>

After adding Prometheus as the data source, you’ll create a new Grafana dashboard for the system monitoring.

Click on the menu Dashboard > Create dashboard.

<img alt="create dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/25-create-dashboard.png66746c2ad34b8.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="273" loading="lazy" src="data:image/svg xml,” width=”750″>

Select Import dashboard to import dashboard.

<img alt="import dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/26-import-dashboard.png66746c2b34e76.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="409" loading="lazy" src="data:image/svg xml,” width=”750″>

Visit https://grafana.com/grafana/dashboards/ and find your suitable dashboard. In this example, you’ll load the Grafana dashboard with id 15172.

Click Load to import the dashboard.

<img alt="Load dashboard id" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/27-load-dashboard.png66746c2b68d62.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="403" loading="lazy" src="data:image/svg xml,” width=”640″>

Now select Prometheus backend and click Import to confirm.

<img alt="select prometheus as backend" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/28-add-prometheus.png66746c2bd458d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="750" loading="lazy" src="data:image/svg xml,” width=”684″>

If everything goes well, your Grafana dashboard should be created. Below is the screenshot from the Grafana dashboard with the Prometheus and node_exporter monitoring:

<img alt="dashboard monitoring" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/29-dashboard.png66746c2c1b381.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="407" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Congratulations! You’ve completed the installation of Grafana, Prometheus, and node_exporter on Ubuntu 24.04 servers. You’ve Grafana running with Nginx as a reverse proxy, secured Prometheus with password authentication, integrated node_exporter with Prometheus, added Prometheus as a data source to the Grafana, and imported the Grafana dashboard.