Why self-host Prometheus and Grafana on a VPS
Unlike an all-in-one tool, the Prometheus + Grafana stack clearly separates collection (Prometheus scrapes the metrics exposed by exporters), storage (time series database) and visualization (Grafana). This modularity is precisely what makes it a standard: you monitor the VPS itself with Node Exporter, your containers with cAdvisor, your PostgreSQL or MySQL database with the dedicated exporter, and you instrument your own applications in the Prometheus format. All of this on a VPS you control, which spares you from sending sensitive infrastructure metrics to a SaaS billed by ingestion. You keep the history for as long as your disk allows, you build dashboards specific to your stack, and you define your own alerting rules via Alertmanager. This is the approach to favor when you go beyond simply 'is the site responding?' to move into fine-grained analysis of load trends.
What this stack brings to your VPS
- Detailed system metrics (CPU, RAM, disk I/O, network) via Node Exporter, kept as history over the long term.
- Monitoring of Docker containers with cAdvisor: per-container consumption in real time.
- Custom Grafana dashboards, importable from a community library of thousands of templates.
- Powerful alerting via Alertmanager: thresholds, grouping, silences and multi-channel routing.
- PromQL query language to create derived indicators and rates of change.
- Instrumentation of your own applications in the Prometheus format, with no external ingestion cost.
Requirements to host it
This stack is more demanding than a simple monitor because Prometheus keeps the time series in memory before writing them to disk. Count on a 2 vCPU VPS with 2 to 4 GB of RAM to monitor one to several servers, and more if you multiply the exporters and the scrape frequency. Storage is the key point: plan for 20 to 40 GB of disk depending on the retention period (--storage.tsdb.retention.time). You need Docker and Docker Compose, a domain name to expose Grafana over HTTPS, and a reverse proxy. Keep Prometheus not publicly exposed: only Grafana should be accessible from the outside.
Deploy the Prometheus + Grafana stack with Docker Compose
Write the docker-compose.yml file
Define three services: prometheus, grafana and node-exporter. Mount a prometheus.yml configuration file and named volumes to persist the data (prometheus_data, grafana_data). Then run docker compose up -d.
Configure the targets in prometheus.yml
In the scrape_configs section, add a node job pointing to node-exporter:9100 for system metrics, and a cadvisor job if you monitor Docker. Reload with docker compose restart prometheus.
Connect Grafana to Prometheus
Open Grafana, add a Prometheus-type data source with the URL http://prometheus:9090 (the Docker service name). Test the connection: it should return 'Data source is working'.
Import ready-to-use dashboards
Import the Node Exporter Full dashboard (ID 1860) and a cAdvisor dashboard via their identifier. You instantly get CPU, memory, disk and network graphs without building anything by hand.
Secure Grafana behind an SSL reverse proxy
Expose only Grafana via Nginx or Caddy on grafana.mydomain.com with a Let's Encrypt certificate. Block external access to Prometheus (port 9090) at the firewall level: it should only be reachable by Grafana.
Set up alerting
Add Alertmanager to the Compose file, define rules in Prometheus (for example CPU > 90% for 5 minutes) and route the alerts to email, Slack or Telegram. Verify the triggering with a test rule.
Monitor the disk space consumed by Prometheus's time series database, which grows with the number of metrics and the scrape frequency. Adjust --storage.tsdb.retention.time (for example 30 days) and, if you need a long history without saturating the VPS, connect remote storage such as Thanos or VictoriaMetrics. On a VPS, reducing the scrape interval from 15s to 30s for non-critical metrics also halves the volume written to disk.
The official documentation
For advanced configuration and options specific to the tool, refer to the official Grafana documentation. This guide covers deployment on a VPS; the vendor's documentation remains the reference for fine-tuning, major updates and specific use cases.