Alert Query Multi-Condition Filters
Introduction: Events vs Numbers
In the previous lesson, you monitored CPU usage—a number that goes up and down. You asked: "Is CPU above 80%?" This works great for metrics.
But what about application logs? Your services generate thousands of log entries every minute: "User logged in successfully," "Payment processed," "Database connection failed," "API request completed." You don't want to measure these—you want to filter them. You need alerts that say "notify me when ERROR logs appear" rather than "notify me when a number is too high."
This lesson shows you how Grafana handles event-based alerts using multi-condition filters.
Alert Philosophy: Symptoms, Not Causes
Before building any alert, understand this rule: alert on symptoms, not root causes.
A symptom is what users experience. Users can't log in. That's a symptom. The root cause might be database connection pool exhaustion, but that's a technical detail one layer removed from user impact.
Why does this matter? If you alert on every technical anomaly—CPU spikes, memory increases, cache misses—you'll get hundreds of alerts daily. Engineers start ignoring them. Critical alerts get lost in noise. But if you alert when users can't log in, that's always worth investigating.
Grafana excels at symptom-based monitoring because you can combine conditions. Instead of alerting on a single database error (which might be a transient blip), you can alert when ERROR logs appear in your auth service AND those errors persist for more than 2 minutes AND the error rate exceeds 5% of total requests. This multi-condition approach filters out noise.
Your Log Data Structure
Your PostgreSQL database has a log_events table that captures logs from your microservices:
If you query recent data, you might see:
| ts | level | service | message |
|---|---|---|---|
| 2024-01-15 14:23:00+00 | INFO | auth | User login successful |
| 2024-01-15 14:23:30+00 | ERROR | search | Database connection timeout |
| 2024-01-15 14:24:15+00 | ERROR | auth | Failed to verify JWT token |
Notice how INFO logs vastly outnumber ERROR logs—maybe a 1000:1 ratio in production. Most operations succeed, so you need filtering to focus only on the errors that matter.
