teluzia.Cloud Engineer · Day 128
CHAPTER 19 · OBSERVABILITY AND RELIABILITY ENGINEERING

Prometheus fundamentals

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Scraping and targets is today's starting point. If a target answers /metrics successfully, up{job="api"}=1 even when http_requests_total{status="500"} increases. A scrape timeout makes up=0, so investigate collection failure separately from application errors. You will connect this with counters, gauges and labels and promql rates. The lesson's artifact brings these decisions together: Create six timestamped counter samples including a restart; compute a before/after rate and list a bounded label schema.

Think of it this way

Prometheus is a meter reader making regular rounds; counters are odometers, gauges are fuel levels, and labels identify which meter was read.

TOPIC 01 / 03Step by step

Scraping and targets

Prometheus pulls samples from configured endpoints. The up metric describes scrape success, not business success; a healthy scrape can still expose failing requests. If a target answers /metrics successfully, up{job="api"}=1 even when http_requests_total{status="500"} increases. A scrape timeout makes up=0, so investigate collection failure separately from application errors.

WORKED EXAMPLE
If a target answers /metrics successfully, up{job="api"}=1 even when http_requests_total{status="500"} increases. A scrape timeout makes up=0, so investigate collection failure separately from application errors.

A scrape interval schedules collection; a target is the endpoint being collected; an exporter translates another system's measurements into an exposition format. Imagine a node exporter reachable from a developer laptop but blocked from the Prometheus host. The browser test establishes only the laptop path. Inspect the configured target address, the server-to-target network route and scrape error, then compare the last successful sample time. Collection is pull-based for ordinary targets, so application permission to reach Prometheus does not prove the reverse connection works. Scrape duration approaching the timeout predicts missing observations. Faster intervals improve temporal detail but increase collection load and storage. Monitor the collection path itself so a broken observer cannot make an unavailable application appear merely quiet. Inspect the actual scrape error.

Why this matters

A scrape timeout makes up=0, so investigate collection failure separately from application errors.

A common trap

A successful scrape proves every customer request succeeded.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Scraping and targets

Prometheus pulls samples from configured endpoints. The up metric describes scrape success, not business success; a healthy scrape can still expose failing requests. If a target answers /metrics successfully, up{job="api"}=1 even when http_requests_total{status="500"} increases. A scrape timeout makes up=0, so investigate collection failure separately from application errors.

WORKED EXAMPLE
If a target answers /metrics successfully, up{job="api"}=1 even when http_requests_total{status="500"} increases. A scrape timeout makes up=0, so investigate collection failure separately from application errors.

A scrape interval schedules collection; a target is the endpoint being collected; an exporter translates another system's measurements into an exposition format. Imagine a node exporter reachable from a developer laptop but blocked from the Prometheus host. The browser test establishes only the laptop path. Inspect the configured target address, the server-to-target network route and scrape error, then compare the last successful sample time. Collection is pull-based for ordinary targets, so application permission to reach Prometheus does not prove the reverse connection works. Scrape duration approaching the timeout predicts missing observations. Faster intervals improve temporal detail but increase collection load and storage. Monitor the collection path itself so a broken observer cannot make an unavailable application appear merely quiet. Inspect the actual scrape error.

Why this matters

A scrape timeout makes up=0, so investigate collection failure separately from application errors.

A common trap

A successful scrape proves every customer request succeeded.

Counters, gauges and labels

Counters accumulate and may reset; gauges move both directions. Every label combination creates a series, so user IDs are unsuitable metric labels. http_requests_total goes from 100 to 130, then resets to 4 after restart; active_connections can drop from 20 to 8 without a restart. Labels service and status are bounded; request_id creates unbounded series.

WORKED EXAMPLE
http_requests_total goes from 100 to 130, then resets to 4 after restart; active_connections can drop from 20 to 8 without a restart. Labels service and status are bounded; request_id creates unbounded series.

A counter records cumulative events; a gauge represents a current level; label cardinality is the number of distinct label combinations. Consider five HTTP statuses across three services and two environments: that bounded combination already produces up to thirty series per metric. Adding a distinct URL containing each user's identifier can multiply the count dramatically. Use route templates such as /users/:id rather than literal user paths. For queue occupancy, choose a gauge because successful consumption lowers the number; for processed jobs choose a counter. A counter reset after restart is normal and belongs in rate-aware analysis. Rich labels make queries convenient, but each unique combination consumes memory and storage. Put transaction identifiers in logs or traces when individual-request correlation is needed.

Why this matters

Labels service and status are bounded; request_id creates unbounded series.

A common trap

User IDs are ideal labels because each user needs a dedicated metric series.

PromQL rates

Use rate(http_requests_total[5m]) for per-second counter change, then aggregate by bounded labels. Averaging raw counters misrepresents resets and traffic changes. sum by(service)(rate(http_requests_total[5m])) yields throughput, while dividing the 5xx rate by total rate yields error ratio. Aggregate rates after calculating them so counter resets remain identifiable.

WORKED EXAMPLE
sum by(service)(rate(http_requests_total[5m])) yields throughput, while dividing the 5xx rate by total rate yields error ratio. Aggregate rates after calculating them so counter resets remain identifiable.

A range vector contains multiple samples over a window; an instant vector contains one current value per selected series; rate estimates counter increase per second. Suppose one replica restarts while another continues handling requests. Calculate rate on each replica's counter first, then sum the rates by service. Summing raw counters before calculating a rate can obscure the separate reset. For an error ratio, use compatible numerator and denominator filters and windows; otherwise a change in selection can masquerade as a change in reliability. A zero denominator needs deliberate handling instead of an unexplained infinite value. Longer windows stabilize sparse traffic but react more slowly to a new incident. Keep query expressions and time windows beside charts so reviewers can interpret the measurement.

Why this matters

Aggregate rates after calculating them so counter resets remain identifiable.

A common trap

Raw counter values directly represent per-second traffic.

KEEP THESE WITH YOU

Today’s takeaways

Scraping and targets: Prometheus pulls samples from configured endpoints.

Counters, gauges and labels: Counters accumulate and may reset; gauges move both directions.

PromQL rates: Use rate(http_requests_total[5m]) for per-second counter change, then aggregate by bounded labels.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed