Sub topic 13
Observing health per Availability Zone
This chapter assumes you can read CloudWatch metrics and have an Application Load Balancer (ALB) with targets in at least two AZs, as built in earlier chapters.
Why aggregate metrics hide zonal failures
Suppose a workload runs in three AZs and one AZ starts returning errors. A dashboard that shows the overall error rate may display 33% errors. That looks like a mild problem, but one third of your users are failing. Averages across AZs can stay under your alarm threshold while a whole failure domain is broken.
To detect a zonal failure, measure each AZ separately and compare the results.
Metrics that carry an AZ dimension
The ALB publishes metrics to CloudWatch with an AvailabilityZone dimension, in addition to LoadBalancer and TargetGroup. Useful ones include:
| Metric | What a zonal problem looks like |
|---|---|
| `HealthyHostCount` | Drops to 0 in one AZ only |
| `UnHealthyHostCount` | Rises in one AZ only |
| `HTTPCode_Target_5XX_Count` | Spikes in one AZ |
| `TargetResponseTime` | Climbs in one AZ |
Your own application metrics should also include the AZ as a dimension. An instance can read its AZ ID from instance metadata and attach it to every custom metric it publishes. Prefer the AZ ID over the zone name, because names such as us-east-1a map to different physical zones in different accounts. AZ IDs let you match your data against AWS Health events and against other accounts.
Creating a per-AZ alarm
This alarm fires when no healthy targets remain in one AZ. Create one for each AZ.
aws cloudwatch put-metric-alarm \
--alarm-name "web-healthy-hosts-us-east-1a" \
--namespace AWS/ApplicationELB \
--metric-name HealthyHostCount \
--dimensions Name=TargetGroup,Value="$TARGET_GROUP_DIM" \
Name=LoadBalancer,Value="$LOAD_BALANCER_DIM" \
Name=AvailabilityZone,Value=us-east-1a \
--statistic Minimum \
--period 60 \
--evaluation-periods 3 \
--threshold 1 \
--comparison-operator LessThanThreshold \
--treat-missing-data breachingTARGET_GROUP_DIM has the form targetgroup/web/0123456789abcdef. LOAD_BALANCER_DIM has the form app/web-alb/0123456789abcdef. Setting --treat-missing-data breaching means that a zone that stops reporting data counts as unhealthy.
Telling a zonal event from a global one
Compare the alarms before you act. The decision depends on how many AZs are affected.
If every AZ shows errors, a bad deployment or a shared dependency is more likely than an AZ failure. Moving traffic would not help in that case. A single-AZ pattern points to a zonal event, and you can move traffic away with a zonal shift in Amazon Application Recovery Controller. This only works if the other AZs can absorb the load, which is the static stability work from the previous chapter.
Common errors
- Alarming only on totals. One failed AZ stays hidden in the average.
- Missing data treated as OK. A silent AZ looks healthy. Choose the missing-data setting deliberately.
- Zone names in runbooks. Use AZ IDs so the runbook is correct in every account.
- No external view. Metrics from inside the failing AZ may stop arriving. Add a canary, a synthetic test that calls your endpoint from outside, and record results per AZ where you can.
- Alarms without a response. Each per-AZ alarm should link to a documented action.
Exercise
Your overall 5XX rate is 2%, below your 5% alarm threshold, yet customers in one AZ report failures. What change to your monitoring would expose the problem, and why did the current setup miss it?
Show answer
Alarm on HTTPCode_Target_5XX_Count (or an error rate) per AZ by using the AvailabilityZone dimension. The current setup averages all AZs, so one failing AZ is diluted by the healthy ones and stays under the threshold.