Skip to content
🧮 Is Lifetime with ZapX Pass worth it? Work it out for your own servers in 30 seconds. Open the Lifetime calculator →

Set Up Prometheus on a Linux Server – Monitor Servers and Applications with Metrics

Set up Prometheus on your Linux server: use the One-Click App with HTTPS and login, or install it manually with Docker Compose and Node Exporter. Add your own targets, run PromQL queries, and connect Grafana.

2 December 202610 min read3 Views0 helpful

Introduction

Prometheus is an open-source monitoring system. At regular intervals, it collects metrics from so-called targets, such as a server's CPU, RAM, and storage usage or a service's response times, and stores them as time series. Use the PromQL query language to analyze the data, and set up alert rules to get notified about problems. For attractive dashboards, Prometheus is usually paired with Grafana.

This guide covers two ways to get started: the simple One-Click App option, which makes Prometheus available with HTTPS and login in just a few clicks, and a manual installation with Docker Compose and Node Exporter. Afterward, you'll add your first custom targets.

When it makes sense to run Prometheus on a VPS

Running your own Prometheus server is especially useful if you want to:

  • Monitor multiple servers or services, such as their resource usage, available storage, or whether a service is responding.
  • Compare metrics over several weeks, for example, to see whether your server needs more RAM.
  • Monitor applications that already expose metrics. Many programs, such as Traefik, Caddy, Grafana, and database exporters, provide a /metrics endpoint that Prometheus can query directly.
  • Define your own alerts instead of relying on a third-party service.

Prometheus is less suitable if you only want to know whether a website is reachable. A simple uptime monitor is enough for that. Prometheus also doesn't store log files; it only processes numerical data.

The easy way: Prometheus as a One-Click App

The quickest way to get Prometheus running is through the One-Click Apps on your VPS. The app installs Prometheus with a domain and HTTPS and protects the interface and API with a login. You don't need a reverse proxy or certificate.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set up One-Click Apps for instructions.
  • At least 1 CPU core, 512 MB of free RAM, and 1 GB of storage. For a few thousand time series over 15 days, we recommend 2 cores, 2 GB of RAM, and 20 GB of storage.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Find Prometheus in the app catalog and click Install app.
  3. Use a custom subdomain or zap.cloud is already selected. Leave this option enabled and enter a custom name if needed. You'll use the domain to access Prometheus over HTTPS.
  4. No other information is required. Under Automatically generated values, you'll see SERVICE_USER_PROMETHEUS and SERVICE_PASSWORD_PROMETHEUS: the username and password for logging in are generated during installation.
  5. Click Queue installation. Prometheus will appear online on the app card after one or two minutes.

First access and login

You can find the login details in the app settings (gear icon), under App environment > Automatically generated values. The username is listed under SERVICE_USER_PROMETHEUS and is zapx for a new installation. The password is listed under SERVICE_PASSWORD_PROMETHEUS. Click the eye icon to show a value, or the icon next to it to copy it. You can't change these values in the panel.

  1. Open the app's Access link. Your browser will ask for a username and password.
  2. Enter the two values from the App environment.
  3. Prometheus opens the Query page. Enter up to test it and click Execute. Prometheus shows 1 (reachable) or 0 (unreachable) for each target.

Under Status > Target health, you can see all targets, their status, and the time of their last query. Immediately after installation, Prometheus itself is the only target.

Warning: The login details also apply to the API

Login protects the interface, the API, and the /metrics endpoint. Without valid credentials, Prometheus responds with 401 Unauthorized. Any program that reads data from Prometheus needs the same credentials, such as Grafana with Basic auth enabled or curl with -u zapx:PASSWORD. Don't share your credentials, and store them in your password manager.

Info: Installations from before December 1, 2026

Older One-Click App installations were accessible without login. After an App update, Prometheus requires a username and password for those installations too. For these installations, the username is randomly generated. Always use the values listed in the App environment. Then enter the login details in Grafana and any other programs that query Prometheus.

Add your own targets

The prometheus.yml file lists the targets that Prometheus queries. The One-Click App creates this file in the prometheus-config volume the first time it starts. On your VPS, you'll find it at:

Code
/var/lib/docker/volumes/<APP-ID>_prometheus-config/_data/prometheus.yml

<APP-ID> is the app's identifier. To find the exact path, run ls /var/lib/docker/volumes | grep prometheus-config in the console. Edit the file using SFTP or nano, and add a new block under scrape_configs, as described in the “Connect targets” section below. Keep the existing prometheus block; it contains the login details for self-monitoring.

Then validate the file and restart Prometheus:

Code
docker exec <CONTAINER> promtool check config /config/prometheus.yml
docker restart <CONTAINER>

You can find the container name (prometheus-<APP-ID>) by running docker ps. If promtool reports an error, fix the file before restarting. Otherwise, Prometheus won't start.

Updates and backups

To update Prometheus, go to the app settings (gear icon) and select App update. Click Check for updates, then install a new version with Apply update. If it says the app is up to date, there isn't a newer version in the app catalog yet.

Your metrics are stored in the prometheus-data volume, and your configuration is stored in the prometheus-config volume. Both are retained during updates and when you Reinstall app, as long as you don't delete the data volumes. The app won't overwrite an existing prometheus.yml containing your targets; it only creates the file if it doesn't exist. By default, Prometheus keeps metrics for 15 days and automatically deletes older data. Before making major changes, back up at least the prometheus.yml file, for example, by copying it to your computer using SFTP.

Manual installation

The rest of this guide covers manual installation of Prometheus with Docker Compose. This option is useful if you don't use One-Click Apps on your server or want to monitor the server itself with Node Exporter.

Requirements

  • A Linux server running Debian or Ubuntu that you can access over SSH.
  • Docker with the Compose plugin. See Set up Docker for installation instructions.
MinimumRecommended
CPU1 core2 cores
RAM512 MB2 GB
Storage1 GB20 GB

According to the official documentation, Prometheus needs about 1 to 2 bytes per metric. Storage requirements therefore grow with the number of targets, the scrape interval, and the retention period.

Prepare the firewall

In this guide, Prometheus and Node Exporter listen only on 127.0.0.1, so they can't be reached from outside the server. You only need to open SSH and the ports used by the reverse proxy:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Warning: Prometheus doesn't have built-in login

Without additional configuration, anyone who can reach Prometheus can access all metrics and the configuration. Never expose port 9090 directly. See below for how to set up login. For more information about the firewall, see Manage the firewall on Linux.

Install with Docker Compose

Create a directory:

Code
mkdir -p /opt/prometheus
cd /opt/prometheus

Create a prometheus.yml file in it using nano prometheus.yml:

Code
global:
  scrape_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"]

Then create the docker-compose.yml file:

Code
services:
  prometheus:
    image: prom/prometheus:v3.16.0
    restart: unless-stopped
    network_mode: host
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --storage.tsdb.retention.time=30d
      - --web.listen-address=127.0.0.1:9090
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus

  node-exporter:
    image: prom/node-exporter:v1.13.1
    restart: unless-stopped
    network_mode: host
    pid: host
    command:
      - --path.rootfs=/host
      - --web.listen-address=127.0.0.1:9100
    volumes:
      - /:/host:ro,rslave

volumes:
  prometheus-data:

Key lines:

  • network_mode: host runs both containers directly on the server's network. This lets Node Exporter collect the server's actual network metrics and allows Prometheus to reach it at 127.0.0.1:9100.
  • --web.listen-address=127.0.0.1:… makes both services listen locally only.
  • --storage.tsdb.retention.time=30d sets how long metrics are kept. Without this line, they're kept for 15 days.
  • pid: host and mounting / as read-only let Node Exporter read the server's metrics instead of the container's, as described in the Node Exporter guide.

Start both containers:

Code
docker compose up -d

First access

Since Prometheus listens locally only, use an SSH tunnel to open the interface for your first test. On your own computer, run:

Code
ssh -L 9090:127.0.0.1:9090 root@SERVER_IP

Then open http://localhost:9090 in your browser. Under Status > Target health, the prometheus and node jobs should appear as UP. The node_memory_MemAvailable_bytes query shows the server's available RAM.

Set up login

Prometheus can verify login credentials using Basic Auth. To do this, create a web.yml file containing a bcrypt password hash. Generate the hash with htpasswd from the apache2-utils package:

Code
apt install apache2-utils
htpasswd -nbBC 10 "" 'YOUR_PASSWORD' | tr -d ':\n'

Create web.yml in the /opt/prometheus directory and enter the hash:

Code
basic_auth_users:
  admin: HASH

In docker-compose.yml, add the line - --web.config.file=/etc/prometheus/web.yml under command for the prometheus service, and add - ./web.yml:/etc/prometheus/web.yml:ro under volumes. From now on, Prometheus will require login for all pages, including its own query. So add the following to the prometheus job in prometheus.yml:

Code
    basic_auth:
      username: admin
      password_file: /etc/prometheus/scrape-password

The scrape-password file should contain only the password in plain text. Mount it as read-only, just like web.yml, and secure it on the server with chmod 600. Apply the changes with docker compose up -d.

Info: You can skip self-monitoring

If you don't need Prometheus's own metrics, you can delete the prometheus job. If you leave it in place without basic_auth, Target health will show it as DOWN with the 401 Unauthorized error.

Access over HTTPS through a reverse proxy

To access Prometheus without a tunnel, put a reverse proxy with a valid certificate in front of it. For the basics, see Set up a reverse proxy with nginx and Create an SSL certificate (Let's Encrypt). Here's the nginx server block:

Code
server {
    listen 80;
    server_name prometheus.example.com;

    location / {
        proxy_pass http://127.0.0.1:9090;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then obtain the certificate with certbot --nginx -d prometheus.example.com. Make sure you set up login first; otherwise, Prometheus will be accessible to everyone.

Tip: Shorter with Caddy

If you use Caddy instead of nginx, the proxy obtains the certificate automatically. In the Caddyfile, all you need is prometheus.example.com { reverse_proxy 127.0.0.1:9090 }. For details, see Set up Caddy.

Back up your data

The configuration is stored in /opt/prometheus, and metrics are stored in the prometheus-data volume. To create a complete backup, briefly stop Prometheus and archive the volume:

Code
cd /opt/prometheus
docker compose stop prometheus
docker run --rm -v prometheus_prometheus-data:/data -v "$(pwd)":/backup alpine tar -czf /backup/prometheus-backup-$(date +%F).tar.gz -C /data .
docker compose start prometheus

Docker Compose prefixes the volume with the project name, which is prometheus_ here. Run docker volume ls to find the exact name. If you only need the configuration and alert rules, backing up the /opt/prometheus directory is enough.

Update Prometheus

Before updating, read the release notes for the new version. Then change the version number in docker-compose.yml and restart:

Code
cd /opt/prometheus
docker compose pull
docker compose up -d

Remove old images with docker image prune.

Connect targets

Prometheus only queries targets listed under scrape_configs in prometheus.yml. Each block has a job_name and a list of addresses.

Monitor another server

Install Node Exporter on the second server, for example, using the node-exporter service from the Compose file above, but with --web.listen-address=:9100. In that server's firewall, allow port 9100 only from your Prometheus server's IP address:

Code
ufw allow from PROMETHEUS_IP to any port 9100 proto tcp

Then add the server to prometheus.yml:

Code
  - job_name: "server-2"
    static_configs:
      - targets: ["SERVER_2_IP:9100"]

Validate the file with promtool check config and restart Prometheus. The new target will appear under Status > Target health within 15 seconds.

Applications with their own metrics endpoint

Many programs already expose their metrics in Prometheus format, usually at /metrics. If the endpoint is protected or uses a different path, add metrics_path, scheme, and, if needed, basic_auth to the job:

Code
  - job_name: "my-app"
    metrics_path: /metrics
    scheme: https
    static_configs:
      - targets: ["app.example.com"]

Use Prometheus in Grafana

Connect Prometheus to Grafana to create dashboards. For instructions and a ready-made dashboard for Node Exporter, see the data source section in Set up Grafana on a Linux server. If you're using the Prometheus One-Click App, enter the app's Access link (https://…) as the data source URL, enable Basic auth, and enter the username and password from the App environment. The data source connection test will fail without login details because Prometheus responds with 401 Unauthorized.

Limitations

  • Prometheus only stores numerical data: Use other tools for logs and text.
  • No notifications without Alertmanager: Prometheus evaluates alert rules itself. To send emails or chat messages, you also need Alertmanager.
  • Long retention requires storage: If you plan to keep metrics for many months, estimate the storage requirements in advance or reduce the number of targets.

Conclusion

With Prometheus, you collect metrics from your servers and applications in one place, analyze them with PromQL, and add your own targets in prometheus.yml. To go with it, the guide Set Up Grafana on a Linux Server shows you how to display your metrics in clear dashboards.

If you have any other questions or need help, our support team is available every day! 🙂

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the quickest option: Prometheus is available over HTTPS after one or two minutes, protected with generated login details, and can be updated through the ZapX dashboard. Manual installation with Docker Compose is a good choice if you want to monitor the server itself with Node Exporter, change the retention period, or integrate Prometheus into an existing Docker environment.
Go to the app settings (gear icon) and select App environment > Automatically generated values. The username is listed under SERVICE_USER_PROMETHEUS (zapx for new installations), and the password is listed under SERVICE_PASSWORD_PROMETHEUS. You'll also need these details for Grafana or any other program that reads data from Prometheus.
Under Status > Target health, you'll see the error next to the target. Common causes include a port blocked by the target's firewall, an incorrect address, or an endpoint that requires login (401 Unauthorized). Check the address with curl from the Prometheus server, and add basic_auth to the job if the endpoint is protected.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.