Amazon Elastic Container Service with Agent v5
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel,
n'hésitez pas à nous contacter.
This documentation is to setup Amazon EC2 container Service with Datadog Agent 5
Setup
Installation
To monitor your ECS containers and tasks with Datadog, run the Agent as a container on every EC2 instance in your ECS cluster. As detailed below, there are a few setup steps:
- Add an ECS Task
- Create or Modify your IAM Policy
- Schedule the Datadog Agent as a Daemon Service
This documentation assume you already have a working EC2 Container Service cluster configured. If not, see Getting started with Amazon ECS.
Create an ECS task
This task launches the Datadog container. When you need to modify the configuration, update this Task Definition as described further down in this guide. If you’re using APM or Logs, set the appropriate flags in the Task Definition.
You may either configure the task using the AWS CLI tools or using the Amazon Web Console.
AWS CLI
- Download datadog-agent-ecs.json (datadog-agent-ecs1.json if you are using an original Amazon Linux AMI).
- Edit
datadog-agent-ecs.json
and set <YOUR_DATADOG_API_KEY>
with the Datadog API key for your account. - Execute the following command:
Amazon Elastic Container Service register-task-definition --cli-input-json file:<PATH_TO_JSON_DD_AGENT_ECS>.json
Web UI
- Log in to your AWS Console and navigate to the EC2 Container Service section.
- Click on the cluster you wish to add Datadog to.
- Click on Task Definitions on the left side and click the button Create new Task Definition.
- Enter a Task Definition Name, such as
dd-agent-task
. - Click on the Add volume link.
- For Name enter
docker_sock
. For Source Path, enter /var/run/docker.sock
. Click Add. - Add another volume with the name
proc
and source path of /proc/
. - Add another volume with the name
cgroup
and source path of /cgroup/
(Use /sys/fs/cgroup/
if you are using an original Amazon Linux AMI) - Click the large Add container button.
- For Container name enter
dd-agent
. - For Image enter
gcr.io/datadoghq/docker-dd-agent:latest
. - For Maximum memory enter
256
. Note: For high resource usage, you may need a higher memory limit. - Scroll down to the Advanced container configuration section and enter
10
in CPU units. - For Env Variables, add a Key of
API_KEY
and enter your Datadog API Key in the value. If you feel more comfortable storing secrets like this in s3, take a look at the ECS Configuration guide. - Add another Environment Variable for any tags you want to add using the key
TAGS
. - Scroll down to the Storage and Logging section.
- In Mount points select the docker_sock source volume and enter
/var/run/docker.sock
in the Container path. Leave the Read only checkbox un-checked. - Add another mount point for proc and enter
/host/proc/
in the Container path. Check the Read only checkbox. - Add a third mount point for cgroup and enter
/host/sys/fs/cgroup
in the Container path. Check the Read only checkbox.
Create or modify your IAM policy
- Add those permissions to your Datadog IAM policy in order to collect Amazon ECS metrics:
ecs:ListClusters
: List available clusters.ecs:ListContainerInstances
: List instances of a cluster.ecs:DescribeContainerInstances
: Describe instances to add metrics on resources and tasks running, adds cluster tag to ec2 instances.
For more information on ECS policies, see Identity and access management for Amazon ECS.
- Using the Identity and Access Management (IAM) console, create a new role called
dd-agent-ecs
. - Select Amazon EC2 Role for EC2 Container Service. On the next screen do not check any checkboxes and click Next Step.
- Click Create Role.
- Click on the newly created role.
- Expand the Inline Policies section. Click the link to create a new inline policy.
- Choose Custom Policy and press the button.
- For Policy Name enter
dd-agent-policy
. Copy the following text into the Policy Document:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:RegisterContainerInstance",
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Submit*",
"ecs:Poll",
"ecs:StartTask",
"ecs:StartTelemetrySession"
],
"Resource": ["*"]
}
]
}
- Click Create Policy
Run the Agent as a daemon service
Ideally you want the Datadog Agent to load on one container on each EC2 instance. The easiest way to achieve this is to run the Datadog Agent as a daemon service.
Schedule a daemon service in AWS with an ECS task
- Log in to the AWS console and navigate to the ECS Clusters section. Click into the cluster you want to run the Agent on.
- Create a new service by clicking the Create button under Services.
- For launch type, select EC2. Then select the Task Definition created before.
- For service type, select
DAEMON
, and enter a Service name. Click Next. - Since the Service runs once on each instance, you don’t need a load balancer. Select None. Click Next.
- Daemon services don’t need Auto Scaling, so click Next Step, and then Create Service.
If you’re not using APM or Logs, you are finished. Otherwise, point your application containers to the underlying IP address of the host they are running on to ship information.
Dynamic detection and monitoring of running services
Datadog’s Autodiscovery can be used in conjunction with ECS and Docker to automatically discover and monitor running tasks in your environment.