In this lesson, you will learn how to bridge the gap between abstract reliability targets and real-world observability by configuring Prometheus to track your Service Level Indicators (SLIs) in real-time.
While your Service Level Objectives (SLOs) define the "goal," your SLIs are the specific metrics providing the "scorecard." To implement this in Kubernetes, we use Prometheus to calculate ratios—typically the number of "good" events divided by the "total" events over a rolling window.
Tracking Availability with Ratio Queries
If your SLI is "99.9% of HTTP requests return a 2xx or 3xx status code," you don't just want a raw counter; you want a rate calculation. Using rate() or irate() functions in PromQL allows you to isolate the success rate against the total request volume.
Consider this Prometheus query to calculate the success ratio over a 5-minute window:
sum(rate(http_requests_total{status=~"2.."}[5m]))
/
sum(rate(http_requests_total[5m]))
From Queries to Alerting Rules
Tracking a graph is useful, but proactive reliability requires alerts. You should define recording rules to pre-calculate these SLIs, and then create alerting rules that trigger when your error budget consumption exceeds a defined threshold.
For example, an alerting rule for "High Error Rate" would look like this:
groups:
- name: reliability.rules
rules:
- alert: HighErrorRate
expr: |
(sum(rate(http_requests_total{status=~"5.."}[5m]))
/
sum(rate(http_requests_total[5m]))) > 0.001
for: 2m
labels:
severity: page
annotations:
summary: "High error rate detected"
description: "Service is exceeding the 99.9% availability threshold."
By embedding these queries into your Prometheus configuration, you move from "monitoring CPU and RAM" to "monitoring user experience." You are no longer just looking at system health; you are programmatically enforcing the reliability targets you established during your SLO planning phase. When the expression evaluates to true, it signals that your production operations are impacting your defined user experience goals, requiring immediate engineering attention.
Key Takeaway: Implementing SLI monitoring requires transforming raw metric counts into ratio-based PromQL queries and wrapping them in alerting rules that trigger based on your defined SLO thresholds.