Amazon CloudWatch
Developer Guide (API Version 2010-08-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did 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

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

Getting Statistics for a Specific EC2 Instance

The following table describes the types of monitoring data available for your Amazon EC2 instances.

Monitoring TypeDescription

Basic

Data is available automatically in 5-minute periods at no charge.

Detailed

Data is available in 1-minute periods at an additional cost. To get this level of data, you must specifically enable it for the instance. For the instances where you've enabled detailed monitoring, you can also get aggregated data across groups of similar instances.

For information about pricing, go to the Amazon CloudWatch product page.

The following 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. For more information about monitoring EC2 instances, see Monitoring Your Instances with CloudWatch in the Amazon Elastic Compute Cloud User Guide.

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. If necessary, change the region. From the navigation bar, select the region that meets your needs. For more information, see Regions and Endpoints.

    region selector on the navigation bar
  3. In the navigation pane, click Metrics.

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

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

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

    A graph showing average CPUUtilization for a single instance appears in the lower 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

Getting Statistics Aggregated Across Instances

Aggregate statistics are available for the instances that have detailed monitoring enabled. Instances that use basic monitoring are not included in the aggregates. In addition, Amazon CloudWatch does not aggregate data across Regions. Therefore, metrics are completely separate between Regions. Before you can get statistics aggregated across instances, you must enable detailed monitoring (at an additional charge), which provides data in 1-minute periods. This scenario shows you how to use detailed monitoring with either the AWS Management Console, the GetMetricStatistics API, or the mon-get-stats command to get the average CPU usage for your EC2 instances. Because no dimension is specified, Amazon CloudWatch returns statistics for all dimensions in the AWS/EC2 namespace. To get statistics for other metrics, see Amazon CloudWatch Metrics, Namespaces, and Dimensions Reference.

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 your Amazon EC2 instances

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

  2. If necessary, change the region. From the navigation bar, select the region that meets your needs. For more information, see Regions and Endpoints.

    region selector on the navigation bar
  3. In the navigation pane, click Metrics.

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

    The metrics available across all instances appear.

  5. In the upper pane, select the row that contains CPUUtilization.

    A graph showing CPUUtilization for your EC2 instances is displayed in the lower pane.

    AWS Management Console metrics aggregated across your EC2 instances.

Command Line Tools

To get average CPU utilization across your 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 your Amazon 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

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. If necessary, change the region. From the navigation bar, select the region that meets your needs. For more information, see Regions and Endpoints.

    region selector on the navigation bar
  3. In the navigation pane, click Metrics.

    AWS Management Console viewing all metrics
  4. 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.

  5. 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

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. If necessary, change the region. From the navigation bar, select the region that meets your needs. For more information, see Regions and Endpoints.

    region selector on the navigation bar
  3. In the navigation pane, click Metrics.

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

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

  5. 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