Is there a cloudwatch metric to determine no. of graviton instances running in a AWS region?

0

I want to create a grafana dashboard showing no. of graviton instances running in each region. This doesn't need to real time, need it refreshed once a week. Probably looking for some instance level metric which is unique to graviton or a metric which has a instance type dimension, or some other way to get the information.

已提问 9 个月前161 查看次数
1 回答
0

I don't think there is going to be any pre-built metrics that can do this for you. Two ways that I can think of that might help here:

  1. This is probably simplest: Use Config - you can create a query to list all of the instances, then filter from there: https://docs.aws.amazon.com/config/latest/developerguide/example-query.html
  2. Create a Lambda function that scans all regions and collects the data that you need. Run the function periodically using EventBridge then store the results in an appropriate place. This is more complex but depending on what you're looking for may have greater flexibility. Example Python code below:
import boto3

ec2 = boto3.client('ec2')

regionList = ec2.describe_regions()['Regions']
for region in regionList:
    regionName = region['RegionName']
    ec2Region = boto3.client('ec2', region_name=regionName)

    ec2Iterator = ec2Region.get_paginator('describe_instances').paginate()
    for object in ec2Iterator:
        for instanceList in object['Reservations']:
            for instance in instanceList['Instances']:
                print(regionName, instance['InstanceType'])
profile pictureAWS
专家
已回答 9 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容