Amazon Elastic Beanstalk

Overview

AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.

Setup

Installation

If you haven’t already, set up the Amazon Web Services integration first. To receive Elastic Beanstalk metrics, you must enable the Enhanced Health Reporting feature for your environment, and configure your environment to publish enhanced health metrics to CloudWatch.

Note: These settings increase your CloudWatch custom metric charges.

The following steps deploy the Datadog Agent on your Elastic Beanstalk VMs, so they report host metrics in addition to the metrics crawled by the AWS integration.

Configuration

Select your installation method to configure your Elastic Beanstalk environment:

For a single Docker container setup, install the Datadog Agent in Elastic Beanstalk using Advanced Environment Customization with Configuration Files (.ebextensions).

Note: This setup requires your API key to be placed in the .ebextensions directory, which is part of the source code. Use AWS Secret Manager or other secret management tooling to protect your API key.

  1. Create a folder named .ebextensions in the root of your application source bundle.
  2. Download 99datadog.config and put it in the .ebextensions folder.
  3. Change the value of api_key within the file template for /etc/datadog-agent/datadog.yaml with your Datadog API Key.
  4. Change the value of site in /etc/datadog-agent/datadog.yaml to your Datadog region (for example: ) to ensure the Agent sends data to the right Datadog location.
  5. Pin a specific Agent version by setting DD_AGENT_VERSION under option_settings to ensure that all hosts run the same version of the Agent.
  6. Deploy your application with the Elastic Beanstalk Console, EB CLI, or AWS CLI.

You can add additional Agent settings to /etc/datadog-agent/datadog.yaml.

For example, to enable Live Process Monitoring:

process_config:
  enabled: "true"

Trace collection

To enable tracing for single Docker containers:

  1. Update the /etc/datadog-agent/datadog.yaml section in the 99datadog.config file with apm_non_local_traffic, formatted like this:

    apm_config:
      enabled: "true"
      apm_non_local_traffic: "true"
    
  2. Set up the tracing libraries to direct traces to the Gateway IP of the bridge network, which defaults to 172.17.0.1 from inside the application container. (If you’re not sure this is the Gateway IP, run docker inspect <container id> to confirm.)

For all languages, set the environment variable DD_AGENT_HOST to the Gateway IP. Alternatively, for the languages below, set the host name programmatically using:

Python
from ddtrace import tracer

tracer.configure(hostname="172.17.0.1")
Node.js
const tracer = require('dd-trace');

tracer.init({ hostname: "172.17.0.1" });
Ruby
require 'ddtrace'

Datadog.configure do |c|
  c.tracer hostname: "172.17.0.1")
end
Go
package main

import (
    "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
  tracer.Start(tracer.WithAgentAddr("172.17.0.1"))
  defer tracer.Stop()
  
  // ...
}

For multiple Docker containers, use the containerized Datadog Agent to monitor Docker usage with a file named Dockerrun.aws.json.

A Dockerrun.aws.json file is an Elastic Beanstalk—specific JSON file that describes how to deploy a set of Docker containers as an Elastic Beanstalk application. You can use this file for a multicontainer Docker environment. Dockerrun.aws.json describes the containers to deploy to each container instance in the environment and the data volumes to create on the host instance for the containers to mount.

A Dockerrun.aws.json file can be used on its own or zipped up with additional source code in a single archive. Source code that is archived with Dockerrun.aws.json is deployed to container instances and accessible in the /var/app/current/ directory. Use the volumes section of the config to provide mount points for the containers running on the instance and the mountPoints section of the embedded container definitions to mount them from the containers.

The following code sample illustrates a Dockerrun.aws.json declaring the Datadog Agent. Update the containerDefinitions section with your Datadog API Key, tags (optional), and any additional container definitions. If needed, this file can be zipped with additional content as described above. For more info about the syntax of this file, see Multicontainer Docker configuration.

Notes:

  • For high resource usage, you may need a higher memory limit.
  • To ensure all hosts run the same Agent version, it is recommended to change agent:7 to a specific minor version of the Docker image.

  • Set DD_SITE to to ensure the Agent sends data to the right Datadog location.

{
    "AWSEBDockerrunVersion": 2,
    "volumes": [
        {
            "name": "docker_sock",
            "host": {
                "sourcePath": "/var/run/docker.sock"
            }
        },
        {
            "name": "proc",
            "host": {
                "sourcePath": "/proc/"
            }
        },
        {
            "name": "cgroup",
            "host": {
                "sourcePath": "/cgroup/"
            }
        }
    ],
    "containerDefinitions": [
        {
            "name": "dd-agent",
            "image": "gcr.io/datadoghq/agent:7",
            "environment": [
                {
                    "name": "DD_API_KEY",
                    "value": "<YOUR_DD_API_KEY>"
                },
                {
                    "name": "DD_SITE",
                    "value": "<YOUR_DD_SITE>"
                },
                {
                    "name": "DD_TAGS",
                    "value": "<SIMPLE_TAG>, <KEY:VALUE_TAG>"
                }
            ],
            "memory": 256,
            "mountPoints": [
                {
                    "sourceVolume": "docker_sock",
                    "containerPath": "/var/run/docker.sock",
                    "readOnly": false
                },
                {
                    "sourceVolume": "proc",
                    "containerPath": "/host/proc",
                    "readOnly": true
                },
                {
                    "sourceVolume": "cgroup",
                    "containerPath": "/host/sys/fs/cgroup",
                    "readOnly": true
                }
            ]
        }
    ]
}

Creating the environment

Once the container definition is ready, ship it to Elastic Beanstalk. For specific instructions, see Multicontainer Docker Environments in the AWS Elastic Beanstalk documentation.

DogStatsD

To collect custom metrics from your application container using DogStatsD in the Multicontainer Docker Environment, add the following to your Dockerrun.aws.json:

  1. Add the environment variable DD_DOGSTATSD_NON_LOCAL_TRAFFIC under the dd-agent container:

    {
      "name": "DD_DOGSTATSD_NON_LOCAL_TRAFFIC",
      "value": "true"
    }
    
  2. Add a link to the dd-agent container under your application container:

    "links": [ "dd-agent:dd-agent"]
    

See DogStatsD and Docker for additional information.

For a no container setup, install the Datadog Agent in Elastic Beanstalk using Advanced Environment Customization with Configuration Files (.ebextensions):

  1. Create a folder named .ebextensions in the root of your application source bundle.
  2. Download 99datadog.config and put it in the .ebextensions folder.
  3. Change the value of api_key within the file template for /etc/datadog-agent/datadog.yaml with your Datadog API Key.
  4. Change the value of site in /etc/datadog-agent/datadog.yaml to your Datadog region (for example: ) to ensure the Agent sends data to the right Datadog location.
  5. Pin a specific Agent version by setting DD_AGENT_VERSION under option_settings to ensure that all hosts run the same version of the Agent.
  6. Deploy your application with the Elastic Beanstalk Console, EB CLI, or AWS CLI.

You can add additional Agent settings to /etc/datadog-agent/datadog.yaml.

For example, to enable Live Process Monitoring:

process_config:
  enabled: "true"

Trace collection

When the application isn’t containerized and the Datadog Agent is configured with 99datadog.config, tracing is enabled without any additional configuration, provided the application is instrumented with the tracing library setup.

For a no container setup, install the Datadog Agent in Elastic Beanstalk using Advanced Environment Customization with Configuration Files (.ebextensions):

  1. Create a folder named .ebextensions in the root of your application source bundle.
  2. Download 99datadog-windows.config and move it to the .ebextensions folder.
  3. In 99datadog-windows.config, replace the APIKEY value with your Datadog API Key.
  4. (Optional) The 99datadog-windows.config file adds the .NET APM Tracing Library to generate traces. If you don’t want to enable APM in your environment, remove the packages section, the 02_setup-APM1 section, and the 03_setup-APM2 section.
  5. (Optional) If you need to add environment variables, set them in the 00_setup-env1 section of 99datadog-windows.config. You can remove this section if you do not need to set environment variables.
  6. Deploy your application with the Elastic Beanstalk Console, EB CLI, or AWS CLI.

Trace collection

When the application isn’t containerized and the Datadog Agent is configured with 99datadog-windows.config, tracing is enabled without any additional configuration. For more information on instrumenting tracing, see Set up Datadog APM.

Multiple Docker containers

  1. In the same Dockerrun.aws.json as the application, add a Datadog Agent container using the datadog/agent image. Add the following:
    • Under the portMappings section, add a hostPort 8126 with containerPort 8126.
    • Under the environment section, setDD_APM_ENABLED and DD_APM_NON_LOCAL_TRAFFIC to true.
  2. Under your application container, which was instrumented with the [tracing library setup][14], add the following:
    • Under the environment section, add an environment variable called DD_AGENT_HOST to the name of the Datadog Agent container.
    • Under the links section, set the Agent container to be used as an environment variable.

An example can be seen below:

 "containerDefinitions": [    {
      "name": "dd-agent",
      "image": "datadog/agent:latest",
      "environment": [
          {
              "name": "DD_API_KEY",
              "value": "<api key>"
          },
          {
              "name": "DD_APM_ENABLED",
              "value": "true"
          },
          {
             "name": "DD_APM_NON_LOCAL_TRAFFIC",
             "value": "true"
          },
         # any other environment variables needed 
      ],
      "portMappings": [
        {
          "hostPort": 8126,
          "containerPort": 8126
        }
      ],
      "memory": 256,
      "mountPoints": [
          # any mountpoints needed
         }
      ]
    },
    {
      "name": "application-container",
      "image": "<application image name>",
      "environment": [
        {
          "name": "DD_AGENT_HOST",
          "value": "dd-agent",
          # any other environment variables needed
        }
      ],
      "links": [
        "dd-agent:dd-agent"
      ],

Data Collected

Metrics

aws.elasticbeanstalk.application_latency_p_1_0
(gauge)
The average time to complete the fastest 10 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_5_0
(gauge)
The average time to complete the fastest 50 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_7_5
(gauge)
The average time to complete the fastest 75 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_8_5
(gauge)
The average time to complete the fastest 85 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_9_0
(gauge)
The average time to complete the fastest 90 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_9_5
(gauge)
The average time to complete the fastest 95 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_9_9
(gauge)
The average time to complete the fastest 99 percent of requests.
Shown as second
aws.elasticbeanstalk.application_latency_p_9_9_9
(gauge)
The average time to complete the fastest 99.9 percent of requests.
Shown as second
aws.elasticbeanstalk.application_requests_2xx
(count)
The number of requests that completed with a 2XX status code.
Shown as request
aws.elasticbeanstalk.application_requests_3xx
(count)
The number of requests that completed with a 3XX status code.
Shown as request
aws.elasticbeanstalk.application_requests_4xx
(count)
The number of requests that completed with a 4XX status code.
Shown as request
aws.elasticbeanstalk.application_requests_5xx
(count)
The number of requests that completed with a 5XX status code.
Shown as request
aws.elasticbeanstalk.application_requests_total
(count)
The number of requests completed by the instance or environment.
Shown as request
aws.elasticbeanstalk.cpuidle
(gauge)
[Instance] The percentage of time the CPU was in the idle state in the last minute.
Shown as percent
aws.elasticbeanstalk.cpuiowait
(gauge)
[Instance] The percentage of time the CPU was in the iowait state in the last minute.
Shown as percent
aws.elasticbeanstalk.cpuirq
(gauge)
[Instance] The percentage of time the CPU was in the interrupt request state in the last minute.
Shown as percent
aws.elasticbeanstalk.cpunice
(gauge)
[Instance] The percentage of time the CPU was in the nice state in the last minute.
Shown as percent
aws.elasticbeanstalk.cpusoftirq
(gauge)
[Instance] The percentage of time the CPU was in the soft interrupt request state in the last minute.
Shown as percent
aws.elasticbeanstalk.cpusystem
(gauge)
[Instance] The percentage of time the CPU was in the system state in the last minute.
Shown as percent
aws.elasticbeanstalk.cpuuser
(gauge)
[Instance] The percentage of time the CPU was in the user state in the last minute.
Shown as percent
aws.elasticbeanstalk.environment_health
(gauge)
[Environment] The health status of the environment. The possible values are 0 (OK) 1 (Info) 5 (Unknown) 10 (No data) 15 (Warning) 20 (Degraded) and 25 (Severe).
aws.elasticbeanstalk.instance_health
(gauge)
[Instance] The health status of the instance.
Shown as instance
aws.elasticbeanstalk.instances_degraded
(count)
[Environment] The number of instances with Degraded health status.
Shown as instance
aws.elasticbeanstalk.instances_info
(count)
[Environment] The number of instances with Info health status.
Shown as instance
aws.elasticbeanstalk.instances_no_data
(count)
[Environment] The number of instances with no health status data.
Shown as instance
aws.elasticbeanstalk.instances_ok
(count)
[Environment] The number of instances with OK health status.
Shown as instance
aws.elasticbeanstalk.instances_pending
(count)
[Environment] The number of instances with Pending health status.
Shown as instance
aws.elasticbeanstalk.instances_severe
(count)
[Environment] The number of instances with Severe health status.
Shown as instance
aws.elasticbeanstalk.instances_unknown
(count)
[Environment] The number of instances with Unknown health status.
Shown as instance
aws.elasticbeanstalk.instances_warning
(count)
[Environment] The number of instances with Warning health status.
Shown as instance
aws.elasticbeanstalk.load_average_1min
(gauge)
[Instance] The average CPU load over the last minute.
aws.elasticbeanstalk.load_average_5min
(gauge)
[Instance] The average CPU load over the last five minutes.
aws.elasticbeanstalk.root_filesystem_util
(gauge)
[Instance] The percentage of disk space in use.
Shown as percent

Each of the metrics retrieved from AWS are assigned the same tags that appear in the AWS console, including but not limited to host name, security-groups, and more.

Events

The AWS Elastic Beanstalk integration does not include any events.

Service Checks

The AWS Elastic Beanstalk integration does not include any service checks.

Troubleshooting

Need help? Contact Datadog support.

Further Reading

Additional helpful documentation, links, and articles: