Sub topic 12
Building dashboards
This chapter assumes you can run AWS CLI commands, know what a metric's namespace, dimensions, and statistic are, and have written a Logs Insights query. A CloudWatch dashboard is a customizable page in the console that shows metrics, alarms, and log query results together. It lets you see the health of a workload in one place.
What a dashboard contains
A dashboard is a JSON document made of widgets. Each widget has a type, a position on a 24-column grid, and properties. The common widget types are:
| Widget type | Shows |
|---|---|
| Line, stacked area, bar, number, gauge | Metrics from one or more resources |
| Alarm status | The current state of selected alarms |
| Logs table | Results of a Logs Insights query |
| Text | Markdown notes, links, and section headings |
Dashboards are global to your account, but each widget names the Region of its data. One dashboard can therefore combine resources from several Regions.
Creating a dashboard from the CLI
The put-dashboard command creates a dashboard or replaces one with the same name. The body is passed as a JSON string. This example puts CPU for two instances on one graph and a Logs Insights error count next to it.
aws cloudwatch put-dashboard \
--dashboard-name web-overview \
--dashboard-body '{
"widgets": [
{
"type": "metric", "x": 0, "y": 0, "width": 12, "height": 6,
"properties": {
"title": "Web CPU",
"region": "us-east-1",
"stat": "Average",
"period": 300,
"metrics": [
["AWS/EC2", "CPUUtilization", "InstanceId", "i-0123456789abcdef0"],
["AWS/EC2", "CPUUtilization", "InstanceId", "i-0fedcba9876543210"]
]
}
},
{
"type": "log", "x": 12, "y": 0, "width": 12, "height": 6,
"properties": {
"title": "Errors per 5 minutes",
"region": "us-east-1",
"view": "table",
"query": "SOURCE '"'"'/app/web'"'"' | filter @message like /ERROR/ | stats count() as errors by bin(5m)"
}
}
]
}'Each metric entry lists the namespace, metric name, then dimension name and value pairs. Because the two entries differ only in the InstanceId value, the graph draws one line per instance.
Design guidance
- Put the most important signals, such as alarm status and error rates, at the top.
- Use a text widget as a heading for each group of related widgets.
- Keep a graph's period consistent with the data. A 60-second period on a metric published every 5 minutes leaves gaps.
- Graph related metrics together only when their units are comparable. Otherwise use the right-hand Y axis for the second unit.
- Add an alarm status widget so a viewer can tell at once whether a threshold has been crossed.
Exercise
A dashboard graph shows CPU for two EC2 instances, but one line is missing. The JSON has two entries under metrics. What is the most likely cause?
Show answer
The second entry probably has a wrong instance ID or a typo in a dimension name. A metric is identified by its namespace, name, and exact dimensions, so a mismatch matches no data and draws no line. Check the entry against aws cloudwatch list-metrics.