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?

질문됨 2년 전2166회 조회
3개 답변
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
답변함 2년 전
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

답변함 2년 전
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
답변함 7달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠