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.
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.
Install AWS SDK for Python. It's required for this Agent Check.
$ sudo /opt/datadog-agent/embedded/bin/pip install boto3
Place ./checks.d/aws_ec2_count.py
from this repository into /etc/dd-agent/checks.d/
.
$ sudo cp ./checks.d/aws_ec2_count.py /etc/dd-agent/checks.d/
Create /etc/dd-agent/conf.d/aws_ec2_count.yaml
by referring to ./conf.d/aws_ec2_count.yaml.example
in this repository.
init_config:
min_collection_interval: 60
instances:
- 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 ininstances
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
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.
- Platform is
This software is released under the MIT License, see LICENSE.