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.
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
/metricsendpoint 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 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.
- 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.
- Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
- Find Prometheus in the app catalog and click Install app.
- 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.
- No other information is required. Under Automatically generated values, you'll see
SERVICE_USER_PROMETHEUSandSERVICE_PASSWORD_PROMETHEUS: the username and password for logging in are generated during installation. - Click Queue installation. Prometheus will appear online on the app card after one or two minutes.
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.
- Open the app's Access link. Your browser will ask for a username and password.
- Enter the two values from the App environment.
- Prometheus opens the Query page. Enter
upto test it and click Execute. Prometheus shows1(reachable) or0(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.
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.
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.
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:
/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:
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.
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.
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.
- 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.
| Minimum | Recommended | |
|---|---|---|
| CPU | 1 core | 2 cores |
| RAM | 512 MB | 2 GB |
| Storage | 1 GB | 20 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.
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:
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
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.
Create a directory:
mkdir -p /opt/prometheus
cd /opt/prometheus
Create a prometheus.yml file in it using nano prometheus.yml:
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:
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: hostruns 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 at127.0.0.1:9100.--web.listen-address=127.0.0.1:…makes both services listen locally only.--storage.tsdb.retention.time=30dsets how long metrics are kept. Without this line, they're kept for 15 days.pid: hostand 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:
docker compose up -d
Since Prometheus listens locally only, use an SSH tunnel to open the interface for your first test. On your own computer, run:
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.
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:
apt install apache2-utils
htpasswd -nbBC 10 "" 'YOUR_PASSWORD' | tr -d ':\n'
Create web.yml in the /opt/prometheus directory and enter the hash:
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:
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.
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.
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:
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.
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.
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:
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.
Before updating, read the release notes for the new version. Then change the version number in docker-compose.yml and restart:
cd /opt/prometheus
docker compose pull
docker compose up -d
Remove old images with docker image prune.
Prometheus only queries targets listed under scrape_configs in prometheus.yml. Each block has a job_name and a list of addresses.
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:
ufw allow from PROMETHEUS_IP to any port 9100 proto tcp
Then add the server to prometheus.yml:
- 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.
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:
- job_name: "my-app"
metrics_path: /metrics
scheme: https
static_configs:
- targets: ["app.example.com"]
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.
- 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.
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! 🙂
