Skip to content

How to Set Up Prometheus + Grafana

Key idea:

Prometheus (metrics storage) + Grafana (visualization) — the open-source standard for monitoring. Deploy in 15 min via Docker Compose. Prometheus scrapes /metrics endpoints of your apps + Node exporter (system metrics). Grafana connects to Prometheus as a data source, shows dashboards. No lock-in: all open-source, self-hosted.

Below: step-by-step, working examples, common pitfalls, FAQ.

Step-by-Step Setup

  1. Create docker-compose.yml with prometheus + grafana services
  2. Write prometheus.yml with scrape_configs → your targets
  3. Add Node exporter on every server for system metrics
  4. Expose Prometheus :9090, Grafana :3000 (behind reverse proxy with auth in prod)
  5. docker compose up -d
  6. In Grafana admin/admin → add Prometheus (http://prometheus:9090) as data source
  7. Import a ready dashboard: Grafana Dashboards → Node Exporter Full (ID 1860)
  8. For uptime monitoring from outside — Enterno Monitor complements

Working Examples

ScenarioConfig
docker-compose.ymlservices: prometheus: image: prom/prometheus ports: ["9090:9090"] volumes: [./prometheus.yml:/etc/prometheus/prometheus.yml] grafana: image: grafana/grafana ports: ["3000:3000"] environment: - GF_SECURITY_ADMIN_PASSWORD=change_me
prometheus.ymlscrape_configs: - job_name: 'node' static_configs: - targets: ['host.docker.internal:9100'] - job_name: 'app' metrics_path: '/metrics' static_configs: - targets: ['app:8080']
Node exporterdocker run -d --name node-exporter \ --net="host" --pid="host" \ -v /:/host:ro \ prom/node-exporter --path.rootfs=/host
PromQL query (CPU idle)rate(node_cpu_seconds_total{mode="idle"}[5m])
Alert rulegroups: - name: example rules: - alert: HighCPU expr: rate(node_cpu_seconds_total{mode!="idle"}[5m]) > 0.9 for: 5m

Common Pitfalls

  • Grafana :3000 exposed without auth → full dashboard public
  • Prometheus without retention config keeps all metrics forever → disk fills
  • Scrape interval 5 s × 100 targets = heavy load. Default 15-30 s
  • High-cardinality labels (user_id) → memory explosion in Prometheus
  • Docker bridge networking: "localhost" targets don't resolve → use service names

Learn more

Frequently Asked Questions

Prometheus or InfluxDB?

Prometheus — pull model, simple setup, TSDB. InfluxDB — push model, SQL-like queries, better long-term. Prometheus wins in Kubernetes/microservices.

Retention — how long?

Default 15 days. Long-term — remote storage (Thanos, Cortex, Grafana Mimir) or Prometheus federation.

Where to configure alerts?

Alertmanager (separate service). Routes alerts to email, Slack, PagerDuty, Telegram.

vs Datadog/New Relic?

Prometheus+Grafana — self-hosted, free. Datadog — SaaS, $15+/host/mo, better UX. Pick by budget vs control.