Metrics & Alarms
Understand namespaces and dimensions, and get paged before your users notice.
Metrics
A metric is a time series identified by:
- Namespace: the group, e.g.
AWS/Lambdaor your ownNoteSnap - Metric name: e.g.
Errors - Dimensions: name/value pairs that narrow it, e.g.
FunctionName=notesnap-summarize
You view metrics with a statistic (Sum, Average, Maximum, p99…) over a period (1 minute, 5 minutes…).
For latency, watch p95 or p99 rather than Average. Averages hide the slow requests your unhappiest users experience.
Alarms
An alarm watches one metric (or a math expression) and changes state:
OK: within thresholdALARM: breached for N of M periodsINSUFFICIENT_DATA: not enough data yet
On state change it can notify an SNS topic (email, Slack via a chatbot, PagerDuty), trigger Auto Scaling, or run an automated action.
Try it
# Alert if the summarizer has any errors in 2 of the last 3 five-minute periods
aws cloudwatch put-metric-alarm \
--alarm-name notesnap-summarize-errors \
--namespace AWS/Lambda --metric-name Errors \
--dimensions Name=FunctionName,Value=notesnap-summarize \
--statistic Sum --period 300 \
--evaluation-periods 3 --datapoints-to-alarm 2 \
--threshold 0 --comparison-operator GreaterThanThreshold \
--treat-missing-data notBreaching \
--alarm-actions arn:aws:sns:us-east-1:123456789012:ops-alerts--treat-missing-data notBreaching matters for Lambda: when nothing runs, there's no Errors data at all,
and you don't want that to look like a problem.
Key takeaways
- Metrics are identified by namespace, name, and dimensions.
- Use percentiles (p95/p99) for latency, not averages.
- Alarms notify SNS or trigger actions when thresholds are breached.
Check your understanding
Pick an answer to see the explanation.
1. Your API's average latency looks fine, but users complain it's slow. What should you look at?