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?

preguntada hace 2 años2166 visualizaciones
3 Respuestas
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
respondido hace 2 años
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

respondido hace 2 años
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
respondido hace 7 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas