1

I am currently running the following query

aws ec2 describe-reserved-instances    \
  --filters "Name=state,Values=active" \
  --query "ReservedInstances[].{InstanceType:InstanceType,ProductDescription:ProductDescription,InstanceCount:InstanceCount}"

In order to obtain something resembling the following:

{
    "ProductDescription": "Linux/UNIX (Amazon VPC)",
    "InstanceType": "m3.medium",
    "InstanceCount": 44
}

I am looking to get the instances already utilized though as well and am not finding a sane way to do this I would like a report showing the following information.

{
    "ProductDescription": "Linux/UNIX (Amazon VPC)",
    "InstanceType": "m3.medium",
    "InstanceCount": 44,
    "InstancesUsed": 44,
    "UtilizationPercentage": "100%"
}

How would I end up with instances used along with utilization percentage?

NOTE

In order to get percentage I can variable cast, then use the following...

Percentage() { echo "$((200*$1/$2 % 2 + 100*$1/$2))%" ; }

Percentage 44 44 //100%
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
ehime
  • 8,025
  • 14
  • 51
  • 110

1 Answers1

2

Well, AWS doesn't work like this. Reserved instances are not "utilized" or "not utilized" on EC2 level. The magic happens in billing. When Amazon bills you, it will match instances that were running against instances that were reserved. That means that you can't get that information with aws ec2. The only thing you can do is to try to calculate which running instances are covered by reserved instances by yourself.

Sergey Kovalev
  • 9,110
  • 2
  • 28
  • 32
  • Per our AWS TAMs and leveraged AWS SDE's this is incorrect, as they are currently generating the same thing but using the ECB (private backend api) to get to the numbers. There is also a console based utilization report that can be ran, http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/usage-reports-ri.html#usage-reports-ri-options – ehime Dec 19 '16 at 19:25
  • Exactly my point. EC2 itself doesn't know about RI utilization. So `aws ec2` can't give you a direct answer. Another API, or third party tool or your custom code can. – Sergey Kovalev Dec 19 '16 at 19:28
  • I'm aware `describe-instances` as well as `describe-reserved-instances` do not provide this inherently, hence the question ;) using something like `JQ` you can run combined queries etc to be able to get something I'm hoping – ehime Dec 19 '16 at 19:30
  • After digging around I think a comparison is honestly the best i can accomplish. Accepting and plus one, Thanks Sergey – ehime Dec 19 '16 at 20:05