Skip to content
Datadog Agent Check : Obtain On-Demand and Reserved Instance count of AWS EC2
Python Makefile
Branch: master
Clone or download
isaoshimizu Merge pull request #7 from chaspy/chaspy/add-missing-instance-class
Add missing instance size and normalization factor
Latest commit 86bc059 Aug 26, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.config 不要な ignore を削除 Apr 26, 2017
tests Add test for missing instance size Aug 26, 2019
.gitignore add dummy tests Apr 14, 2017
.travis.yml make パラメータ変更 Apr 25, 2017
LICENSE Initial commit Mar 23, 2017
Makefile update status image urls May 30, 2017 update status image urls May 30, 2017
requirements-test.txt コーディング規約チェックのために flake8 を利用できるように Apr 25, 2017

Build Status


This is an Agent Check for Datadog for obtaining On-Demand and Reserved Instances count of AWS EC2. The custom metrics that can be obtained with this Agent Check are as follows.

  • Count of active EC2 On-Demand Instances and footprint
  • Count of active EC2 Reserved Instances and footprint
  • Count of unused EC2 Reserved Instances and footprint
  • Total count of active EC2 Instances and footprint

By using these custom metrics, you can refer to contracts of Reserved Instances or discover unused Reserved Instances.

This information can also be confirmed in the EC2 report of the AWS console, but by using this Agent Check it becomes possible to grasp in detail the usage situation in real time every minute.



The list of metrics acquired with this Agent Check is as follows.

Metrics Description
aws_ec2_count.ondemand.count Count of active EC2 On-Demand Instances
aws_ec2_count.ondemand.footprint Footprint of active EC2 On-Demand Instances
aws_ec2_count.reserved.count Count of active EC2 Reserved Instances
aws_ec2_count.reserved.footprint Footprint of active EC2 Reserved Instances
aws_ec2_count.reserved_unused.count Count of unused EC2 Reserved Instances
aws_ec2_count.reserved_unused.footprint Footprint of unused EC2 Reserved Instances
aws_ec2_count.running.count Total count of active EC2 Instances
aws_ec2_count.running.footprint All footprint of active EC2 Instances

Each metric has the following tags, from which you can determine its Availability Zone and Instance Type.

Tag Description
ac-az Availability Zone (or 'region' in the case of Reserved Instances in a region)
ac-family Instance Family
ac-type Instance Type


Prepare the following EC2 Instance.

  • Server on which Datadog Agent is installed
  • Grant ec2:DescribeInstances authority in IAM Role

Install this Agent Check on this server.

How to setup

This section describes how to install this Agent Check on Datadog Agent installed on CentOS. You may need to adjust depending on the installation environment.

1. Install AWS SDK

Install AWS SDK for Python. It's required for this Agent Check.

$ sudo /opt/datadog-agent/embedded/bin/pip install boto3

2. Install this Agent Check

Place ./checks.d/ from this repository into /etc/dd-agent/checks.d/.

$ sudo cp ./checks.d/ /etc/dd-agent/checks.d/

3. Place Agent Check configuration file

Create /etc/dd-agent/conf.d/aws_ec2_count.yaml by referring to ./conf.d/aws_ec2_count.yaml.example in this repository.

    min_collection_interval: 60

    - region: 'ap-northeast-1'
  • min_collection_interval specifies the request interval (in seconds)
  • region specifies the region to be acquired. Several regions can be speficied in instances as an array.

If the acquisition target is a Tokyo region (ap-northeast-1), you can use this aws_ec2_count.yaml.example as it is.

$ sudo cp conf.d/aws_ec2_count.yaml.example /etc/dd-agent/conf.d/aws_ec2_count.yaml

4. Restart Datadog Agent

Finally restart Datadog Agent.

$ sudo /etc/init.d/datadog-agent restart

Your custom metrics should now be sent to Datadog.


This Agent Check has the following restrictions.

  • The count of On-Demand Instances is calculated as the difference between the count of active instances and the count of valid Reserved Instances.
    • Because of that, it may not exactly match the invoiced amount.
    • In addition, due to changes in AWS specifications in the future, the applicable conditions of Reserved Instances may change.
    • Please use this Agent Check's data as a reference only. For exact data always refer to AWS.
  • Regional Reserved Instances are calculated with applied discounts under the following conditions.
    • Priority is given to the same Instance Type.
    • The surplus is applied to those of the same Instance Family, starting with the smallest Instance Size.
      • This makes it possible to minimize the count of On-Demand Instances.
  • There are times when it is not possible to correctly acquire the count of Reserved Instances depending on the timing Reserved Instances are changed.
  • Only the following instances are supported.
    • Platform is Linux/UNIX.
    • Tenancy is default.
    • Scheduled Reserved Instances are not supported.


This software is released under the MIT License, see LICENSE.

You can’t perform that action at this time.