Amazon CloudWatch is the observability service for monitoring resources and applications on AWS. It collects data such as the CPU usage of EC2 servers, the number of connections to RDS databases or the error rate of a Lambda function as metrics; stores application and system logs in CloudWatch Logs; and raises alarms when thresholds you set are crossed. In this article we explain CloudWatch’s core concepts and how to use it, based on the AWS documentation.
Core Components of CloudWatch
- Metrics: Time-ordered data points, for example the CPU usage of an EC2 instance. Many services such as EC2, EBS and RDS send basic metrics at no charge; you can also publish your own application metrics.
- Logs: Collects application, server and AWS service logs centrally; you can query them with Logs Insights.
- Alarms: Watch a single metric and trigger an SNS notification or an Auto Scaling action when a threshold is crossed for a set period.
- Dashboards: Show metrics and alarms as graphs on one screen.
- CloudWatch agent: Sends OS-level metrics such as memory and disk usage, and log files, from inside the server; these aren’t in the default EC2 metrics.
Metric Concepts: Namespaces, Dimensions, Resolution
- Namespace: A container for metrics. AWS services use names such as
AWS/EC2andAWS/RDS; you define a separate namespace for your own metrics. - Dimension: A name/value pair that identifies a metric (for example
InstanceId=i-0abc...). A metric can have up to 30 dimensions. - Resolution: AWS metrics are standard resolution (1 minute). You can publish custom metrics at high resolution (1 second).
- EC2 basic vs detailed monitoring: With basic monitoring, EC2 metrics arrive every 5 minutes; with paid detailed monitoring, every minute.
How Long Are Metrics Kept?
| Data point period | Retention |
|---|---|
| Less than 60 seconds (high resolution) | 3 hours |
| 1 minute | 15 days |
| 5 minutes | 63 days |
| 1 hour | 455 days (15 months) |
Short-period data is aggregated over time: 1-minute data can be read at 5-minute resolution after 15 days and at 1-hour resolution after 63 days. Metrics that receive no new data expire automatically after 15 months.
How to Create an Alarm
An alarm watches a single metric and is in one of three states: OK, ALARM or INSUFFICIENT_DATA. An action is triggered only when the state changes and persists for the number of periods you set. For example, to get an email when an EC2 server’s CPU usage exceeds 80% for 5 minutes, using the AWS CLI:
aws cloudwatch put-metric-alarm \
--alarm-name high-cpu \
--namespace AWS/EC2 --metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--statistic Average --period 300 --evaluation-periods 1 \
--threshold 80 --comparison-operator GreaterThanThreshold \
--alarm-actions arn:aws:sns:eu-central-1:111122223333:alertsFor an EC2 metric under basic monitoring, the alarm period should be at least 300 seconds (5 minutes), because data arrives every 5 minutes.
What Do You Use CloudWatch For?
- Monitoring server, database and load balancer performance
- Getting notified immediately when error rates, latency or resource usage rise
- Automatically adding servers with Auto Scaling when load increases
- Collecting application logs in one place for troubleshooting
- Reviewing historical data for cost and capacity planning
Some CloudWatch usage is paid: custom metrics, detailed monitoring, high-resolution alarms and log storage are priced separately. See AWS’s CloudWatch pricing page for current rates.
For other AWS services that CloudWatch monitors, see our articles on Amazon EC2, Amazon RDS and Amazon DynamoDB. If you want to monitor a server outside AWS, open-source tools such as Zabbix, Prometheus + Grafana or Netdata do the same job, and you can install them on your own VDS server.
Conclusion
Amazon CloudWatch brings the metrics, logs and alarms of your AWS resources together in one place. Understanding namespaces and dimensions, data retention periods and alarm periods helps you avoid unnecessary alarms and costs, and lets you notice problems before your users do.
Categories
-
CentOS 7 guides
-
cPanel 20 guides
-
CyberPanel 18 guides
-
Operating Systems 81 guides
-
Juniper Networks 18 guides
-
Control Panels 50 guides
-
Linux 17 guides
-
MySQL 29 guides
-
Network 95 guides
-
Plesk Panel 12 guides
-
Virtual Servers 273 guides
-
SEO 3 guides
-
Cyber Security 8 guides
-
Technology 162 guides
-
VMware 36 guides
-
WordPress 20 guides
-
Artificial Intelligence 22 guides