Servers rarely fail out of nowhere. Disks fill up day by day, memory usage creeps up after every release, and the CPU hits its ceiling only in the evening peak. Monitoring lets you see those trends before someone complains that the site is slow. Prometheus and Grafana solve this with free, open-source tools. Below is a minimal setup on an ordinary VPS.
What Prometheus collects and how
Prometheus is a time-series database and metrics collector. At a fixed interval, for example every 15 seconds, it calls the HTTP endpoints of the services it watches and reads their metrics. This is the pull model: the server does not push anything, Prometheus fetches it. Each metric has a name, labels and values over time.
Small programs that expose metrics are called exporters. The most common is node_exporter, which publishes Linux CPU, memory, disk, network and load figures on port 9100.
Where Grafana fits
Prometheus has its own web UI, but it is mostly meant for testing queries. Grafana is the visualisation layer: it connects to Prometheus as a data source and turns metrics into dashboards. It stores no metrics itself and queries Prometheus whenever a panel loads.
Example: an online shop in Tashkent
Imagine a Tashkent home-appliance store running misol.uz on a single VPS. Every weekend sale the site slows down, yet when the developer logs in everything looks fine because the load has already dropped. With Prometheus and Grafana in place, the graph showed memory almost exhausted around 20:00 on Saturdays, with the system falling back to swap. The team could now decide between adding RAM and tuning the cache.
Installing Prometheus and node_exporter on Ubuntu
Both packages are available in the Ubuntu and Debian repositories. systemd starts them automatically.
sudo apt update
sudo apt install -y prometheus prometheus-node-exporter
systemctl status prometheus prometheus-node-exporter
The main configuration lives in /etc/prometheus/prometheus.yml. The minimal version below scrapes Prometheus itself and the local node_exporter, and loads alert rules from a separate directory.
global:
scrape_interval: 15s
rule_files:
- /etc/prometheus/rules/*.yml
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: node
static_configs:
- targets: ['localhost:9100']
Check it with promtool check config /etc/prometheus/prometheus.yml before running sudo systemctl restart prometheus.
Installing Grafana and adding the data source
Grafana is installed from its official APT repository. It listens on port 3000 and asks you to change the admin password on first login.
sudo apt install -y apt-transport-https wget gnupg
sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo systemctl enable --now grafana-server
Under "Connections" add a Prometheus data source pointing to http://localhost:9090. Import a community node_exporter dashboard by its ID, then trim it to the five or six panels you actually read.
First PromQL queries
PromQL is the Prometheus query language behind every Grafana panel. Three numbers are enough to start: CPU usage, available memory and free disk space. rate() computes the per-second change of a counter over the [5m] window.
# CPU usage, percent
100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100
# Available memory, percent
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100
# Free space on the root filesystem, percent
node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"} * 100
Alerting before the disk fills up
A graph only helps when someone looks at it, so the critical cases need alert rules. The rule below fires when less than 10 percent of the root filesystem is free for 10 minutes. Save it as /etc/prometheus/rules/server.yml and restart Prometheus.
groups:
- name: server
rules:
- alert: DiskAlmostFull
expr: node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"} * 100 < 10
for: 10m
labels:
severity: warning
annotations:
summary: "Less than 10% disk space left"
Prometheus only evaluates rules; Alertmanager delivers notifications to Telegram, email and other channels. For small projects Grafana's built-in alerting is a simpler alternative.
Keep monitoring ports private
Ports 9090 and 9100 have no authentication, so leaving them open exposes details about your server to anyone. Keep them local and reach Grafana only from your own IP or through an HTTPS reverse proxy with a strong password. Replace 203.0.113.10 with your fixed office IP.
sudo ufw allow OpenSSH
sudo ufw allow from 203.0.113.10 to any port 3000 proto tcp
sudo ufw deny 9090/tcp
sudo ufw deny 9100/tcp
sudo ufw enable
Shared hosting or VPS
Prometheus and Grafana are long-running services that need root access and their own ports, so they belong on a VPS. On shared hosting the provider monitors the server and you see disk and resource usage in ISPmanager. When your project needs its own monitoring, you can order a VPS in the sayt.uz cabinet and apply the steps above there.