Amazon CloudWatch is a monitoring and observability service built for DevOps engineers, developers, site reliability engineers (SREs), and IT managers. It provides data and actionable insights to monitor your applications, respond to system-wide performance changes, optimize resource utilization, and get a unified view of operational health.
Core Architecture: The Three Pillars
CloudWatch is built around three fundamental data types.
1. Metrics: Numerical data points measured over time.
- Example: "CPU Utilization is 85% at 10:00 AM."
- Source: AWS services send metrics automatically (e.g., EC2, RDS, Lambda). You can also send Custom Metrics from your own applications (e.g., "Number of items in cart").
2. Logs: Text files containing detailed records of events.
- Example: An Apache access log or a Lambda function error trace.
- Storage: Logs are organized into Log Groups (e.g., /aws/lambda/my-function) and Log Streams (individual instances).
3.Events (now EventBridge): A stream of system events that describe changes in AWS resources.
- Example: "EC2 Instance State changed from Running to Stopped."
Amazon CloudWatch Features
Metrics
- It represents a time-ordered set of data points that are published to Amazon CloudWatch.
- All data point is marked with a timestamp.
- Metric is a variable that is monitored and data points are the value of that variable over time.
- They are uniquely defined by a name, namespace, and zero or more dimensions.
- Metric math is used to query multiple CloudWatch metrics and use math expressions to create new time series based on these metrics
Dimensions
- A dimension is a name/value pair which uniquely identifies a metric.
- Dimensions are the unique identifiers for a metric, so whenever you add a unique name/value pair to one of the metrics, you are creating a new variation of that metric.
Statistics
- Statistics are metric data aggregations over specified periods of time.
- The few available statistics on CloudWatch are maximum, minimum, sum, average, and sample count.
Alarm
- It is used to automatically initiate actions on our behalf.
- It watches a single metric over a specified time period and performs one or more specified actions based on the value of the metric.
- The estimated AWS charges can also be monitored using the alarm.
Percentiles
- It represents the relative weightage of the data in a dataset.
- It helps the user to get a better understanding of the distribution of metric data.
CloudWatch dashboard
- A user-friendly CloudWatch console is available which is used for monitoring resources in a single view.
- There is no limit on the number of CloudWatch dashboards you can create.
- These dashboards are global and not region-specific.
CloudWatch agent
- It is required to be installed.
- It collects logs and system-level metrics from EC2 instances and on-premises servers.
CloudWatch Events
- CloudWatch events help you to create a set of rules that match with any event(i.e. stopping of EC2 instance).
- These events can be routed to one or more targets like AWS Lambda functions, Amazon SNS Topics, Amazon SQS queues, and other target types.
- CloudWatch Events observes the operational events continuously and whenever there is any change in the state of the event, it performs the action by sending notifications, activating lambda, etc.
- An event indicates a change in the AWS environment. Whenever there is a change in the state of AWS resources, events are generated.
- Rules are used for matching events and routing to targets.
- Target process events. They include Amazon EC2 instances, AWS Lambda functions, etc. A target receives the events in JSON format.
CloudWatch logs
- Amazon CloudWatch logs enable you to store, monitor, and access files from AWS resources like Amazon EC2 instances, Route53, etc.
- It also helps you to troubleshoot your system errors and maintain the logs in highly durable storage.
- It also creates log of information about the DNS queries that Route 53 receives.
Getting started with Amazon CloudWatch
Notifying gfg website management team when the instance on which gfg website is hosted stops Whenever the CPU utilization of instance (on which GeeksForGeeks website is hosted ) goes above 80%, CloudWatch event is triggered. This CloudWatch event then activates the SNS topic which sends the alert email to the attached gfg subscribers.
Create an SNS Topic
Step 1: Let us assume that you have already launched an instance with the name tag 'instance'.

Step 2: Go to SNS topic dashboard and click on create a topic.

Step 3: You will be directed to this dashboard. Now specify the name and display name.

Step 4: Scroll down and click on create the topic.

Step 5: The SNS topic is created successfully.

Add Subscribers
Step 1: Go to the SNS topic dashboard and click on gfgtopic link.

Step 2: Under the subscriptions section, Click on Create subscription.

Step 3: Select Email as protocol and specify the email address of subscribers in Endpoint. Click on create the subscription. Now Go to the mailbox of the specified email id and click on Subscription confirmed.

Craft the CloudWatch Alarm
Step 1: Go to the CloudWatch dashboard on the AWS management console. Click on Metrics in the left pane.

Step 2: In All metrics section click on EC2

Step 3: Click on Per-instance metrics.

Step 4: Select the instance you launched.

Step 5: Go to Graphed metrics, click on the bell icon.

Step 6: This dashboard shows the components of Amazon CloudWatch such as Namespace, Metric Name, Statistics, etc.

Set the Threshold
Step 1: Select the greater threshold. Also, specify the amount( i.e. 80 ) of the threshold value. Click on Next.

Connect the Dots
Step 1: Click on Select an existing SNS topic, also mention the name of the SNS topic you created now.

Step 2: Specify the name of alarm and description which is completely optional. Click on Next and then click on Create alarm.

Monitor your Instances using CloudWatch
Step 3: The alarm is successfully created.

Step 4: You can see the graph which notifies whenever CPU utilization goes above 80%.

CloudWatch vs. CloudTrail
These two services are often confused, but they serve very different purposes.
| Feature | Amazon CloudWatch | AWS CloudTrail |
|---|---|---|
| Focus | Performance & Monitoring. | Auditing & Compliance. |
| Answers | "Is my server slow?" "Is my CPU high?" | "Who deleted the database?" "When did they do it?" |
| Data Type | Metrics & Logs. | API Activity History. |
| Example | 90% CPU Utilization. | User Alice called TerminateInstance at 2:00 PM. |
Benefits of Amazon CloudWatch
- A large amount of data is produced by web applications nowadays so amazon CloudWatch acts as a dashboard that contains the organized collection of whole data.
- It improves the total cost of ownership by providing alarms and also takes automated actions when there is an error in limits provided.
- Applications and resources can be optimized by examining the logs and metric data.
- Detailed Insights from the application are provided through data like CPU utilization, capacity utilization, memory utilization, etc.
- It provides a great platform to compare and contrast the data produced by various AWS services.
Draw Backs of Amazon CloudWatch
- Cloud Watch can be expensive, especially for large-scale monitoring and logging needs.
- Cloud Watch may not be able to handle large amounts of log data, especially during spikes in usage, making it difficult to maintain a consistent level of monitoring and logging.
- The monitoring and logging processes of CloudWatch can consume significant system resources, impacting the overall performance of an application.
- Integrating CloudWatch with other AWS services and third-party tools can be challenging.
- Setting up and managing CloudWatch can be complex, especially for users who are not familiar with cloud-based systems.
Pricing Model
CloudWatch has a Free Tier, but costs can scale quickly if not managed.
- Free Tier: 10 custom metrics, 10 alarms, 5GB log ingestion.
- Metrics: ~$0.30 per metric/month (first 10k).
- Logs:
- Ingestion: ~$0.50 per GB.
- Storage: ~$0.03 per GB.
- Alarms: ~$0.10 per alarm/month.
- Dashboards: ~$3.00 per dashboard/month.
Cost Tip: Be careful with Detailed Monitoring on EC2 (1-minute intervals) and high-resolution custom metrics, as they cost extra.

