How to Install Prometheus and Grafana on an Ubuntu VPS Print

  • Prometheus Node Exporter, Ubuntu VPS monitoring, install Grafana Ubuntu, Node Exporter, Grafana dashboard, Grafana HTTPS, Prometheus Grafana tutorial, Ubuntu 24.04, Prometheus, VPS performance monitoring, install Prometheus Ubuntu, Ubuntu 26.04, KVM VPS, Grafana alerts, Grafana, Prometheus systemd, Linux server monitoring, Owned Networks
  • 0

How to Install Prometheus and Grafana on an Ubuntu VPS

Prometheus and Grafana provide a powerful monitoring solution for Linux servers, virtual private servers, and application infrastructure.

Prometheus collects and stores time-series metrics, while Grafana transforms those metrics into interactive dashboards. Combined with Node Exporter, these tools allow administrators to monitor CPU utilization, memory consumption, disk performance, network traffic, and overall server health.

In this guide, you will learn how to install Prometheus, Node Exporter, and Grafana on an Ubuntu VPS, configure metric collection, create monitoring dashboards, enable HTTPS, and understand how to configure alerts.

The instructions apply to Ubuntu 24.04 LTS, Ubuntu 26.04 LTS, and other supported Ubuntu releases.

Prerequisites

  • An Ubuntu VPS with root or sudo access.
  • SSH access to the server.
  • At least 2 GB of RAM for a small monitoring deployment; 4 GB or more is preferable when monitoring multiple systems.
  • Sufficient disk space for metrics retention.
  • A domain or subdomain pointing to the VPS if HTTPS access is required.
  • Basic familiarity with Linux services and networking.

Need a server for your monitoring infrastructure? Explore Owned Networks KVM VPS hosting for full root access and flexible server resources.

1. Understand the Prometheus Monitoring Architecture

A typical Prometheus and Grafana deployment contains three main components:

  • Prometheus: Collects and stores metrics from configured monitoring targets.
  • Node Exporter: Exposes Linux system metrics in a format Prometheus can collect.
  • Grafana: Queries Prometheus and displays metrics through customizable dashboards.

The monitoring process works as follows:

Linux VPS
   |
   | System Metrics
   v
Node Exporter
   |
   | HTTP Metrics Endpoint
   v
Prometheus
   |
   | PromQL Queries
   v
Grafana
   |
   v
Monitoring Dashboard

Prometheus typically collects metrics at regular intervals, while Grafana queries the stored data to display historical trends and current performance.

2. Update Ubuntu Packages

Update your package repositories:

sudo apt update

Review available upgrades:

apt list --upgradable

Apply approved updates during an appropriate maintenance window:

sudo apt upgrade -y

Production recommendation: Review package changes before upgrading critical systems. Some updates may require restarting services or rebooting the VPS.

3. Install Prometheus and Node Exporter

Ubuntu provides packages for Prometheus and Node Exporter.

Install both components:

sudo apt install -y prometheus prometheus-node-exporter

Verify the installed versions:

prometheus --version
prometheus-node-exporter --version

Check their service status:

sudo systemctl status prometheus --no-pager
sudo systemctl status prometheus-node-exporter --no-pager

The installed versions depend on the Ubuntu release and configured repositories.

Ubuntu repository packages may differ from the latest upstream releases. For production environments, evaluate package support, security updates, and compatibility before choosing an installation method.

4. Secure Prometheus Network Access

Prometheus commonly uses TCP port 9090 for its web interface and API.

For a single-server deployment, Prometheus should generally listen only on localhost.

On Ubuntu installations using the distribution package, review:

/etc/default/prometheus

Back up the configuration before making changes:

sudo cp -a /etc/default/prometheus \
/etc/default/prometheus.backup

Open the file:

sudo nano /etc/default/prometheus

Find the ARGS variable and ensure the Prometheus startup arguments include:

--web.listen-address=127.0.0.1:9090

For example, if no other startup arguments are required:

ARGS="--web.listen-address=127.0.0.1:9090"

Important: Preserve any existing arguments required by your installation. Do not replace the entire variable without reviewing its current contents.

Restart Prometheus:

sudo systemctl restart prometheus

Verify the listening address:

sudo ss -tlnp | grep 9090

Prometheus should now listen on 127.0.0.1:9090.

Test the local health endpoint:

curl -fsS http://127.0.0.1:9090/-/healthy

Security recommendation: Avoid exposing the Prometheus API directly to the public internet. Use private networking, SSH tunneling, or an authenticated reverse proxy when remote access is necessary.

5. Configure Node Exporter

Node Exporter commonly exposes Linux system metrics on TCP port 9100.

Check whether the service is running:

sudo systemctl status prometheus-node-exporter --no-pager

Check its listening address:

sudo ss -tlnp | grep 9100

For a local monitoring deployment, restrict Node Exporter to localhost.

On Ubuntu packages, review the configuration file:

/etc/default/prometheus-node-exporter

Back it up:

sudo cp -a /etc/default/prometheus-node-exporter \
/etc/default/prometheus-node-exporter.backup

Edit the configuration:

sudo nano /etc/default/prometheus-node-exporter

Ensure the startup arguments include:

--web.listen-address=127.0.0.1:9100

For example, if no other arguments are required:

ARGS="--web.listen-address=127.0.0.1:9100"

Restart Node Exporter:

sudo systemctl restart prometheus-node-exporter

Verify the endpoint:

curl -fsS http://127.0.0.1:9100/metrics | head -n 20

Node Exporter should return metrics in Prometheus exposition format.

Important: If your installation uses a different systemd unit or startup configuration, inspect it using systemctl cat prometheus-node-exporter before changing service arguments.

6. Configure Prometheus to Collect Node Exporter Metrics

Prometheus uses a YAML configuration file to define monitoring targets.

On Ubuntu package installations, the configuration is commonly located at:

/etc/prometheus/prometheus.yml

Back up the configuration:

sudo cp -a /etc/prometheus/prometheus.yml \
/etc/prometheus/prometheus.yml.backup

Edit the file:

sudo nano /etc/prometheus/prometheus.yml

For a basic single-server deployment, configure:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['127.0.0.1:9090']

  - job_name: 'node'
    static_configs:
      - targets: ['127.0.0.1:9100']

This configuration tells Prometheus to collect:

  • Its own operational metrics.
  • Linux system metrics exposed by Node Exporter.

Prometheus will scrape both targets every 15 seconds.

Note: YAML indentation is significant. Use spaces rather than tabs.

7. Validate the Prometheus Configuration

Prometheus includes a configuration validation utility called promtool.

Validate the configuration:

sudo promtool check config /etc/prometheus/prometheus.yml

If validation succeeds, restart Prometheus:

sudo systemctl restart prometheus

Verify the service:

sudo systemctl status prometheus --no-pager

Check the API readiness endpoint:

curl -fsS http://127.0.0.1:9090/-/ready

You can also query the Prometheus API:

curl -fsSG \
--data-urlencode 'query=up' \
http://127.0.0.1:9090/api/v1/query

The up metric indicates whether Prometheus successfully scraped each configured target.

A value of 1 indicates a successful scrape, while 0 indicates a failed scrape.

8. Install Grafana on Ubuntu

Grafana provides an official APT repository for supported Debian-based systems.

Install the required packages:

sudo apt install -y \
apt-transport-https \
software-properties-common \
wget \
gnupg

Create the APT keyring directory:

sudo mkdir -p /etc/apt/keyrings

Download and install the Grafana repository signing key:

wget -q -O - \
https://apt.grafana.com/gpg.key \
| sudo gpg --dearmor -o /etc/apt/keyrings/grafana.gpg

Restrict the keyring permissions:

sudo chmod 644 /etc/apt/keyrings/grafana.gpg

Add the Grafana repository:

echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" \
| sudo tee /etc/apt/sources.list.d/grafana.list

Update the package index:

sudo apt update

Install Grafana:

sudo apt install -y grafana

Security recommendation: Verify repository signing keys and installation instructions against the official Grafana documentation before deploying third-party packages to production servers.

9. Start and Enable Grafana

Enable Grafana at system startup:

sudo systemctl enable --now grafana-server

Verify the service:

sudo systemctl status grafana-server --no-pager

Grafana commonly listens on TCP port 3000.

Check the listening address:

sudo ss -tlnp | grep 3000

Before exposing Grafana publicly, configure its network binding and HTTPS access.

10. Restrict Grafana to Localhost

Grafana's primary configuration file is commonly located at:

/etc/grafana/grafana.ini

Back up the file:

sudo cp -a /etc/grafana/grafana.ini \
/etc/grafana/grafana.ini.backup

Edit the configuration:

sudo nano /etc/grafana/grafana.ini

Under the [server] section, configure:

[server]
http_addr = 127.0.0.1
http_port = 3000
domain = monitor.example.com
root_url = https://monitor.example.com/

If the [server] section already exists, modify its existing directives rather than creating a duplicate section.

Replace monitor.example.com with your monitoring hostname.

Restart Grafana:

sudo systemctl restart grafana-server

Verify that Grafana listens only on localhost:

sudo ss -tlnp | grep 3000

Test its local health endpoint:

curl -fsS http://127.0.0.1:3000/api/health

11. Configure Grafana's Administrator Password

Grafana creates an administrator account during initial installation.

Set a strong administrator password before enabling external access.

On supported Grafana installations, use:

sudo grafana cli admin reset-admin-password

The command requires a new password argument. To avoid placing a password directly in shell history, use the Grafana web interface through a temporary SSH tunnel to complete the initial login and password change.

From your local computer:

ssh -L 3000:127.0.0.1:3000 \
ubuntu@YOUR_SERVER_IP

Open:

http://127.0.0.1:3000

Complete the initial administrator login and change the password immediately.

For production environments, use unique administrator credentials and enable additional authentication controls where supported.

12. Install Nginx as a Reverse Proxy

Nginx can provide HTTPS access to Grafana without exposing its internal port.

Install Nginx:

sudo apt install -y nginx

Enable the service:

sudo systemctl enable --now nginx

Create a DNS record pointing your monitoring hostname to the VPS.

For example:

monitor.example.com

Ensure the hostname resolves correctly before requesting an SSL certificate.

13. Configure the Grafana Nginx Reverse Proxy

Create a dedicated Nginx configuration:

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

Add:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    listen 80;
    server_name monitor.example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;

        proxy_http_version 1.1;

        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;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

Replace the example hostname with your actual domain.

Enable the configuration:

sudo ln -s \
/etc/nginx/sites-available/grafana \
/etc/nginx/sites-enabled/grafana

Validate Nginx:

sudo nginx -t

Reload Nginx:

sudo systemctl reload nginx

Important: The initial HTTP listener is intended for certificate issuance and redirect configuration. Do not enter administrator credentials over unencrypted public HTTP.

Restrict external access until HTTPS is configured and tested.

14. Enable HTTPS with Let's Encrypt

Install Certbot and its Nginx plugin:

sudo apt install -y certbot python3-certbot-nginx

Ensure that ports 80 and 443 are permitted by the appropriate firewall rules and that the monitoring hostname points to your VPS.

Request a certificate:

sudo certbot --nginx \
-d monitor.example.com \
--redirect

Follow the prompts to complete certificate issuance.

After HTTPS is enabled, access:

https://monitor.example.com

Verify automatic renewal:

sudo certbot renew --dry-run

Security recommendation: Consider restricting Grafana access to a VPN or trusted IP addresses, especially when monitoring sensitive production infrastructure.

15. Add Prometheus as a Grafana Data Source

Log in to the Grafana dashboard.

Navigate to:

Connections
  > Data sources
  > Add new data source

Select Prometheus.

Configure the Prometheus server URL:

http://127.0.0.1:9090

Because Grafana and Prometheus run on the same VPS, Grafana can access Prometheus through localhost.

Click Save & test.

If the connection succeeds, Grafana can query the metrics stored in Prometheus.

16. Import a Linux Server Monitoring Dashboard

Grafana supports reusable dashboards for Node Exporter metrics.

Navigate to:

Dashboards
  > New
  > Import

You can import a compatible community dashboard from the Grafana dashboard library.

A commonly used dashboard is:

Node Exporter Full
Dashboard ID: 1860

Select your Prometheus data source during import.

Dashboard availability, compatibility, and required metric names can change over time. Review the dashboard before importing it into production.

Once imported, the dashboard may display:

  • CPU utilization.
  • System load.
  • Memory consumption.
  • Swap activity.
  • Disk capacity.
  • Disk I/O.
  • Network traffic.
  • Filesystem usage.

17. Monitor CPU Usage with PromQL

Prometheus uses a query language called PromQL.

To calculate approximate CPU utilization across all logical CPU cores:

100 * (
  1 - avg by (instance) (
    rate(node_cpu_seconds_total{mode="idle"}[5m])
  )
)

This query calculates the percentage of non-idle CPU time over a five-minute interval.

It can be used in Grafana panels to visualize CPU utilization.

18. Monitor Memory Usage with PromQL

To calculate approximate memory utilization:

100 * (
  1 -
  (
    node_memory_MemAvailable_bytes
    /
    node_memory_MemTotal_bytes
  )
)

This query uses Linux's available memory estimate rather than relying exclusively on the amount of completely free memory.

It provides a useful overview of memory consumption for capacity planning.

19. Monitor Filesystem Usage with PromQL

To calculate filesystem utilization:

100 * (
  1 -
  (
    node_filesystem_avail_bytes{
      fstype!~"tmpfs|overlay|squashfs"
    }
    /
    node_filesystem_size_bytes{
      fstype!~"tmpfs|overlay|squashfs"
    }
  )
)

This query excludes several common temporary and container-related filesystem types.

Depending on your environment, additional filesystem exclusions may be appropriate.

Monitor important mount points individually when possible, particularly the root filesystem and application data volumes.

20. Monitor Network Traffic with PromQL

To calculate incoming network traffic in bytes per second:

rate(node_network_receive_bytes_total{
  device!="lo"
}[5m])

To calculate outgoing network traffic:

rate(node_network_transmit_bytes_total{
  device!="lo"
}[5m])

These queries exclude the loopback interface.

Additional interface filtering may be required for VPS environments with multiple virtual interfaces, bridges, or container networks.

21. Configure Basic Grafana Alerts

Grafana includes an alerting system that can evaluate metric queries and trigger notifications.

Navigate to the Grafana alerting section:

Alerting
  > Alert rules
  > New alert rule

For example, create an alert when CPU utilization remains above 90% for five minutes.

Use the CPU utilization PromQL query from this guide.

Configure an appropriate threshold and evaluation period.

Next, configure a notification contact point, such as email or another supported notification integration.

Important: Creating an alert rule does not guarantee that notifications will be delivered. Configure contact points, notification policies, and test alert delivery.

For production systems, consider alerts for:

  • High CPU utilization.
  • Low available memory.
  • Filesystem usage above defined thresholds.
  • Unavailable monitoring targets.
  • Unexpected service interruptions.

22. Monitor Multiple Linux VPS Servers

Prometheus can collect metrics from multiple Linux servers.

Install Node Exporter on each monitored VPS.

For remote servers, configure Node Exporter to listen on a private network interface rather than a public interface.

For example:

--web.listen-address=10.0.0.20:9100

Restrict access to the monitoring server's private IP using firewall rules.

Then add the remote server to the Prometheus configuration:

- job_name: 'remote-linux'
  static_configs:
    - targets:
        - '10.0.0.20:9100'
        - '10.0.0.21:9100'

Replace the example addresses with your actual private IP addresses.

Validate the configuration:

sudo promtool check config /etc/prometheus/prometheus.yml

Restart Prometheus:

sudo systemctl restart prometheus

Security recommendation: Use private networking, VPN connectivity, or authenticated and encrypted exporter endpoints when collecting metrics from remote servers.

Do not expose Node Exporter port 9100 directly to the public internet.

23. Configure Prometheus Data Retention

Prometheus stores historical metrics locally.

Without appropriate retention settings, monitoring data can consume significant disk space.

Prometheus supports retention options such as:

--storage.tsdb.retention.time=15d

This example retains time-series data for approximately 15 days.

For Ubuntu package installations, review the existing startup arguments in:

/etc/default/prometheus

Add the retention setting while preserving other required arguments.

Restart Prometheus after changing startup options:

sudo systemctl restart prometheus

Monitor disk consumption:

df -h
sudo du -sh /var/lib/prometheus

Actual storage requirements depend on the number of monitored targets, collected metrics, scrape frequency, and retention period.

24. Troubleshooting Common Problems

Prometheus is not running:

sudo systemctl status prometheus --no-pager
sudo journalctl -u prometheus -n 100 --no-pager

Node Exporter metrics are unavailable:

sudo systemctl status prometheus-node-exporter --no-pager
curl -fsS http://127.0.0.1:9100/metrics | head

Prometheus configuration error:

sudo promtool check config /etc/prometheus/prometheus.yml

Grafana is inaccessible:

sudo systemctl status grafana-server --no-pager
sudo journalctl -u grafana-server -n 100 --no-pager

Grafana cannot connect to Prometheus: Verify that Prometheus is running and listening on the configured address.

curl -fsS http://127.0.0.1:9090/-/ready

Nginx returns 502 Bad Gateway: Verify that Grafana is listening on localhost and that the reverse proxy points to the correct port.

sudo nginx -t
curl -fsS http://127.0.0.1:3000/api/health

Dashboard displays no data: Check the Prometheus data source, monitoring targets, dashboard time range, and metric availability.

25. Prometheus and Grafana Security Best Practices

  • Keep Prometheus, Node Exporter, Grafana, and Ubuntu updated.
  • Restrict Prometheus and Node Exporter to localhost or trusted private networks.
  • Protect Grafana with HTTPS and strong authentication.
  • Disable anonymous access unless explicitly required.
  • Use least-privilege Grafana accounts.
  • Restrict monitoring access through firewall rules or VPN connectivity.
  • Configure appropriate metrics retention.
  • Monitor the disk usage of the Prometheus database.
  • Back up Grafana configuration and dashboards.
  • Configure and test alert notifications.
  • Review monitoring targets regularly.
  • Protect credentials and configuration files.

For critical production infrastructure, consider monitoring the monitoring platform itself and maintaining independent availability checks.

Related Linux VPS Tutorials

Monitor Your Infrastructure with Owned Networks

Deploy monitoring platforms, websites, databases, and business applications on an Owned Networks KVM VPS with full root access and flexible server resources.

Prometheus and Grafana provide the visibility needed to understand infrastructure performance, identify resource bottlenecks, and make informed decisions about server capacity and application optimization.

Explore Owned Networks VPS Hosting and deploy your next Linux server today.


Was this answer helpful?

KVM VPS & Dedicated Servers

Deploy a Linux VPS in under 2 minutes — AlmaLinux, Rocky Linux, Ubuntu, Debian. Full root access, KVM virtualization, US and EU locations.

« Back