201 — PromQL Queries & Metric Types

Intermediate

Master the Prometheus Query Language from selectors and matchers to advanced aggregations. Learn the difference between instant and range vectors, use rate() and histogram_quantile(), and build production-ready dashboard queries. Starting state: ~/observability-lab/ running with Prometheus, Grafana, OTel Collector, and demo app from Module 1. After this lesson: you can write PromQL queries for any metric in your stack.

Learning Objectives

1
Master PromQL selectors and matchers
2
Use rate/irate/increase for counter metrics
3
Apply aggregation operators effectively
4
Calculate percentiles from histograms
Step 1

Verify your lab is running

Before diving into PromQL, make sure your observability lab and demo app from Module 1 are running. If you stopped them since Lesson 104, restart everything now.

Commands to Run

cd ~/observability-lab && docker compose up -d
echo 'Waiting for services to start...'
sleep 5
echo 'Checking Prometheus...'
curl -s -o /dev/null -w '%{http_code}' http://localhost:9090/-/healthy
echo ''
echo 'Checking demo app...'
curl -s -o /dev/null -w '%{http_code}' http://localhost:4000/
echo ''
echo 'Generating some traffic for PromQL practice...'
for i in $(seq 1 20); do curl -s http://localhost:4000/ > /dev/null; curl -s http://localhost:4000/users > /dev/null; done
echo 'Done! Lab is ready for PromQL practice.'

What This Does

PromQL queries need data to work with. By restarting the lab and sending some requests to the demo app, you ensure Prometheus has fresh metrics to query. The demo app emits metrics through the OTel Collector, and Prometheus scrapes them every 15 seconds.

Expected Outcome

Both health checks return '200'. The traffic generation completes without errors.

Pro Tips

  • 1
    If the demo app isn't running, restart it: cd ~/observability-lab/app && node server.js &
  • 2
    Wait at least 30 seconds after starting before running PromQL queries — Prometheus needs time to scrape
  • 3
    You can also generate traffic throughout this lesson to see richer query results

Common Mistakes to Avoid

  • ⚠️If Prometheus returns connection refused, Docker may still be starting — wait 10 seconds and try again
  • ⚠️If the demo app returns connection refused, check if server.js is running: ps aux | grep server.js
Was this step helpful?

All Steps (0 / 11 completed)