Inventory and CPU / memory utilization report

0

I have been fiddling around with trying to export information on a couple of topics, but I have not had a good experience with Cloudwatch or AWS inventory.

first, I want to export a list of my EC2 instances to an spreadsheet or cv by instance type

second, I want to be able to see the average and Max CPU and memory utilization across my fleet for the last 30 days. I want this data to be readable by each instance, not a aggregated graph with a bunch of lines. how can I get this data out to look at?

asked 2 years ago2109 views
3 Answers
3

You could create a comma separated file using the following command:

aws ec2 describe-instances --query "Reservations[*].Instances[*].{Instance:InstanceId,Type:InstanceType,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --region eu-central-1 | jq -r '.[] | map({Instance,Type,Name,Status}) | (first | keys_unsorted) as $keys | map([to_entries[] | .value]) as $rows | $keys,$rows[] | @csv'

Note that this is per region! This uses jq which can be installed using the instructions here: https://stedolan.github.io/jq/download/

For the statistics you can also use a command line:

aws cloudwatch get-metric-statistics --metric-name CPUUtilization --namespace AWS/EC2 --start-time 2021-11-19T08:00:00Z --end-time 2021-12-19T08:00:00Z --period 86400 --statistic Average --region eu-central-1

Note that this is per region! This is for the whole fleet in a region. You can get this per InstanceId/InstanceType/ImageId/AutoScalingGroupName but that would require multiple calls. Here I used one month of data to fetch and specified I only want one datapoint per day at 8:00 (period=86400)

Regards Jacco

profile picture
JaccoPK
answered 2 years ago
1

You can utilize AWS Resources Groups & Tag Editor to get list of EC2 instances and export them.

Resource Groups Screenshot

As far as exporting metrics to CSV, this can't be done without some scripting. Fortunately for you there is a readymade solution documented on AWS official website and available to give it a try. If you know python you might be able to tweak it to your requirements. Check out Publish Amazon CloudWatch metrics to a CSV file

answered 2 years ago
0

We can use the AWS Prescriptive guidance mentioned if it helps :- https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/publish-amazon-cloudwatch-metrics-to-a-csv-file.html

Things to note:- This is region, and account specific, we would need to fetch the csv individually at each account level ( not a pan-account solution) Alternatively, if the number of instances is small, we can also use the CloudWatch console (Export to CSV option)

Anshika
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions