- 最新
- 最多得票
- 最多評論
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
You can utilize AWS Resources Groups & Tag Editor to get list of EC2 instances and export them.
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
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)
相關內容
- 已提問 6 個月前
- AWS 官方已更新 2 年前