Prometheus is great. But it uses a lot of RAM. And long-term storage? That's a headache involving Thanos or Cortex.
VictoriaMetrics solves this. It's a drop-in replacement for Prometheus that:
- Uses 10x less RAM.
- Compresses data 7x better.
- Supports the Prometheus API (so Grafana works out of the box).
The Setup
We will run VictoriaMetrics (storage) and vmagent (scraper).
version: '3.5'
services:
vmagent:
container_name: vmagent
image: victoriametrics/vmagent:latest
depends_on:
- "victoriametrics"
ports:
- 8429:8429
volumes:
- vmagentdata:/vmagentdata
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- "-promscrape.config=/etc/prometheus/prometheus.yml"
- "-remoteWrite.url=http://victoriametrics:8428/api/v1/write"
victoriametrics:
container_name: victoriametrics
image: victoriametrics/victoria-metrics:latest
ports:
- 8428:8428
volumes:
- vmdata:/storage
command:
- "-storageDataPath=/storage"
- "-retentionPeriod=12" # 12 months retention
grafana:
container_name: grafana
image: grafana/grafana:latest
depends_on:
- "victoriametrics"
ports:
- 3000:3000
volumes:
vmagentdata: {}
vmdata: {}
The Config (prometheus.yml)
This is standard Prometheus config. vmagent reads it and scrapes targets.
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'vmagent'
static_configs:
- targets: ['localhost:8429']
- job_name: 'victoriametrics'
static_configs:
- targets: ['victoriametrics:8428']
Why Switch?
Because efficiency matters. If you can store a year of metrics on a $5 VPS instead of a $50 dedicated server, why wouldn't you?
Switch your Grafana Data Source URL to http://victoriametrics:8428. That's it. You're done.