Grafana is an open-source and multi-platform data visualization platform developed by Grafana Labs. Grafana provides an interactive data visualization web application which 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 guide, you will install Grafana on the Debian 12 server with Nginx as a reverse proxy, then add Prometheus as the data source and configure the Grafana Dashboard for system monitoring.

Prerequisites

Before you proceed, make sure you have the following:

Adding Grafana Repository

In this guide, you will be installing Grafana via the official Grafana repository. To do that, you must add the Grafana repository to your Debian server.

To get started, run the following command to install basic dependencies to your Debian machine.

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

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

Now add the Grafana GPG key and repository by executing the following command.

curl -fsSL https://packages.grafana.com/gpg.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/grafana.gpg

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

Lastly, update and refresh your Debian package index to apply the changes.

sudo apt update

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

Installing Grafana

Now that you’ve added the Grafana repository, you will be installing Grafana via APT. Then, you will configure the administrator user and password for your Grafana installation.

Install Grafana to your Debian system using the following command. Input y to proceed with the installation.

sudo apt install grafana

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

After installation is completed, reload the systemd manager by executing the following command.

sudo systemctl daemon-reload

Then, start and enable the grafana-server service using the command below.

sudo systemctl start grafana-server

sudo systemctl enable grafana-server

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

Once the grafana-server is running, verify it using the command below. If everything goes well, you should see the grafana-server is enabled and running.

sudo systemctl status grafana-server

<img alt="verify grafana" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/5-verify-grafana.png663d92759de41.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="219" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, launch your web browser and visit your server IP address with default Grafana port 3000, such as http://192.168.5.20:3000/.

Input the default user admin and password admin, then click Login.

<img alt="login grafana" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/6-login-grafana.png663d9275d4cea.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="601" loading="lazy" src="data:image/svg xml,” width=”637″>

Now change the default admin password with a new password. Then click Submit to confirm.

<img alt="change admin password" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/7-change-password.png663d927614db7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="711" loading="lazy" src="data:image/svg xml,” width=”629″>

When the process is finished, you should see the Grafana dashboard like the following:

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

Configuring Grafana

With Grafana installed, the next step is to configure Grafana by modifying the default configuration /etc/grafana/grafana.ini and set up the http_addr to localhost, http_port to 3000, and the domain with a local domain name grafana.hwdomain.io.

Open the default Grafana configuration /etc/grafana/grafana.ini using the following nano editor command.

sudo nano /etc/grafana/grafana.ini

Change the default configuration with the following lines. In this example, you will run Grafana on localhost and with the local domain name grafana.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 = grafana.hwdomain.io

When you’re done, save and exit the file.

Now run the following systemctl command to restart the grafana-server and apply the changes. With this, your Grafana installation is running on localhost only.

sudo systemctl restart grafana-server

Installing Nginx as a Reverse Proxy

In this guide, you will run Grafana with Nginx as a reverse proxy. Now, complete the following tasks to install and configure Nginx as a reverse proxy for your Grafana installation.

Run the following command to install the Nginx web server to your Debian machine. Input y to proceed with the installation.

sudo apt install nginx

<img alt="install nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/9-install-nginx.png663d92769e5eb.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="316" loading="lazy" src="data:image/svg xml,” width=”640″>

After Nginx is installed, run the following nano editor command to create a new server block file /etc/nginx/sites-available/grafana.conf.

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

Insert the following configuration and be sure to change the domain name within the server_name parameter.

# This is required to proxy Grafana Live WebSocket connections.

map $http_upgrade $connection_upgrade {

    default upgrade;

    '' close;

}

server {

    listen      80;

    server_name grafana.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 and close the file when finished.

Next, run the following command to activate the server block file /etc/nginx/sites-available/grafana.conf. Then, verify your Nginx syntax to ensure that you have proper syntax.

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

sudo nginx -t

If you have the correct Nginx syntax, you should get the output ‘test is successful – syntax is ok‘.

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

Lasy, run the following systemctl command to restart the Nginx service and apply the changes. Then, verify Nginx to ensure that the service is running.

sudo systemctl restart nginx

sudo systemctl status nginx

In the following output, you should see the Nginx service is running.

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

To access your Grafana server, you can modify the /etc/hosts file on your local machine if you’re a Linux or MacOS user. For Windows users, edit the file C:WindowsSystem32driversetchosts as administration.

Input the following configuration to the file.

192.168.5.15    grafana.hwdomain.io

Save and close the file when finished.

Now back to the web browser and visit your local domain name for the Grafana server, such as http://grafana.hwdomain.io/. If your configuration is successful, you will be redirected to the Grafana login page.

Log in with your admin user and password, then click Login to confirm.

<img alt="grafana login" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/12-grafana-reverse-proxy.png663d92773d51e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="526" loading="lazy" src="data:image/svg xml,” width=”750″>

Now you should get the Grafana admin dashboard.

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

Adding Authentication to the Prometheus Server

Before adding Prometheus to Grafana, you will set up basic authentication for Prometheus. You will generate the basic authentication password with apache2-utils, then enable basic_auth for the Prometheus server.

In this example, the Prometheus and Node Exporter are installed on different servers with IP address 192.168.5.15 and the hostname prometheus.

Log in to the Prometheus server and install the apache2-utils package via the apt command below.

sudo apt install apache2-utils -y

<img alt="install apache2-utils" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/14-install-apache2-utils.png663d9277c0870.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="263" loading="lazy" src="data:image/svg xml,” width=”644″>

After that, generate the new password for the Prometheus basic authentication. Input your password and copy the generated password to your note.

htpasswd -nB promadmin

<img alt="generate password" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/15-geenrate-password.png663d927808f6f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="161" loading="lazy" src="data:image/svg xml,” width=”665″>

Now, create a new Prometheus configuration /etc/prometheus/web.yml using the following nano editor command.

sudo nano /etc/prometheus/web.yml

Add the following configuration to secure the Prometheus administration dashboard with the basic_auth module.

# basic_auth

basic_auth_users:

  promadmin: $2y$05$UlvHd4An.oQRt2UdUXzr9eZ6ShRLe3xYbMhw8ePfvGeLuu0khO4Bu

Save and close the file when finished.

Next, open the default Prometheus configuration /etc/prometheus/prometheus.yml using the following nano editor command.

sudo nano /etc/prometheus/prometheus.yml

Add the basic_auth configuration below within the Prometheus job. Be sure to change the details user and password with your data.

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: 'promadmin'

      password: 'password'

Save and close the file when you’re done.

<img alt="add basic_auth" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/16-add-basic-auth.png663d92783773e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="409" loading="lazy" src="data:image/svg xml,” width=”669″>

Next, run the following command to edit the prometheus service file.

sudo systemctl edit --full prometheus

Change the default ExecStart option with the following.

ExecStart=/usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --web.config.file=/etc/prometheus/web.yml

Save and close the file when finished.

<img alt="change ExecStart" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/17-modify-prometheus-service.png663d927866a91.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="127" loading="lazy" src="data:image/svg xml,” width=”750″>

Now, run the following systemctl command to reload the systemd manager and apply the changes. Then, restart the prometheus service.

sudo systemctl daemon-reload

sudo systemctl restart prometheus

Verify the prometheus service using the below command.

sudo systemctl status prometheus

Within the ExecStart section, the command has changed like the following.

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

Lastly, open your web browser and visit the Prometheus IP address with port 9090 (i.e: http://192.168.10.15:9090/). You will be prompted with the Prometheus basic_auth, input your admin user and password, then click Sign In.

<img alt="login prometheus" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/19-login-prometheus.png663d9278ecf43.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="263" loading="lazy" src="data:image/svg xml,” width=”750″>

If your configuration is successful, you should see the Prometheus dashboard like the following.

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

Integrating Prometheus with Grafana Dashboard

After configuring Basic authentication on Prometheus, you can add Prometheus as the data source to the Grafana dashboard. There are two steps that you must complete: add Prometheus as the data source and then import or create a Grafana dashboard for your system monitoring.

Adding Prometheus Data Source

Back to the Grafana Dashboard, click the Connections menu, and select Data source.

<img alt="connection data source" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/21-add-data-sources.png663d92796c37d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="154" loading="lazy" src="data:image/svg xml,” width=”395″>

Click Add data source to continue.

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

Select the time series database Prometheus.

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

Input the name of the new data source and Prometheus host to http://192.168.5.15:9090/. Within the Authentication section, select Basic Authentication and input the username and password for Prometheus.

<img alt="setup prometheus data source" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/24-add-prometheus-details.png663d9279f22ec.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="684" loading="lazy" src="data:image/svg xml,” width=”750″>

Scroll down and click Save & test to confirm. The output ‘Successfully queried the Prometheus API.‘ confirms that Prometheus has been added to Grafana.

<img alt="add prometheus" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/25-save-test-success.png663d927a2e878.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="328" loading="lazy" src="data:image/svg xml,” width=”750″>

Importing Dashboard Monitoring

Click the menu at the top-right and select Import Dashboard.

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

Find your desired Dashboard at https://grafana.com/grafana/dashboards/. Then, copy and paste the dashboard ID, and click Load to confirm. In this case, we’ll be using Dashboard ID 15172.

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

Input the dashboard name and select the Prometheus data source. Then click Import to confirm.

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

Below is an example of the improved Grafana Dashboard with Prometheus to monitor the system.

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

You have now successfully installed Grafana on a Debian 12 server with Nginx as a reverse proxy, added Prometheus as the data source to Grafana, and imported the Grafana dashboard for system monitoring.