Datadog Agent for AWS ECS Clusters for Metrics

The Datadog Agent for AWS ECS Clusters enables metric collection from containerized workloads running on ECS. It automatically gathers performance data including CPU, memory, disk, and network metrics at both the container and task level with minimal configuration required. This integration provides visibility into ECS-specific metrics such as task CPU usage and memory utilization.

Create an IAM Role for ECS Tasks

Create an IAM role for the ECS tasks, so they can send data to Kloudfuse and interact with AWS services.

You can use the following policy to allow Datadog Agent to collect metrics, logs, and traces.

Navigate to IAM in the AWS Console, and create a new Role with the following specifications:

Trusted entity

ECS (Elastic Container Service)

Policy

Custom, or use AWS-managed policies:

  • AmazonEC2ContainerServiceforEC2Role, for ECS task communication

  • CloudWatchFullAccess, for metrics

  • AWSXRayDaemonWriteAccess, for tracing

  • logs policy, for CloudWatch logs access

Install Datadog Agent on ECS

Datadog provides a Docker image that runs as an agent inside the ECS containers. To use this image, configure ECS Task Definitions.

  1. Create an ECS Task Definition with Datadog Agent.

    Modify your ECS service’s task definition to run the Datadog agent as a sidecar container.

    {
    "containerDefinitions": [
    {
        "name": "datadog-agent",
        "image": "public.ecr.aws/datadog/agent:latest",
        "cpu": 100,
        "memory": 512,
        "essential": true,
        "environment": [
            {
                "name": "DD_LOGS_ENABLED",
                "value": "true"
            },
            {
                "name": "DD_API_KEY",
                "value": "kloudfuse"
            },
            {
                "name": "DD_URL",
                "value": "https://<kf-domain-name>/ingester"
            },
            {
                "name": "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL",
                "value": "true"
            },
            {
                "name": "DD_LOGS_CONFIG_FORCE_USE_HTTP",
                "value": "true"
            },
            {
                "name": "DD_LOGS_CONFIG_LOGS_DD_URL",
                "value": "<kf-domain-name>:443"
            },
        ],
        "mountPoints": [
            {
                "sourceVolume": "docker_sock",
                "containerPath": "/var/run/docker.sock"
            },
            {
                "sourceVolume": "cgroup",
                "containerPath": "/host/sys/fs/cgroup"
            },
            {
                "sourceVolume": "proc",
                "containerPath": "/host/proc"
            },
            {
                "sourceVolume": "pointdir",
                "containerPath": "/opt/datadog-agent/run",
                "readOnly": false
            },
            {
                "sourceVolume": "containers_root",
                "containerPath": "/var/lib/docker/containers",
                "readOnly": true
            }
        ],
        "linuxParameters": {
            "initProcessEnabled": true
        },
    }
    ],
    "family": "datadog-agent-task",
    "taskRoleArn": "arn:aws:iam::<aws-account-id>:role/<custom-ecs-iam-role>",
    "executionRoleArn": "arn:aws:iam::<aws-account-id>:role/<custom-ecs-iam-role>",
    "placementConstraints": [],
    "compatibilities": [
    "EXTERNAL",
    "EC2"
    ],
    "tags": []
    }
    code

Collect Metrics

Metric collection includes data related to CPU, memory, disk, network, and other container performance metrics. Datadog automatically collects ECS-specific metrics, such as ECS task CPU usage, memory utilization.

The ECS Agent collects metrics with minimal configuration.