Ravindra BagaleCourses & study guides मराठी Track your progress

Guides

How to Set Up Prometheus and Grafana for Beginners

Configure Prometheus scrapes until Targets are UP, add Prometheus as a Grafana data source, build a PromQL panel, and save the dashboard.

Friends, Prometheus pulls numbers; Grafana draws them. Chala mitrano — get Targets UP before you decorate dashboards.

Quick answer

Hold this vertical picture:

  1. Write prometheus.yml.
  2. Run Prometheus; check Targets.
  3. Add Grafana datasource.
  4. Write PromQL panel.
  5. Save dashboard; learn rate().

Language: English · मराठी · हिंदी

Exporters / appExpose /metrics Prometheus scrapeStore time series PromQLAsk questions Grafana data sourcePoint at Prom Panel + saveDashboard
Prom + Grafana

Why Prometheus + Grafana

Metrics need storage and eyes.

Why: SSH top does not scale to many services. What: Prometheus scrapes; Grafana graphs. How: Start with self-scrape then exporters.

Example 1: Prometheus config scrape sketch

Type this:

mkdir -p /tmp/prom && printf '%s\n' 'global:' '  scrape_interval: 15s' 'scrape_configs:' '  - job_name: "prometheus"' '    static_configs:' '      - targets: ["localhost:9090"]' > /tmp/prom/prometheus.yml && cat /tmp/prom/prometheus.yml

You will see:

global:

What it means: Prometheus scrapes targets on an interval — self-scrape first.

Example 2: Run Prometheus (compose-style idea)

Type this:

printf '%s\n' 'docker run --rm -p 9090:9090 -v /tmp/prom/prometheus.yml:/etc/prometheus/prometheus.yml public.ecr.aws/bitnami/prometheus:latest'

You will see:

docker run --rm -p 9090:9090 -v /tmp/prom/prometheus.yml:/etc/prometheus/prometheus.yml public.ecr.aws/bitnami/prometheus:latest

What it means: Lab path; production uses HA and persistent storage.

Example 7: Targets page check

Type this:

printf '%s\n' 'Open Prometheus UI → Status → Targets — State should be UP'

You will see:

Open Prometheus UI → Status → Targets — State should be UP

What it means: DOWN means scrape failed (network, path, or auth).

Concept 1: Scrape and query

Jobs, targets, PromQL.

Why: DOWN targets make empty graphs. What: Targets UP; up{}; rate(). How: Add node exporter job.

Example 3: Query up metric

Type this:

printf '%s\n' 'up{job="prometheus"}'

You will see:

up{job="prometheus"}

What it means: up==1 means the target answered the scrape.

Example 5: First panel PromQL

Type this:

printf '%s\n' 'rate(process_cpu_seconds_total[1m])'

You will see:

rate(process_cpu_seconds_total[1m])

What it means: rate() turns counters into a per-second view for graphs.

Example 8: Add a node exporter job

Type this:

printf '%s\n' '  - job_name: "node"' '    static_configs:' '      - targets: ["node-exporter:9100"]' >> /tmp/prom/prometheus.yml && tail -4 /tmp/prom/prometheus.yml

You will see:

- job_name: "node"

What it means: Exporters expose metrics Prometheus understands.

Concept 2: Grafana panels

Datasource then Explore then save.

Why: Unsaved work vanishes. What: Prometheus type URL; Explore; Save. How: Name dashboards clearly.

Example 4: Grafana datasource JSON sketch

Type this:

printf '%s\n' '{' '  "name": "Prometheus",' '  "type": "prometheus",' '  "url": "http://prometheus:9090",' '  "access": "proxy"' '}' > /tmp/prom/ds.json && cat /tmp/prom/ds.json

You will see:

{

What it means: Grafana reads Prometheus over HTTP as a data source.

Example 6: Save dashboard reminder

Type this:

printf '%s\n' 'Save the dashboard with a clear name: App CPU — Payments'

You will see:

Save the dashboard with a clear name: App CPU — Payments

What it means: Unsaved panels vanish on refresh — Infosys demos warn about this.

Example 10: Grafana Explore

Type this:

printf '%s\n' 'Grafana → Explore → pick Prometheus → run PromQL → see graph'

You will see:

Grafana → Explore → pick Prometheus → run PromQL → see graph

What it means: Explore before you build a full dashboard.

Concept 3: Ops basics

Reload, retention, pull model.

Why: Restarting blindly loses learners time. What: lifecycle reload; know retention limits. How: Pull vs push interview line.

Example 9: Reload config

Type this:

printf '%s\n' 'curl -X POST http://127.0.0.1:9090/-/reload'

You will see:

curl -X POST http://127.0.0.1:9090/-/reload

What it means: Requires --web.enable-lifecycle; else restart the process.

Example 11: Retention note

Type this:

printf '%s\n' 'Local Prometheus keeps short retention; long-term needs Thanos/Mimir later'

You will see:

Local Prometheus keeps short retention; long-term needs Thanos/Mimir later

What it means: Beginners start local; companies add long-term storage.

Example 12: Interview line

Type this:

printf '%s\n' 'Prometheus pulls (scrapes); many older tools push — that is the mental model'

You will see:

Prometheus pulls (scrapes); many older tools push — that is the mental model

What it means: TCS interviews open with pull vs push.

Prom/Grafana card

1 prometheus.yml scrape 2 Targets UP 3 Grafana Prometheus datasource 4 PromQL panel 5 Save dashboard

Suppose: Target DOWN

Check network, path /metrics, and job config.

Suppose: empty graph

Use rate() on counters; confirm time range.

Ravindra Bagale's Tip

At Flipkart-style on-call, the first panel is often request rate and error rate, not pretty CPU alone. Reviewers ask for rate() on counters.

Check yourself (quiz)

Q1. How does Prometheus get data?

Scrapes (pull) targets

Q2. First health check?

Targets UP

Q3. Grafana needs?

Prometheus data source URL

Q4. Counters on graphs?

rate() or similar

Q5. Empty panel?

Bad query or time range / DOWN target

Q6. Long retention?

Later: Thanos/Mimir

Reading tracking

Mark this guide when you finish. Your browser remembers it on this device.

scrape → UP → datasource → panel → save. Did you understand? Let us try it once more.

Frequently asked questions

Pull vs push?

Prometheus scrapes targets by default.

What is an exporter?

A small process that exposes /metrics.

Why rate()?

Counters only go up; rate makes a graphable per-second.

HA Prometheus?

Advanced — start single then learn.

Grafana without Prometheus?

Other datasources exist; this guide focuses Prom.

Security?

Do not expose UIs publicly without auth.