How can I obtain metrics from Amazon CloudWatch that show the aggregate Amazon Elastic Block Store (Amazon EBS) throughput of my Amazon Elastic Compute Cloud (Amazon EC2) instance? Also, how can I then set up an alarm that notifies me when the EC2 instance has reached the throughput limit? 

There is no native Amazon EBS metric that tracks the EBS throughput of a Xen-based Amazon EC2 instance in CloudWatch. However, you can use the EC2EBSThroughput/ebs-stats.sh script to measure the aggregate EBS throughput of your EC2 instance.

The script collects the total read/write bytes per second across all attached volumes, and pushes the throughput as a metric to Amazon CloudWatch. You can then view the metrics in the Amazon CloudWatch console and set an alarm that is triggered based on a threshold that you specify.

Note: The new Nitro instances, M5 and C5, include the CloudWatch metrics EBSIOBalance% and EBSByteBalance%. For more information, see Amazon EBS-Optimized Instances.

The ebs-stats.sh script is intended for Xen-based EC2 instances in CloudWatch, and is compatible only with Amazon Linux, Red Hat Enterprise Linux, and CentOS instances. However, the script can be customized for other Linux distributions.

Note: If your instance has an instance store volume, the script reports aggregate throughput, including the throughput of the instance store volume. This means that you might not get an accurate measurement of the EBS throughput from this script.

1.    For RHEL-based distributions, install the AWS Command Line Interface (AWS CLI), if you haven't already done so.

2.    Download the ebs-stats.sh script.

3.    Place the script on your instance, and then make it executable. You must run the script as a "root" user or "sudo" otherwise it will fail.

$sudo chmod +x ebs-stats.sh 

4.    From the AWS CLI, set the desired ebs-stats.sh runtime frequency by running the following command in the background:

$sudo nohup ./ebs-stats.sh example-sleep-interval &

Note: Replace example-sleep-interval with the desired number of seconds between each data point. 

5. Create an IAM role.

6. Attach the following policy to the role:

{
  "Version": "2012-10-17",
  "Statement": [{
    "Action": [
      "cloudwatch:ListMetrics",
      "cloudwatch:GetMetricStatistics",
      "cloudwatch:PutMetricData",
      "autoscaling:DescribeAutoScalingInstances"
    ],
    "Effect": "Allow",
    "Resource": "*"
  }]
}

7.    Attach the IAM policy to your EC2 instance. This enables the script to push the metrics to Amazon CloudWatch.

8.    From the CloudWatch console, set an alarm for EBSThroughoutMB. For more information, see Create a CloudWatch Alarm Based on a CloudWatch Metric or Using Amazon CloudWatch Alarms.

Be sure that you choose the correct period based on the argument that you used.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2019-03-29