Module 4 ยท Lecture 16

Alerts in Grafana: From Data to Action

Alert rules ยท Contact points ยท Routing ยท Alert design strategy

โฑ 90 minutes ๐Ÿ“ Prerequisites: Lecture 15 (dashboards built) ๐Ÿ”ง Lab: Alert rules + Slack/email routing

Contents

  1. Learning Objectives
  2. Session Timeline
  3. Why Alerts Matter
  4. Grafana Alert Architecture
  5. Lab Part 1 โ€” Create Alert Rules
  6. Lab Part 2 โ€” Configure Contact Points
  7. Alert Design Framework
  8. Case Studies
  9. Module 4 Summary
  10. Key Takeaways

Learning Objectives

Session Timeline

TimeSegmentActivity
0โ€“10 minRecapL15 dashboards โ€” what are you watching and why?
10โ€“25 minWhy Alerts MatterThe "sleeping in front of a dashboard" problem
25โ€“40 minGrafana Alert ArchitectureRules, contact points, notification policies, state machine
40โ€“60 minLab Part 1Create alert rules on Open Alerts count panel
60โ€“70 minLab Part 2Configure email / Slack contact point + routing
70โ€“80 minAlert Design FrameworkThresholds, routing, escalation, fatigue
80โ€“88 minCase StudiesZepto & HDFC Securities production alerting
88โ€“90 minModule 4 Wrap-UpCourse arc + Final Project preview

Section 1: Why Alerts Matter

A dashboard is only useful if someone is looking at it. In a 24-hour streaming system, no one watches 24 hours a day. Alerts let the data come to you โ€” instead of you going to the data.

Without alerts:
  10:47 PM  INFY price drops 6% โ€” alert fires in stock_alerts
  10:47 PM  Nobody sees it
  11:30 PM  Risk manager checks Grafana manually โ€” too late

With alerts:
  10:47 PM  Grafana alert fires โ†’ Slack message in #risk-alerts
  10:48 PM  Manager reviews position, takes action
ToolPurposeActs On
LoggingRecord everything that happenedEngineers debugging after an event
MonitoringShow current state continuouslyTeams watching dashboards
AlertingNotify when action is neededDecision-makers who need to respond

Key principle: The goal of an alert is to trigger a human action. If an alert fires and nobody knows what to do, the alert is not useful โ€” it is noise. Every alert rule should have a corresponding runbook: who gets notified and what they do.

Section 2: Grafana Alert Architecture

Three Components

  1. Alert Rules โ€” Conditions evaluated on a schedule. Each rule has a query and fires when the condition is met for a defined duration.
  2. Contact Points โ€” Where notifications go. Supported: Email, Slack, PagerDuty, Opsgenie, Teams, Webhook, Telegram, and 20+ more.
  3. Notification Policies โ€” Routing rules: which alert labels go to which contact point.

The Alert State Machine

NORMAL
โ†’ condition met โ†’
PENDING
โ†’ "For" duration elapsed โ†’
FIRING
โ†’ condition clears โ†’
RESOLVED

The "For" Duration โ€” Why It Matters

Without a "For" duration, a single bad data point triggers an alert. With For: 2m, the condition must be true for 2 continuous minutes before the alert fires.

Without "For":
  Tick 1: Rs 1390 โ†’ FIRES immediately (bad tick? spike? genuine drop?)
  Tick 2: Rs 1410 โ†’ Resolves โ€” false alarm. Engineers start ignoring alerts.

With For: 2m:
  Tick 1: Rs 1390 โ†’ enters PENDING state
  2 min later: still Rs 1385 โ†’ FIRES โ€” genuine sustained move, worth acting on.

Section 3: Lab Part 1 โ€” Create Alert Rules

Alert 1: "Too Many Open Alerts"

Navigate: Left sidebar โ†’ Alerting (bell icon) โ†’ Alert Rules โ†’ New alert rule

1

Name: Stock Alerts โ€” High Open Count | Data source: MongoDB

2

Query: stock_alerts collection, match status=open, count

3

Condition: IS ABOVE 5 | Evaluate every: 1m | For: 2m

4

Labels: severity=warning, team=risk

5

Annotations: Summary: "Open alert count has exceeded threshold" | Description: "There are {{ $value }} unreviewed stock alerts."

Alert 2: "Symbol Price Anomaly" (from panel)

  1. Open the INFY Price panel โ†’ Edit โ†’ Alert tab โ†’ Create alert rule from this panel
  2. Condition: IS BELOW 1400 (absolute floor) | For: 1m
  3. Labels: severity=critical, symbol=INFY

Threshold design discussion: Should the threshold be absolute (Rs 1,400) or relative (5% from yesterday's close)? Absolute is simpler to configure. Relative is more accurate but requires the query to compute the deviation. The consumer_alerts.py from Lecture 9 already handles relative alerting at the Kafka layer โ€” Grafana can handle the absolute floor as a safety net.

Section 4: Lab Part 2 โ€” Contact Points

Option A: Email

Requires SMTP configuration in Docker. Add environment variables to the Grafana run command:

-e GF_SMTP_ENABLED=true
-e GF_SMTP_HOST=smtp.gmail.com:587
-e GF_SMTP_USER=your@gmail.com
-e GF_SMTP_PASSWORD=your-app-password

Then: Alerting โ†’ Contact points โ†’ New โ†’ Type: Email โ†’ Add your address โ†’ Test

Option B: Slack Webhook (Recommended for demos)

  1. Go to api.slack.com/apps โ†’ Create New App โ†’ Incoming Webhooks โ†’ Activate
  2. Add New Webhook to Workspace โ†’ select channel #grafana-alerts
  3. Copy webhook URL: https://hooks.slack.com/services/T.../B.../...
  4. Grafana: Alerting โ†’ Contact points โ†’ New โ†’ Type: Slack โ†’ Paste URL โ†’ Test

Notification Routing by Label

Alerting โ†’ Notification policies โ†’ Edit root policy โ†’ Add matchers:

Expected Slack Alert Message

FIRING: Stock Alerts โ€” High Open Count
Severity: warning | Team: risk
Open alert count has exceeded threshold
Current value: 7
Starts at: 11:47:00
Dashboard: http://localhost:3000/d/...

Section 5: Alert Design Framework

Three Questions for Every Alert Rule

  1. Who receives this alert and what will they do? If you can't answer in one sentence, the alert is not ready.
  2. What is the cost of a false positive? Each false positive erodes trust. After 10, people ignore alerts.
  3. What is the cost of a false negative? A missed alert on a financial system can mean regulatory exposure or monetary loss.
Notification CostExampleThreshold Approach
Low (Slack message, easy to dismiss)Warning โ€” 5+ open alertsSensitive threshold OK
Medium (email + calendar)Price below floorThreshold needs care, use "For: 2m"
High (PagerDuty, on-call woken up)System outage, fraud spikeVery precise threshold, long "For" duration

Avoiding Alert Fatigue

Alert fatigue = when so many alerts fire that operators start ignoring them โ€” including the ones that matter.

Section 6: Case Studies

Case A: Zepto โ€” Dark Store Operations

Zepto operates ~350 dark stores. Their alerting rules:

Discussion: Why is the "For" duration 3 minutes for order acceptance but 5 minutes for delivery time? What is different about the business consequence of each?

Case B: HDFC Securities โ€” Trading Platform

Discussion: The order rejection rate alert goes to the CTO, not an engineer. Why? What does this tell you about how alerting functions as a business communication tool, not just a technical one?

Module 4 Summary

What Module 4 Delivered

L14: Grafana BasicsL15: Dashboard BuildL16: Alerts
ConceptData sources, panels, dashboardsDashboard design + live multi-panel buildAlert rules, contact points, routing
BuiltFirst panel: INFY time seriesStock monitor + transactions dashboardsAlert rules with Slack/email routing
Business skillUnderstand the visual layerDesign a dashboard around a business questionDesign an alerting strategy that creates action
Module 1 (L1-L5):    UNDERSTAND โ€” What is streaming? How does Kafka work?
Module 2 (L6-L10):   BUILD โ€” Producer, consumer, MongoDB, alert routing
Module 3 (L11-L13):  SCALE โ€” Windowing, Spark, Flink โ€” enterprise patterns
Module 4 (L14-L16):  VISUALISE โ€” Grafana dashboards + alert routing
Module 5 (L17-L20):  PRESENT โ€” Atlas Charts, final project, real architectures

Key Takeaways

โœ“ Key Takeaways โ€” Lecture 16

  1. Alerts close the feedback loop โ€” data flows in, decisions flow out. Without alerts, dashboards require 24/7 human watching.
  2. Three components: Alert Rules (conditions) โ†’ Notification Policies (routing) โ†’ Contact Points (delivery)
  3. The "For" duration prevents noise โ€” require a condition to persist for 1โ€“2 min before firing
  4. Every alert needs a runbook โ€” who receives it, what they do. If you can't write this, the alert shouldn't exist.
  5. Alert fatigue kills alerting systems โ€” fewer, well-calibrated, high-signal alerts outperform many low-quality ones
  6. Threshold design is a business decision โ€” it depends on cost of false positives vs cost of missing a real event

Coming Up โ€” Module 5: Atlas Charts & Final Project

L17: MongoDB Atlas Charts โ€” native charting tool, no separate install required.
L18โ€“L20: Final Project โ€” architecture review, pipeline critique, presentations.
Start thinking: What business problem are you solving? Who is your end user? What alert would notify a manager without watching the screen?