When something important breaks, monitoring does not send one alert; it sends thousands, from every system that depends on the broken one. Event correlation turns that storm into one incident with a likely cause: events are normalised into one shape, enriched with owner, service, and recent changes, deduplicated, grouped by topology (what depends on what) and time, and suppressed where they are only symptoms. Anomaly detection adds signals nobody wrote a threshold for. Every step is measured against labelled incidents, because a noise filter that hides a real problem is worse than the noise. This lesson follows one database failure through the pipeline, and shows two failures: correlation with no topology, and an anomaly detector that cried wolf until it was muted.
Difficulty: Advanced · Know this first: Lesson 322, Lesson 222
By the end of this lesson you can work at four levels:
This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.
This bar adds up minutes from a failure to the right team holding one incident. It is a worked example, not a measurement. The correlation and anomaly hops decide whether noise reduction helps or hides.
Pick how alerts are correlated, how the anomaly detector builds its baseline, and how aggressive suppression is. The readouts come from replaying last quarter's labelled events.
Three questions. No score is saved anywhere — this is just you against the material.
Event correlation grows in four levels: reading an incident's evidence, building the pipeline, tuning it with data, and running it as a measured system.
At the basic level you can read what the correlation engine grouped and why.
Where it breaks: acting on the suggested origin without confirming it.
Try it: Basic
The incident suggests orders-db as origin. What do you do first?
Now do it: Check how often your tool's suggestions were right.
At the intermediate level you build normalisation, enrichment, dedup, and correlation.
Try it: Intermediate
Which enrichment helps most in finding causes?
Now do it: Attach recent deploys to your next incident automatically.
At the advanced level every rule is tuned against labelled history.
Try it: Advanced
How do you know a new correlation rule is better?
Now do it: Build a small replay set from three past incidents.
At the master level the correlation system has its own SLOs and governance.
Trade-off: aggressive grouping reduces pages and can merge two real incidents into one; measure both.
Try it: Master
Someone muted a noisy detector permanently. What policy prevents this from hiding incidents?
Now do it: List every active mute and its expiry.
Alertmanager does simple versions of grouping, deduplication, and suppression. This configuration groups alerts by service and cluster, and inhibits symptom alerts while the database they depend on is down (check the current Alertmanager documentation):
route: receiver: default group_by: [service, cluster] # one notification per service per cluster group_wait: 30s # wait for related alerts before the first notification group_interval: 5m repeat_interval: 4h inhibit_rules: - source_matchers: [alertname="DatabaseDown"] target_matchers: [severity=~"warning|critical", depends_on="orders-db"] equal: [cluster] # only within the same cluster
A seasonal anomaly score in plain terms: for this metric at this hour of this weekday, take the last four weeks' values, compute the median and the median absolute deviation (MAD), and score now as |value − median| ÷ (1.4826 × MAD). A score over about 4 is unusual. Robust statistics like these are not thrown off by last week's incident the way a mean and standard deviation are.
The evaluation metrics: precision = pages that were real ÷ all pages; recall = real incidents that paged ÷ all real incidents; compression = events ÷ incidents; plus mean time to the right team. Report them per rule change, on the same replay set.
This is a composite of a failure pattern that keeps repeating; the details are illustrative. The detector that was muted.
The detector uses a four-week seasonal baseline, anomalies create tickets rather than pages until their precision passes 0.8, every mute has an owner and expiry and appears in a weekly review, and rule changes are replayed against labelled incidents before release.
Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.
Before you start: Linux with jq (sudo apt install jq) and Python 3.
Type each one, read what it prints, and compare it with the note above it.
Write a small alert storm as JSON lines, the way a collector would export it.
mkdir -p ~/labs/aiops && cd ~/labs/aiops
cat > events.jsonl <<'EOF'
{"t":"10:00:05","service":"orders-db","check":"replication","msg":"replica lag 45s"}
{"t":"10:01:10","service":"orders-db","check":"up","msg":"primary unreachable"}
{"t":"10:01:12","service":"checkout","check":"http_5xx","msg":"5xx rate 34%"}
{"t":"10:01:14","service":"checkout","check":"http_5xx","msg":"5xx rate 41%"}
{"t":"10:01:20","service":"payments","check":"latency","msg":"p99 4.1s"}
{"t":"10:01:31","service":"invoices","check":"queue_lag","msg":"lag 9,000"}
{"t":"10:01:40","service":"checkout","check":"http_5xx","msg":"5xx rate 44%"}
EOF
wc -l events.jsonlDeduplicate by fingerprint (service and check), counting repeats.
jq -s 'group_by(.service + "/" + .check) | map({fingerprint: (.[0].service + "/" + .[0].check), count: length, first: .[0].t})' events.jsonlFind the most upstream failing service using a dependency map.
cat > deps.json <<'EOF'
{"checkout": ["payments", "orders-db"], "payments": ["orders-db"], "invoices": ["orders-db"], "orders-db": []}
EOF
jq -s --slurpfile d deps.json '[.[].service] | unique as $failing | [$failing[] | select(($d[0][.] // []) as $deps | ($deps - ($deps - $failing)) == [])]' events.jsonlcorrelate.pyThis program runs a storm through deduplication, correlation by time only, and correlation by topology with suppression of dependents, counting the pages each produces. Then it compares an anomaly detector baselined on the previous day with one baselined on the same hour over four weeks, against labelled anomalies. Save it as correlate.py, then run it.
# correlate.py
import statistics
DEPS = {"checkout": ["payments", "orders-db"], "payments": ["orders-db"], "invoices": ["orders-db"],
"search": ["search-index"], "orders-db": [], "search-index": []}
OWNER = {"checkout": "web", "payments": "payments", "invoices": "finance-eng", "search": "search",
"orders-db": "data-platform", "search-index": "search"}
EVENTS = [(t, s, c) for t, s, c in [
(5, "orders-db", "replication"), (70, "orders-db", "up"), (72, "checkout", "5xx"), (74, "checkout", "5xx"),
(80, "payments", "latency"), (91, "invoices", "queue_lag"), (100, "checkout", "5xx"), (130, "search", "latency"),
]]
alerts = {}
for t, svc, check in EVENTS:
alerts.setdefault((svc, check), t)
failing = {svc for svc, _ in alerts}
print(f"{len(EVENTS)} events -> {len(alerts)} alerts after dedup")
time_only = {OWNER[s] for s, _ in alerts}
print(f"time-window grouping: pages {len(time_only)} teams: {sorted(time_only)}")
def upstream(svc, seen=()):
bad = [d for d in DEPS[svc] if d in failing and d not in seen]
return svc if not bad else upstream(bad[0], seen + (svc,))
incidents = {}
for svc in failing:
incidents.setdefault(upstream(svc), set()).add(svc)
for origin, members in sorted(incidents.items()):
suppressed = sorted(members - {origin})
print(f"topology: incident origin {origin:<10} page {OWNER[origin]:<14} suppressed: {suppressed}")
print()
WEEKS = 5
def traffic(week, day, hour):
base = 200 if day >= 5 else 900 # weekends are quiet
rush = 1.6 if (day == 0 and hour == 8) else 1.0
leak = 1.0 + (0.04 * day if (week == WEEKS - 1 and 1 <= day <= 3 and hour == 14) else 0)
return base * rush * leak
def score(series, value):
med = statistics.median(series)
mad = statistics.median(abs(x - med) for x in series) or 1
return abs(value - med) / (1.4826 * mad)
week = WEEKS - 1
labelled = {(1, 14), (2, 14), (3, 14)} # the real anomaly: a leak on Tue-Thu afternoons
for name in ("previous day", "same hour, 4 weeks"):
flagged = set()
for day in range(7):
for hour in (8, 14):
now = traffic(week, day, hour)
if name == "previous day":
ref = [traffic(week, (day - 1) % 7, h) for h in range(24)]
else:
ref = [traffic(w, day, hour) for w in range(week)] + [traffic(w, day, hour) * 1.01 for w in range(week)]
if score(ref, now) > 4:
flagged.add((day, hour))
tp = len(flagged & labelled)
print(f"baseline {name:<19} flagged {len(flagged):>2} true {tp} false {len(flagged) - tp} missed {len(labelled - flagged)}")
Run it, and you should see this output:
$ python3 correlate.py 8 events -> 6 alerts after dedup time-window grouping: pages 5 teams: ['data-platform', 'finance-eng', 'payments', 'search', 'web'] topology: incident origin orders-db page data-platform suppressed: ['checkout', 'invoices', 'payments'] topology: incident origin search page search suppressed: [] baseline previous day flagged 7 true 3 false 4 missed 0 baseline same hour, 4 weeks flagged 3 true 3 false 0 missed 0
The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/aiops-event-correlation-and-noise-reduction && cd ~/labs/aiops-event-correlation-and-noise-reduction) and save this as lab.sh.
#!/usr/bin/env bash
# The Linux steps of "AIOps Event Correlation and Noise Reduction: From 2,400 Alerts to One Incident", as one script (save it as lab.sh).
#
# ./lab.sh run every step, in order
# ./lab.sh 2 4 run only steps 2 and 4
# ./lab.sh --list list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.
STEPS=(
'Write a small alert storm as JSON lines, the way a collector would export it.'
'Deduplicate by fingerprint (service and check), counting repeats.'
'Find the most upstream failing service using a dependency map.'
)
step_1() {
mkdir -p ~/labs/aiops && cd ~/labs/aiops
cat > events.jsonl <<'EOF'
{"t":"10:00:05","service":"orders-db","check":"replication","msg":"replica lag 45s"}
{"t":"10:01:10","service":"orders-db","check":"up","msg":"primary unreachable"}
{"t":"10:01:12","service":"checkout","check":"http_5xx","msg":"5xx rate 34%"}
{"t":"10:01:14","service":"checkout","check":"http_5xx","msg":"5xx rate 41%"}
{"t":"10:01:20","service":"payments","check":"latency","msg":"p99 4.1s"}
{"t":"10:01:31","service":"invoices","check":"queue_lag","msg":"lag 9,000"}
{"t":"10:01:40","service":"checkout","check":"http_5xx","msg":"5xx rate 44%"}
EOF
wc -l events.jsonl
}
step_2() {
jq -s 'group_by(.service + "/" + .check) | map({fingerprint: (.[0].service + "/" + .[0].check), count: length, first: .[0].t})' events.jsonl
}
step_3() {
cat > deps.json <<'EOF'
{"checkout": ["payments", "orders-db"], "payments": ["orders-db"], "invoices": ["orders-db"], "orders-db": []}
EOF
jq -s --slurpfile d deps.json '[.[].service] | unique as $failing | [$failing[] | select(($d[0][.] // []) as $deps | ($deps - ($deps - $failing)) == [])]' events.jsonl
}
# print a step that has to be run by hand, instead of running it
by_hand() {
echo " (run this one yourself: $1)"
sed 's/^/ /'
}
RESULTS=()
run_step() {
local n=$1 start=$SECONDS code
printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
"step_$n"
code=$?
RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}
summary() {
echo
echo "== summary"
local r
for r in "${RESULTS[@]}"; do echo " $r"; done
}
case "${1:-}" in
-h|--help) sed -n '2,6p' "$0"; exit 0 ;;
--list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac
[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
echo "there is no step '$n'; try --list" >&2
exit 2
fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done
Then make it executable and run it:
chmod +x lab.sh ./lab.sh --list # the steps ./lab.sh # every step, then a summary of exit codes and times ./lab.sh 2 3 # only steps 2 and 3
New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.
wc, mkdir, cat, cd, Pipes, Redirection, If...Else, Here documents.On-call engineers at your company get 900 pages a week, and two major incidents last quarter were found by customers. Design the event correlation and noise reduction system.
Which sources feed it, and what schema do they share? Where do topology and ownership come from? How do you deduplicate, correlate, and suppress? How are anomalies used? How do you prove it reduces noise without missing incidents?
Say 400 services, 9 monitoring tools, 1.5 million events a day, 900 pages a week, and 60 real incidents a quarter.
Normalise all sources to an OpenTelemetry-based event schema; enrich from the service catalogue (owner, tier, runbook) and the change log; dedup by fingerprint; correlate on the dependency graph from tracing and the mesh within time windows; suppress dependents of a known origin with expiry; seasonal anomaly detection that creates tickets until precision is proven; a replay set of last quarter's labelled events; targets of recall 1.0 for tier-1 incidents and fewer than 3 pages per incident; weekly review of mutes and suppression rules.
Topology data takes work to keep accurate, and correlation is only as good as it; aggressive grouping can merge separate incidents; anomaly detection finds unknown problems and adds noise until tuned.
Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.
| Scenario | Where | Effect | What goes wrong |
|---|---|---|---|
| No topology | Hop 5: Correlation | Breaks | There is no dependency map. Correlation groups by 5-minute windows and message similarity. The storm becomes 14 incidents ("checkout 5xx", "payment timeouts", "queue lag", "search slow"…), each routed to its own team. |
| Noisy anomaly detector | Hop 7: Anomaly detection | Breaks | The detector compares each hour with the previous day. Every Monday at 08:00 traffic jumps from Sunday levels and it pages "anomalous latency". After a month of weekly false pages, on-call mutes it. |
The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.
Last updated . Next review due by November 2027. Found something out of date? Tell me.