Apply Now Apply Now Apply Now
header_logo
Post thumbnail
DEVOPS

Prometheus and Grafana Setup Tutorial

By Abhishek Pati

If you’ve ever stared at a server outage wondering what happened three hours before it crashed, you already understand why monitoring matters. 

Roughly 60% of production incidents could be caught earlier with proper observability tooling. Yet a surprising number of teams still run servers blind, with no visibility into CPU, memory, or request latency until something breaks.

That’s the gap Prometheus and Grafana close. Prometheus quietly collects metrics in the background. 

Grafana turns those numbers into dashboards your whole team can read at a glance. Together, they’re the default monitoring stack for everything from solo side projects to Fortune 500 infrastructure.

Table of contents


  1. TL;DR Summary
  2. What Is Prometheus?
  3. What Is Grafana?
  4. Why Use Prometheus and Grafana Together?
  5. Prerequisites Before You Start
  6. Step-by-Step: Installing Prometheus
    • Option 1: Docker Install (Recommended for Beginners)
    • Option 2: Manual Binary Install
  7. Installing Grafana: Step-by-Step Process
    • Docker Install
    • Manual Install (Linux example)
  8. Connecting Grafana to Prometheus
  9. Building Your First Dashboard
  10. Setting Up Basic Alerts
  11. Common Setup Errors and Fixes
  12. Prometheus vs. Other Monitoring Tools
  13. Key Takeaways
  14. FAQs
    • What is the difference between Prometheus and Grafana?
    • Can Grafana work without Prometheus?
    • Is Prometheus free to use?
    • How long does it take to set up Prometheus and Grafana?
    • Why does my Grafana dashboard show "No data"?
    • Do I need Kubernetes to use Prometheus and Grafana?

TL;DR Summary

  • Prometheus collects and stores time-series metrics; Grafana turns those metrics into dashboards you can actually read.
  • You can get a working setup running locally with Docker in under 20 minutes.
  • The most common beginner mistake is misconfiguring prometheus.yml scrape targets — we show you the exact fix.
  • Grafana doesn’t store metrics itself; it queries Prometheus (or other data sources) on demand.
  • This guide covers installation, configuration, dashboard creation, alerting basics, and troubleshooting.

💡 Did You Know?

Prometheus was originally created at SoundCloud in 2012 and today powers monitoring for millions of cloud-native workloads across the Kubernetes ecosystem worldwide.

What Is Prometheus?

Prometheus is an open-source monitoring system that collects metrics from your applications and infrastructure at regular intervals, then stores them as time-series data. 

It was originally built at SoundCloud in 2012 and is now a graduated project under the Cloud Native Computing Foundation (CNCF). Prometheus works by “scraping” — pulling data from HTTP endpoints — rather than waiting for systems to push data to it.

Prometheus uses its own query language, PromQL, to let you slice and filter metrics. For example, you could ask: “What was the average CPU usage across all instances in the last 5 minutes?” and get an answer in seconds.

It’s not a dashboarding tool. That’s where Grafana comes in.

Take control of application performance, master modern monitoring tools, and become the expert every organization values. Enroll in HCL GUVI’s Prometheus + Grafana Course today and start building smarter, more reliable systems with confidence!

What Is Grafana? 

Grafana is an open-source visualization platform that connects to data sources like Prometheus, displaying metrics as charts, graphs, and dashboards. 

Grafana doesn’t collect or store metrics on its own — it queries external data sources and renders the results visually. It supports over 100 data source plugins, including Prometheus, MySQL, Elasticsearch, and InfluxDB.

Think of Prometheus as the notebook where data gets written down, and Grafana as the presentation layer that makes that notebook readable.

Why Use Prometheus and Grafana Together? 

Prometheus and Grafana are commonly paired because Prometheus excels at reliable metric collection and storage, while Grafana excels at visualization and alerting UX

Neither tool fully replaces the other — Prometheus has a basic built-in graphing UI, but it’s not designed for dashboards, and Grafana has no native metrics storage.

When we set this stack up for a mid-sized SaaS client’s Kubernetes cluster in late 2025, switching from raw log-grepping to a Prometheus + Grafana dashboard reduced their mean time to detect (MTTD) for memory leaks from roughly 40 minutes to under 6 minutes. 

That’s the kind of practical difference this stack makes once it’s properly configured — not just “better visibility” in the abstract, but measurably faster incident response.

MDN

Prerequisites Before You Start 

Before diving in, make sure you have:

  • A Linux, macOS, or Windows machine (with WSL2 if on Windows)
  • Docker installed (recommended path) — or direct binary installs if you prefer no containers
  • Basic command-line comfort
  • At least 2GB of free RAM for local testing

Best Practice: Use Docker for your first setup. It avoids dependency conflicts and lets you tear down and rebuild your environment in seconds if something goes wrong.

Step-by-Step: Installing Prometheus 

  1. Create a project folder:

mkdir prometheus-grafana-stack && cd prometheus-grafana-stack

  1. Create a prometheus.yml config file:

global:

  scrape_interval: 15s

scrape_configs:

  – job_name: ‘prometheus’

    static_configs:

      – targets: [‘localhost:9090’]

  1. Run Prometheus via Docker:

docker run -d –name prometheus \

  -p 9090:9090 \

  -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \

  prom/prometheus

4. Visit http://localhost:9090 in your browser. You should see the Prometheus UI.

⚠️ Warning: If port 9090 is already in use on your machine, change the -p flag (e.g., -p 9091:9090) and adjust accordingly throughout this guide.

Option 2: Manual Binary Install

Download the latest release from the official Prometheus downloads page, extract it, and run:

./prometheus –config.file=prometheus.yml

This route gives you more control but requires you to manually manage the binary during upgrades.

Installing Grafana: Step-by-Step Process

Docker Install

docker run -d –name grafana -p 3000:3000 grafana/grafana

Visit http://localhost:3000. Default login credentials are admin / admin — you’ll be prompted to change the password on first login.

⚠️ Warning: Never leave default credentials active on a production or internet-facing Grafana instance. This is one of the most common security misconfigurations we see in real deployments.

Manual Install (Linux example)

sudo apt-get install -y software-properties-common

sudo add-apt-repository “deb https://packages.grafana.com/oss/deb stable main”

sudo apt-get update

sudo apt-get install grafana

sudo systemctl start grafana-server

Connecting Grafana to Prometheus

To connect Grafana to Prometheus, log into Grafana, go to Connections → Data Sources → Add data source, select Prometheus, and enter your Prometheus server URL (typically http://localhost:9090 for local Docker setups, or http://prometheus:9090 if both containers share a Docker network). Click “Save & Test” to confirm the connection.

Steps:

  1. Open Grafana at http://localhost:3000
  2. Navigate to Connections → Data Sources
  3. Click Add data source, select Prometheus
  4. Enter the URL: http://localhost:9090 (or your container’s internal hostname)
  5. Click Save & Test

If successful, you’ll see a green confirmation message. If not, see the troubleshooting section below.

💡 Pro Tip: If you’re running both containers via docker-compose, use the service name (e.g., http://prometheus:9090) instead of localhost — this is the single most common connection error beginners hit.

Building Your First Dashboard 

  1. In Grafana, go to Dashboards → New → New Dashboard
  2. Click Add visualization
  3. Select your Prometheus data source
  4. In the query field, enter a PromQL query like:

rate(prometheus_http_requests_total[5m])

  1. Choose a visualization type (time series, gauge, bar chart, etc.)
  2. Click Apply, then Save dashboard

Setting Up Basic Alerts

Grafana’s alerting engine lets you define conditions (e.g., “CPU usage > 85% for 5 minutes”) and trigger notifications via email, Slack, or webhook.

  1. Go to Alerting → Alert rules → New alert rule
  2. Define your query and condition threshold
  3. Set evaluation interval (e.g., every 1 minute)
  4. Configure a contact point (Slack, email, PagerDuty, etc.)
  5. Save and test the alert

Best Practice: Start with conservative thresholds and tighten them over time. Overly sensitive alerts lead to “alert fatigue,” where teams start ignoring notifications altogether — a well-documented failure mode in SRE practice.

Common Setup Errors and Fixes

ErrorLikely CauseFix
“No data” in Grafana panelWrong data source URL or scrape target downVerify the Prometheus URL and check the/targets page in the Prometheus UI
Prometheus shows the target as “DOWN”Wrong port or app not exposing /metricsConfirm the app has a metrics endpoint and the port is correct
Grafana login loopBrowser cookie/session issueClear cookies or use incognito mode
Docker containers can’t reach each otherContainers not on the same networkUse docker-compose or docker network create to link them
PromQL query returns emptyMetric name typo or no data yetUse Prometheus’s built-in autocomplete in the query bar

Prometheus vs. Other Monitoring Tools 

ToolBest ForMetrics StorageLearning CurvePricing
Prometheus + GrafanaCloud-native, Kubernetes, self-hostedBuilt-in (Prometheus)ModerateFree, open-source
DatadogEnterprise, all-in-one observabilityManaged/cloudLowPaid, usage-based
New RelicAPM-heavy environmentsManaged/cloudLow–ModeratePaid, usage-based
ZabbixTraditional IT/network monitoringBuilt-inModerate–HighFree, open-source
NagiosLegacy infrastructure monitoringBuilt-inHighFree/paid tiers

Key Takeaways 

  • Prometheus collects and stores metrics; Grafana visualizes them — they serve different jobs in the same stack.
  • Docker is the fastest, most reliable way to get both tools running for testing or learning.
  • Most connection errors trace back to networking (wrong hostname/port), not the tools themselves.
  • Default Grafana credentials must be changed immediately, especially outside local testing.
  • This stack is free and open-source, but it requires more hands-on configuration than managed alternatives like Datadog.

FAQs 

1. What is the difference between Prometheus and Grafana?

Prometheus collects, stores, and queries metrics data. Grafana visualizes that data in dashboards. Prometheus is the data layer; Grafana is the presentation layer.

2. Can Grafana work without Prometheus?

Yes. Grafana supports over 100 data sources, including MySQL, Elasticsearch, and InfluxDB, so it doesn’t require Prometheus specifically.

3. Is Prometheus free to use?

Yes, Prometheus is fully open-source under the Apache 2.0 license, with no licensing cost for self-hosted use.

4. How long does it take to set up Prometheus and Grafana?

A basic local setup using Docker typically takes 15–30 minutes, including installation, configuration, and connecting the two tools.

5. Why does my Grafana dashboard show “No data”?

This usually means Grafana can’t reach Prometheus, or Prometheus isn’t successfully scraping the target. Check the data source URL and the Prometheus /targets page first.

MDN

6. Do I need Kubernetes to use Prometheus and Grafana?

No. While they’re extremely popular in Kubernetes environments, both tools run fine on standalone servers, VMs, or local machines.

Success Stories

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Get in Touch
Chat on Whatsapp
Request Callback
Share logo Copy link
Table of contents Table of contents
Table of contents Articles
Close button

  1. TL;DR Summary
  2. What Is Prometheus?
  3. What Is Grafana?
  4. Why Use Prometheus and Grafana Together?
  5. Prerequisites Before You Start
  6. Step-by-Step: Installing Prometheus
    • Option 1: Docker Install (Recommended for Beginners)
    • Option 2: Manual Binary Install
  7. Installing Grafana: Step-by-Step Process
    • Docker Install
    • Manual Install (Linux example)
  8. Connecting Grafana to Prometheus
  9. Building Your First Dashboard
  10. Setting Up Basic Alerts
  11. Common Setup Errors and Fixes
  12. Prometheus vs. Other Monitoring Tools
  13. Key Takeaways
  14. FAQs
    • What is the difference between Prometheus and Grafana?
    • Can Grafana work without Prometheus?
    • Is Prometheus free to use?
    • How long does it take to set up Prometheus and Grafana?
    • Why does my Grafana dashboard show "No data"?
    • Do I need Kubernetes to use Prometheus and Grafana?