By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How can I get metrics from Amazon CloudWatch that show the EBS throughput of my EC2 instance, and then set up an alarm that notifies me when the EC2 instance reaches the throughput limit?

3 minute read
0

How can I get 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 reaches the throughput limit?

Short description

There isn't a 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 then pushes the throughput as a metric to Amazon CloudWatch. You can view those metrics in the Amazon CloudWatch console and set an alarm that triggers based on a threshold that you specify.

Note: The AWS Nitro-based EC2 instances built with Amazon EBS-optimized instance burst capability include the CloudWatch metrics EBSIOBalance% and EBSByteBalance%. These metrics are available for some instance sizes that burst to their maximum performance for 30 minutes at least once every 24 hours. For a complete list of applicable instance types, see Supported instance types.

The ebs-stats.sh script is for Xen-based EC2 instances in CloudWatch. The script is compatible only with Amazon Linux, Red Hat Enterprise Linux, and CentOS instances. However, you can customize the script 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.

Resolution

Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.

1.    For RHEL-based distributions, install the 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 fails.

$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 AWS Identity and Access Management (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 allows 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 static threshold or Using Amazon CloudWatch alarms.

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


Related information

Monitoring your instances using CloudWatch

List the available CloudWatch metrics for your instances

Amazon EBS-optimized instances

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago