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.

Check your site →

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

TL;DR

To set up Prometheus and Grafana in 2026, install Prometheus using the official binaries or Docker, configure a YAML file for your data sources, and start the service. Then, install Grafana, connect it to your Prometheus instance, and create dashboards to visualize your metrics. This setup provides robust monitoring for your web infrastructure.

Step-by-Step Setup of Prometheus

Setting up Prometheus involves several critical steps to ensure effective monitoring of your systems. Below is a detailed guide on how to install and configure Prometheus in a typical environment.

1. Install Prometheus

Prometheus can be installed using pre-compiled binaries or Docker. Below is the method using binaries:

  1. Download Prometheus: Go to the official Prometheus download page and choose the appropriate version for your operating system. For example, for Linux:
wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gz
  1. Extract the files:
tar xvf prometheus-2.42.0.linux-amd64.tar.gz
  1. Navigate to the directory:
cd prometheus-2.42.0.linux-amd64
  1. Run Prometheus: You need to configure the prometheus.yml file before you start the service. The default configuration file can be found in the extracted folder.
./prometheus --config.file=prometheus.yml

2. Configure Prometheus

Open the prometheus.yml file in a text editor and add your targets under the scrape_configs section. Here’s an example configuration:

global:
  scrape_interval: 15s  # By default, scrape targets every 15 seconds.

scrape_configs:
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']

This configuration tells Prometheus to scrape metrics from a Node Exporter running on the same machine.

3. Verify Prometheus Installation

To verify that Prometheus is running correctly, open your web browser and navigate to http://localhost:9090. You should see the Prometheus UI where you can explore your metrics.

4. Install Node Exporter (Optional)

If you want to gather system metrics, install Node Exporter:

  1. Download Node Exporter:
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
  1. Extract and run:
tar xvf node_exporter-1.5.0.linux-amd64.tar.gz
cd node_exporter-1.5.0.linux-amd64
./node_exporter

Node Exporter will listen on port 9100 by default, which you can add to your Prometheus configuration.

5. Set Up Grafana

After configuring Prometheus, you can set up Grafana for visualization:

  1. Download Grafana: Visit the Grafana download page and select your OS. For example:
wget https://dl.grafana.com/oss/release/grafana-9.6.1.linux-amd64.tar.gz
  1. Extract and run Grafana:
tar -zxvf grafana-9.6.1.linux-amd64.tar.gz
cd grafana-9.6.1
./bin/grafana-server web

6. Connect Grafana to Prometheus

Once Grafana is running, access it at http://localhost:3000. Log in using the default credentials (username: admin, password: admin). After logging in:

  1. Click on the gear icon to access the configuration menu.
  2. Select Data Sources.
  3. Click Add data source and choose Prometheus.
  4. Set the URL to http://localhost:9090 and save.

7. Create Dashboards

Now that Grafana is connected to Prometheus, you can create dashboards to visualize your metrics:

  1. Click on the + icon in the left sidebar and select Dashboard.
  2. Click on Add new panel.
  3. Select the Prometheus data source and enter your query.

This process allows you to visualize metrics such as CPU usage, memory consumption, and more, providing valuable insights into your system's performance.

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.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.