Amazon CloudWatch
Developer Guide (API Version 2010-08-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Getting Statistics for a Metric

This set of scenarios shows you how you can use the AWS Management Console, the mon-get-stats command, or the GetMetricStatistics API to get a variety of statistics.

[Note]Note

Start and end times must be within the last 14 days.

Getting Statistics Aggregated Across All Instances

This scenario shows you how to use either the AWS Management Console, the GetMetricStatistics API, or the mon-get-stats command to get the average CPU usage for all EC2 instances for the account. Because no dimension is specified, Amazon CloudWatch returns statistics for all dimensions in the AWS/EC2 namespace.

[Important]Important

This technique for retrieving all dimensions across an AWS namespace does not work for custom namespaces that you publish to Amazon CloudWatch. With custom namespaces, you must specify the complete set of dimensions that are associated with any given data point to retrieve statistics that include the data point.

AWS Management Console

To display average CPU utilization for all your EC2 instances

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

  2. In the Navigation pane, click Metrics.

    The Metrics page opens.

    AWS Management Console Viewing all Metrics
  3. Select EC2: Aggregated Across Instances from the Viewing drop-down list.

    The metrics available across all instances appear.

  4. Select the row that contains CPUUtilization.

    A graph showing CPUUtilization for all EC2 instances appears.

    AWS Management Console metrics aggregated across all EC2 instances.

Command Line Tools

To get average CPU utilization across all Amazon EC2 instances

  • Enter the mon-get-stats command with the following parameters:

    Prompt>mon-get-stats CPUUtilization --start-time 2011-01-10T23:18:00 --end-time 2011-01-12T23:18:00 --period 360 --namespace "AWS/EC2" --statistics "Average,SampleCount" --headers

    Amazon CloudWatch returns the following (partial listing):

    Time                 SampleCount  Average  Unit
            2011-01-10 14:18:00  60.0         0.1138   Percent
            2011-01-10 15:18:00  60.0         0.1078   Percent
            2011-01-10 16:18:00  60.0         0.3322   Percent
            2011-01-10 17:18:00  60.0         0.1397   Percent
            2011-01-10 18:18:00  60.0         0.1143   Percent
            2011-01-10 19:18:00  60.0         0.1082   Percent
            2011-01-10 20:18:00  36.0         0.1367   Percent

Query API

To get average CPU utilization for all your EC2 instances

  • Call GetMetricStatistics with the following parameters:

    • MetricName = CPUUtilization

    • Statistics list includes Average

    • Namespace = AWS/EC2

    • StartTime = 2011-01-10T23:18:00

    • EndTime = 2011-01-12T23:18:00

    • Period = 360

    The returned statistics are six-minute values for the two-day interval.

Getting Statistics Aggregated by Auto Scaling Group

This scenario shows you how to use the AWS Management Console, the mon-get-stats command, or the GetMetricStatistics API with the DiskWriteBytes metric to retrieve the total bytes written to disk for one Auto Scaling group. The total is computed for one-minute periods for a 24-hour interval across all EC2 instances in the specified AutoScalingGroupName.

[Note]Note

Start and end times must be within the last 14 days.

We assume for this example that an EC2 application is running and has an Auto Scaling group named test-group-1.

AWS Management Console

To display total DiskWriteBytes for an Auto-Scaled EC2 application

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

  2. In the Navigation pane, click Metrics.

    The Metrics page opens.

    AWS Management Console viewing all metrics
  3. Select EC2: Aggregated by Auto Scaling Group from the Viewing drop-down list.

    The metrics available for Auto Scaling groups appear in the Metrics pane.

  4. Select the row that contains DiskWriteBytes.

    A graph showing DiskWriteBytes for all EC2 instances appears in the Metrics pane.

    AWS Management Console metrics aggregated across an Auto Scaling Group.

Command Line Tools

To get total DiskWriteBytes for an Auto-Scaled EC2 Application

  • Enter the mon-get-stats command with the following parameters.

    Prompt>mon-get-stats DiskWriteBytes --start-time 2011-01-10T23:18:00 --end-time 2011-01-11T23:18:00 --period 60 --namespace AWS/EC2 --statistics "Sum,SampleCount" --dimensions "AutoScalingGroupName=test-group-1" --headers

    Amazon CloudWatch returns the following (partial listing):

    Time                 SampleCount  Sum        Unit
            2011-01-10 15:52:00  1.0          196608.0   Bytes
            2011-01-10 15:53:00  1.0          180224.0   Bytes
            2011-01-10 15:54:00  1.0          200704.0   Bytes
            2011-01-10 15:55:00  1.0          200704.0   Bytes
            2011-01-10 15:56:00  1.0          200704.0   Bytes
            2011-01-10 15:57:00  1.0          180224.0   Bytes
            2011-01-10 15:58:00  1.0          196608.0   Bytes
            2011-01-10 15:59:00  1.0          372736.0   Bytes
            2011-01-10 16:00:00  1.0          258048.0   Bytes

Query API

To get total DiskWriteBytes for an Auto-Scaled EC2 Application

  • Call GetMetricStatistics with the following parameters:

    • MetricName = DiskWriteBytes

    • Period = 60

    • Statistics list includes Sum

    • Unit = Bytes

    • Dimensions (Name=AutoScalingGroupName, Value=test-group-1)

    • Namespace = AWS/EC2

    • StartTime = 2011-01-10T23:18:00

    • EndTime = 2011-01-11T23:18:00

    The statistics returned are one-minute totals for bytes written for the entire Auto Scaling group over the 24-hour interval.

Getting Statistics Aggregated by Image (AMI) ID

This scenario shows you how to use the AWS Management Console, the mon-get-stats command, or the GetMetricStatistics API to determine average CPU utilization for all instances that match a given image ID. The average is over 60-second time intervals for a one-day period.

[Note]Note

Start and end times must be within the last 14 days.

In this scenario the EC2 instances are running an image ID of ami-c5e40dac.

AWS Management Console

To display the average CPU utilization for an image ID

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

  2. In the Navigation pane, click Metrics.

    The Metrics page opens.

    AWS Management Console viewing all Metrics
  3. Select EC2: Aggregated by Image (AMI) Id from the Viewing drop-down list.

    The metrics available for image IDs appear in the Metrics pane.

  4. Select a row that contains CPUUtilization and an image ID.

    A graph showing average CPUUtilization for all EC2 instances based on the ami-c5e40dac image ID appears in the Metrics pane.

    AWS Management Console metrics aggregated by AMI.

Command Line Tools

To get the average CPU utilization for an image ID

  • Enter the mon-get-stats command as in the following example.

    Prompt>mon-get-stats CPUUtilization --start-time 2011-01-10T00:00:00 --end-time 2011-01-11T00:00:00 --period 60 --statistics "Average" --namespace "AWS/EC2" --dimensions "ImageId=ami-c5e40dac" --headers

    Amazon CloudWatch returns the following:

    Time                  Average  Unit  
            2011-01-10 22:42:00   0.38     Percent
            2011-01-10 22:48:00   0.39     Percent
            2011-01-10 22:54:00   0.38     Percent
            2011-01-10 23:00:00   0.38     Percent
            2011-01-10 23:06:00   0.38     Percent
            2011-01-10 23:12:00   0.38     Percent

The operation returns statistics that are one-minute values for the one-day interval. Each value represents an average CPU utilization percentage for EC2 instances running the specified machine image.

Query API

To get the average CPU utilization for an image ID

  • Call GetMetricStatistics with the following parameters:

    • MetricName = CPUUtilization

    • Period = 60

    • Statistics list includes Average

    • Dimensions (Name= ImageId, Value= ami-c5e40dac)

    • Namespace = AWS/EC2

    • StartTime = 2011-01-10T00:00:00

    • EndTime = 2011-01-11T00:00:00

Getting Statistics for a Specific EC2 Instance

This scenario walks you through how to use the AWS Management Console, the mon-get-stats command, or the GetMetricStatistics API to determine the maximum CPU utilization of a specific EC2 instance.

[Note]Note

Start and end times must be within the last 14 days.

For this example, we assume that you have an EC2 instance ID. You can get an active EC2 instance ID through the AWS Management Console or with the EC2 ec2-describe-instances CLI command.

AWS Management Console

To display the average CPU utilization for a specific instance

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

  2. In the Navigation pane, click Metrics pane.

    The Metrics page opens.

    AWS Management Console Viewing all Metrics
  3. Select EC2: Instance Metrics from the Viewing drop-down box.

    The metrics available for individual instances appear in the Metrics pane.

  4. Select a row that contains CPUUtilization for a specific InstanceId.

    A graph showing average CPUUtilization for a single instance appears in the Metrics pane.

    AWS Management Console instance metrics.

Command Line Tools

To get the CPU utilization per EC2 instance

  • Enter the mon-get-stats command with the following parameters

    Prompt>mon-get-stats CPUUtilization --start-time 2011-01-09T23:18:00 --end-time 2011-01-12T23:18:00 --period 360 --namespace "AWS/EC2" --statistics "Maximum" --dimensions "InstanceId=<your-instance-id>" --headers

    Amazon CloudWatch returns the following (partial listing):

    Time                  Maximum  Unit
            2011-01-09 23:18:00   0.38     Percent
            2011-01-09 23:24:00   0.38     Percent
            2011-01-09 23:30:00   0.38     Percent
            2011-01-09 23:36:00   0.38     Percent
            2011-01-09 23:42:00   0.38     Percent
            2011-01-09 23:48:00   0.39     Percent 
            2011-01-09 23:54:00   0.38     Percent
            2011-01-10 00:00:00   0.38     Percent
            2011-01-10 00:06:00   0.38     Percent
            2011-01-10 00:12:00   0.38     Percent

    The returned statistics are six-minute values for the requested two-day time interval. Each value represents the maximum CPU utilization percentage for a single EC2 instance.

Query API

To get the CPU utilization per hour for an EC2 instance for a 3-day range

  • Call GetMetricStatistics with the following parameters:

    • MetricName = CPUUtilization

    • Period = 3600

    • Statistics list includes Maximum

    • Dimensions (Name=InstanceId, Value="<your-instance-id>")

    • Namespace = AWS/EC2

    • StartTime = 2011-01-09T23:18:00

    • EndTime = 2011-01-12T23:18:00