If you run a VPS without monitoring, you’re flying blind. Resource leaks, traffic spikes, and cron jobs gone wrong can silently degrade performance until your site goes down. Prometheus and Grafana together provide battle-tested, open-source monitoring that gives you real-time visibility into CPU, RAM, disk, network, and application metrics. Here’s how to set them up on a Ubuntu 22.04/24.04 VPS in under 30 minutes.
Prerequisites
- A Ubuntu 22.04 or 24.04 VPS with at least 1 GB RAM (2 GB recommended if your app also runs on the same server)
- Root or sudo access
- Port 9090 (Prometheus) and 3000 (Grafana) open in your firewall — but restrict to your IP or use a reverse proxy with auth
If you don’t have a VPS yet, check affordable VPS hosting options that provide the resources you need for both your application and monitoring stack.
Step 1: Install Prometheus
Prometheus is a time-series database that scrapes and stores metrics from configured targets. Install from the official release (not apt — the repo version is often outdated):
# Create prometheus user
sudo useradd --no-create-home --shell /bin/false prometheus
# Download latest Prometheus (check https://prometheus.io/download/ for latest)
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.53.1/prometheus-2.53.1.linux-amd64.tar.gz
tar xvf prometheus-2.53.1.linux-amd64.tar.gz
cd prometheus-2.53.1.linux-amd64
# Copy binaries
sudo cp prometheus promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
# Create directories
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo cp consoles/ console_libraries/ /etc/prometheus/ -r
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
Step 2: Configure Prometheus
Create /etc/prometheus/prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
Create a systemd service at /etc/systemd/system/prometheus.service and start it.
sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl start prometheus
sudo systemctl status prometheus
Step 3: Install Node Exporter
Node Exporter exposes OS-level metrics (CPU, memory, disk, network). Download from the official releases, copy to /usr/local/bin, and run as a systemd service listening on port 9100.
# Download and install
cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
tar xvf node_exporter-1.8.2.linux-amd64.tar.gz
sudo cp node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin/
sudo useradd --no-create-home --shell /bin/false node_exporter
# Start
sudo systemctl daemon-reload
sudo systemctl enable node_exporter
sudo systemctl start node_exporter
Verify: curl http://localhost:9100/metrics | head -20
Step 4: Install Grafana
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
Access Grafana at http://your-vps-ip:3000. Default login: admin / admin (change immediately).
Step 5: Connect Grafana to Prometheus
- Go to Connections > Add new connection in Grafana
- Search for “Prometheus” and click it
- Click “Create a Prometheus data source”
- Set URL to
http://localhost:9090 - Click “Save & Test”
Step 6: Import a Dashboard
- Go to Dashboards > Import
- Enter dashboard ID 1860 (Node Exporter Full) and click “Load”
- Select your Prometheus data source and click “Import”
You’ll immediately see CPU utilization per core, memory breakdown, disk I/O, network traffic, system load, and uptime — all populated from your Node Exporter metrics.
Step 7: Set Up Alerts
In Grafana, go to Alerting > Contact points and add email, Slack, or Telegram. Create alert rules for common failure conditions:
- High CPU: Alert when CPU usage exceeds 90% for 5 minutes
- Low disk: Alert when disk usage drops below 10% free
- High memory: Alert when memory usage exceeds 90% for 5 minutes
- Instance down: Alert when a target is unreachable (up == 0)
Resource Usage of the Monitoring Stack
| Component | RAM | CPU | Disk (30d retention) |
|---|---|---|---|
| Prometheus | 100-200 MB | 1-5% of 1 core | ~5-15 GB |
| Node Exporter | 15-25 MB | <1% of 1 core | 0 GB |
| Grafana | 80-150 MB | 1-3% of 1 core | ~1 GB |
| Total | ~200-375 MB | ~2-9% | ~6-16 GB |
This stack fits comfortably alongside your application on a 2 GB VPS. On a 1 GB VPS, reduce Prometheus retention to 7-14 days.
Next Steps: Advanced Monitoring
- Add cAdvisor to monitor Docker containers
- Add MySQL Exporter for database query performance
- Add Blackbox Exporter for external endpoint uptime checks
- Set up Grafana Loki for centralized log aggregation
With Prometheus and Grafana in place, you’ll catch resource exhaustion before downtime occurs, identify regressions instantly, and make data-driven upgrade decisions. For VPS plans with sufficient resources for both your application and a full observability stack, check recommended VPS configurations.




Leave a Reply
You must be logged in to post a comment.