How to Get Statistics on AWS EC2 Using Amazon CloudWatch
Amazon CloudWatch is used for basic monitoring of several AWS products. Previously, we saw how we can view various metrics of AWS CloudWatch. This guide shows how to get statistics for specific EC2 instances. This guide also shows how to get aggregated statistics across all instances for which detailed monitoring is enabled.
1. To access the AWS CloudWatch console go to AWS console and select the AWS CloudWatch service.
2. The AWS CloudWatch dashboard lists your present alarms as well as an overview of your AWS resources. Click “View Metrics”.
3. It displays a page which has the list of all CloudWatch metrics. In the “Viewing” dropdown menu, select “EC2:Instance Metrics”.
4. It will list all the metrics available for all the instances of that region. Scroll down to select the metric for a specific instance or select “CPU Utilization” for the marked instance.
[Newvem’s Amazon S3 Analytics offers additional value for Amazon S3 users by enabling amplified visibility into their current Amazon S3 footprint. Newvem helps users define and implement AWS storage policies so they can tier their storage needs with confidence. Learn more about Newvem analytics features]
5. It will list CPU Utilization data of the selected instance over the last 6 hours. Currently it shows the basic monitoring data at every 5 minutes.
6. If detailed monitoring is enabled for this instance, select “1 Minute” from the dropdown. It will list more detailed CPU Utilization statistics at every minute for this instance.
7. If you want to see the metrics for the last 12 hours, select 12h in “Time Range”. It will list records of the last 12 hours. The maximum range can be of 14 days.
8. To view multiple metrics of the same instance, select those metrics.
How to View AWS CloudWatch Aggregated Metrics Data for Multiple Instances
CloudWatch also provides APIs to get the aggregated data of multiple instances for which detailed monitoring is enabled. Instances that use basic monitoring are not included in the aggregates. The following steps show how to view aggregated metrics data for detailed monitoring enabled EC2 instances.
9. Select “EC2: Aggregated Across Instances” from the “Viewing” drop down menu.
10. It will list all the metrics available for Aggregated Statistics.
11. If you select “CPUUtilization”, It will list the aggregated metrics collected for all the detailed monitoring enabled instances.
12. You can change the average time or Time Range as explained in steps #6 and #7.
13. As explained above, you can also get statistics for “Aggregated across ELB” (Elastic Load Balancer), “Aggregated by AutoScaling Group” (if auto scaling is created), “Aggregated by AMI” by selecting specific metrics from the drop down menu.
14. If you want to get metrics statistics using the command line tool you will need to install the CLI tools for CloudWatch (Learn how).
15. Follow the steps and run the command below -
First set the Region for the CloudWatch:
Run the command:
mon-get-stats CPUUtilization --start-time 2021-12-08T03:04:00 --end-time 2021-12-08T09:04:00 --period 360 --namespace "AWS/EC2" --statistics "Maximum" --dimensions "InstanceId=i-0cab5d3e" --headers
The above command shows the metrics collected during the last 6 hours for the specified instance. This is the same as we showed in step#5 through AWS graphic user interface console.
16. To get the aggregated data as shown in step #11 run the following command.
mon-get-stats CPUUtilization --start-time 2021-12-08T03:04:00 --end-time 2021-12-08T09:04:00 --period 360 --namespace "AWS/EC2" --statistics "Average,SampleCount" –headers
It will output the below -
[Newvem analytics tracks you AWS cloud utilization:
- Hourly Utilization Pattern Analysis
- Reserved Instances Decision Tool
- Resource Resizing Opportunities
Keywords: Amazon web services, Amazon AWS console, Amazon AWS instances, EC2 Service, Amazon cloud computing, EC2 EBS, EC2 CPU Utilization, AWS Infrastructure Elasticity, Amazon EC2 capacity, Cloud Monitoring, CloudWatch, API, CLI tools, CloudWatch Alarm, Alerts, CLI tools, CloudWatch Dashboard, CloudWatch Metrics, CloudWatch Alarms, CPUUtilization