- Newest
- Most votes
- Most comments
To monitor your EC2 instance's CPU usage and set up an alarm that triggers an SNS notification when usage exceeds 70%, follow these steps:
-
Open the Amazon CloudWatch console.
-
In the navigation pane, select "Alarms" and then click "Create alarm".
-
Choose the EC2 metric you want to monitor. Select "EC2 > Per-Instance Metrics" and find your instance. Choose the "CPUUtilization" metric.
-
Set the alarm conditions:
- For statistic, select "Average"
- For period, choose 5 minutes (300 seconds)
- For threshold type, select "Static"
- For condition, choose "Greater than"
- Set the threshold value to 70
-
Configure the evaluation periods. For example, set it to trigger when the condition is met for 2 consecutive periods out of 2.
-
Set up the SNS notification:
- Choose "Create new topic" if you don't have an existing one
- Enter a name for your SNS topic
- Add email addresses that should receive the notification
-
Give your alarm a name and description.
-
Review the settings and click "Create alarm".
After creation, AWS will send a confirmation email to the addresses you provided. Make sure to confirm the subscription to receive alarm notifications.
This setup will monitor your EC2 instance's CPU utilization and send an email notification whenever it exceeds 70% for two consecutive 5-minute periods. You can adjust these parameters as needed for your specific use case.
To get more exposure, consider exploring additional CloudWatch features such as:
- Creating a dashboard to visualize your EC2 metrics
- Setting up alarms for other metrics like memory usage or network traffic
- Using CloudWatch Logs to monitor application logs
- Experimenting with different alarm actions, such as auto-scaling or running Lambda functions
Remember to regularly review and refine your alarms based on your application's behavior and performance requirements.
Sources
Create a CloudWatch alarm for an instance - Amazon Elastic Compute Cloud
Create a CPU usage alarm - Amazon CloudWatch
Use PutMetricAlarm with an AWS SDK or CLI - Amazon CloudWatch
