---
title: "Monitor ECS applications on AWS Fargate with Datadog"
description: "You can now monitor containerized applications running in AWS Fargate with Autodiscovery and high-resolution metrics."
author: "John Matson"
date: 2018-03-30
tags: ["serverless monitoring", "aws", "aws fargate", "amazon ecs", "aws ecs", "containers"]
blog_type_id: the-monitor
locale: en
---

[AWS Fargate](https://aws.amazon.com/fargate/) allows you to run applications in Amazon Elastic Container Service without having to manage the underlying infrastructure. With Fargate, you can define containerized tasks, specify the CPU and memory requirements, and launch your applications without spinning up EC2 instances or manually managing a cluster.

Datadog has proudly [supported Fargate since its launch](https://aws.amazon.com/blogs/compute/aws-fargate-a-product-overview/), and we have continued to collaborate with AWS on best practices for managing serverless container tasks. Datadog’s integration with AWS Fargate enables you to collect [real-time, high-resolution metrics](https://www.datadoghq.com/blog/introducing-live-container-monitoring.md) from all your containerized tasks. It also enables [Autodiscovery](https://docs.datadoghq.com/agent/autodiscovery.md) to detect containerized services running on Fargate and automatically configures Datadog Agent checks for those services.

The integration provides more than a dozen system metrics from Fargate that track the resource utilization (CPU, memory, I/O, etc.) of your tasks. And beginning with Fargate 1.4.0, Datadog increases your visibility by leveraging new Fargate network performance metrics. You can now see the rate of traffic to and from your containers, as well as network errors and dropped packets. You can also view code-level performance data with Datadog's [Continuous Profiler](https://docs.datadoghq.com/tracing/profiler.md), to analyze the resource usage of your AWS Fargate services' code. The Datadog integration brings all of this together so you can analyze and alert on the performance of your Fargate tasks and services alongside the rest of your infrastructure.

In this post, we’ll show a simple example of how you can deploy and monitor tasks on AWS Fargate with the Datadog Agent. Note that you will need version 6.1.1 or higher of the Datadog Agent to take full advantage of the Fargate integration.

#### Set up real-time monitoring for Amazon Fargate tasks in minutes with Datadog.
Try it free

## Deploy the Datadog Agent on AWS Fargate

To start monitoring AWS Fargate tasks and services, you can deploy the [containerized Datadog Agent](https://github.com/DataDog/datadog-agent/tree/master/Dockerfiles/agent) on Fargate. In addition to passing the usual `DD_API_KEY` environment variable, you must set the `ECS_FARGATE` environment variable to `true`.

The example task definition below deploys the Datadog Agent to Fargate, along with a Redis container in the same task.

```json
{
        "family": "redis-datadog",
        "networkMode": "awsvpc",
        "containerDefinitions": [
            {
                "name": "redis",
                "image": "redis:latest",
                "essential": true,
                "dockerLabels": {
                    "com.datadoghq.ad.instances": "[{\"host\": \"%%host%%\", \"port\": 6379}]",
                    "com.datadoghq.ad.check_names": "[\"redisdb\"]",
                    "com.datadoghq.ad.init_configs": "[{}]"
                }
            }, {
                "name": "datadog-agent",
                "image": "datadog/agent:latest",
                "essential": true,
                "environment": [
                    {
                        "name": "DD_API_KEY",
                        "value": "$YOUR_API_KEY"
                    },
                    {
                        "name": "ECS_FARGATE",
                        "value": "true"
                    }
                ]
           }
        ],
        "requiresCompatibilities": [
            "FARGATE"
        ],
        "cpu": "256",
        "memory": "512"
}
```

After saving that task definition locally as `redis-datadog.json`, you can register the task with ECS using [the AWS CLI](https://aws.amazon.com/cli/):

```bash
aws ecs register-task-definition --cli-input-json file://./redis-datadog.json
```

Once the task has been registered, you can run it in a Fargate cluster, making sure to provide one or more private subnets and security groups for your task. Note that Fargate version 1.4.0 or greater is required, so we specify the platform version in the command:

```bash
# create a cluster if you don’t already have one
aws ecs create-cluster --cluster-name "fargate-test"
 
aws ecs run-task --cluster fargate-test \
--network-configuration "awsvpcConfiguration={subnets=["$PRIVATE_SUBNET"],securityGroups=["$SECURITY_GROUP"]}" \
--task-definition arn:aws:ecs:us-east-1:$AWS_ACCOUNT_NUMBER:task-definition/redis-datadog:1 \
--region us-east-1 --launch-type FARGATE --platform-version 1.4.0
```

You can check the status of your task in [the ECS console](https://console.aws.amazon.com/ecs/home). In just a few moments, your task should be up and running, and your Fargate containers will appear on Datadog’s [Containers](https://app.datadoghq.com/containers) page, where you can search, filter, and view high-resolution system metrics from all the running containers in your infrastructure.

![Viewing high-resolution metrics from AWS Fargate containers in Datadog’s Live Container view.](https://web-assets.dd-static.net/42588/1776301353-monitor-aws-fargate-monitor-aws-fargate-container-view.png)

### Monitoring AWS Fargate containers with Autodiscovery

In the `dockerLabels` section of the task definition above, we applied three labels to the Redis container: this is [the metadata that the Datadog Agent needs](https://docs.datadoghq.com/agent/autodiscovery.md) to auto-detect Redis and start collecting metrics from it. The labels specify the name of the Datadog Agent check to apply (`redisdb`), an empty list of `init_configs`, and the host and port where Redis will run. Note that the `%%host%%` template variable will dynamically configure the Agent to collect metrics from the Redis container, wherever it is running, but the `%%port%%` template variable is not supported in ECS, so we manually provide the default Redis port, 6379.

With Autodiscovery properly configured, our newly deployed Datadog Agent starts collecting metrics from the Redis container automatically.

![Viewing Redis metrics from a container detected and monitored using Datadog Autodiscovery.](https://web-assets.dd-static.net/42588/1776301357-monitor-aws-fargate-monitor-aws-fargate-metrics.png)

## Send logs natively to Datadog

To centralize logging from your entire stack, Datadog also provides native support for [FireLens for Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html). You can now seamlessly route container logs from AWS Fargate to Datadog using [built-in Fluent Bit support](https://github.com/aws-samples/amazon-ecs-firelens-examples/tree/master/examples/fluent-bit/datadog). Read our [blog post](https://www.datadoghq.com/blog/collect-fargate-logs-with-firelens.md) about Fargate and FireLens for more information.

## Container monitoring, minus the host

AWS Fargate supports both ECS and EKS workloads, so you can focus on services and applications rather than hosts and underlying infrastructure. Just as with [AWS Lambda](https://www.datadoghq.com/blog/monitoring-lambda-functions-datadog.md), Datadog provides full visibility into the health and performance of all your applications, wherever they run. Datadog's Continuous Profiler also enables you to monitor the resource usage of application code running on AWS Fargate alongside the rest of your infrastructure. To learn more about how to set up profiling (available for Java, Python, and Go) see our [documentation](https://docs.datadoghq.com/getting_started/profiler.md).

See our [monitoring guide](https://www.datadoghq.com/blog/aws-fargate-metrics.md) and documentation for more information about monitoring [ECS](https://docs.datadoghq.com/integrations/ecs_fargate.md) on Fargate and [EKS](https://docs.datadoghq.com/integrations/eks_fargate.md) on Fargate with Datadog. And if you’re not yet using Datadog, you can sign up for a free trial <!-- Sign-up trigger (here) omitted -->.