Menu
Amazon CloudWatch
User Guide

Create a CPU Usage Alarm that Sends Email

You can create an Amazon CloudWatch alarm that sends an email message using Amazon Simple Notification Service (Amazon SNS) when the alarm changes state from OK to ALARM.

The alarm changes to the ALARM state when the average CPU use of an EC2 instance exceeds a specified threshold for consecutive specified periods.

Set Up a CPU Usage Alarm Using the AWS Management Console

To create an alarm that sends email based on CPU usage

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation pane, choose Alarms.

  3. Choose Create Alarm.

  4. Under EC2 Metrics, select a metric category (for example, Per-Instance Metrics).

  5. Select a metric as follows:

    1. Select a row with the instance and the CPUUtilization metric.

    2. For the statistic, choose Average, choose one of the predefined percentiles, or specify a custom percentile (for example, p95.45).

    3. Choose a period (for example, 5 minutes).

    4. Choose Next.

    CPUUtilization metric selected
  6. Define the alarm as follows:

    1. Under Alarm Threshold, type a unique name for the alarm (for example, myHighCpuAlarm) and a description of the alarm (for example, CPU usage exceeds 70 percent).

    2. Under Whenever, for is, choose > and type 70. For for, type 2.

      Alarm threshold specified
    3. Under Actions, for Whenever this alarm, select State is ALARM. For Send notification to, select an existing SNS topic or create a new one.

      Alarm actions specified
    4. To create a new SNS topic, choose New list. For Send notification to, type a name for the SNS topic (for example, myHighCpuAlarm), and for Email list, type a comma-separated list of email addresses to be notified when the alarm changes to the ALARM state. Each email address will be sent a topic subscription confirmation email. You must confirm the subscription before notifications can be sent.

    5. Choose Create Alarm.

Set Up a CPU Usage Alarm Using the AWS CLI

To create an alarm that sends email based on CPU usage

  1. Set up an SNS topic. For more information, see Set Up Amazon SNS Notifications.

  2. Create an alarm using the put-metric-alarm command as follows.

    aws cloudwatch put-metric-alarm --alarm-name cpu-mon --alarm-description "Alarm when CPU exceeds 70%" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 70 --comparison-operator GreaterThanThreshold --dimensions  Name=InstanceId,Value=i-12345678 --evaluation-periods 2 --alarm-actions arn:aws:sns:us-east-1:111122223333:my-topic --unit Percent
  3. Test the alarm by forcing an alarm state change using the set-alarm-state command.

    1. Change the alarm state from INSUFFICIENT_DATA to OK:

      aws cloudwatch set-alarm-state --alarm-name cpu-mon --state-reason "initializing" --state-value OK
    2. Change the alarm state from OK to ALARM:

      aws cloudwatch set-alarm-state --alarm-name cpu-mon --state-reason "initializing" --state-value ALARM
    3. Check that you have received an email notification about the alarm.