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.

asked 9 months ago150 views
1 Answer
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
EXPERT
answered 9 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