---
title: Monitor services running on Amazon ECS
source: https://docs.newrelic.com/docs/infrastructure/host-integrations/host-integrations-list/monitor-services-running-amazon-ecs
---

If you have services that run on Docker containers in Amazon ECS, and are [supported](#requirements), you can enable those integrations via our ECS integration. This reports data from your monitored services, from the host, and from the containers.

## Requirements [#requirements]

To monitor services running on ECS, you must meet these requirements:

-   A supported service running on ECS that meets our requirements. Supported services include:
    -   [Apache](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/apache-monitoring-integration)
    -   [Cassandra](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/cassandra-monitoring-integration)
    -   [Couchbase](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/couchbase-monitoring-integration)
    -   [Elasticsearch](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/elasticsearch-monitoring-integration)
    -   [HAProxy](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/haproxy-monitoring-integration)
    -   [HashiCorp Consul](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/hashicorp-consul-monitoring-integration)
    -   [JMX](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/jmx-monitoring-integration)
    -   [Kafka](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/kafka-monitoring-integration)
    -   [Memcached](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/memcached-monitoring-integration)
    -   [MongoDB](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mongodb-monitoring-integration)
    -   [MySQL](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration)
    -   [NGINX](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/nginx-monitoring-integration)
    -   [PostgreSQL](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/postgresql-monitoring-integration)
    -   [RabbitMQ](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/rabbitmq-monitoring-integration)
    -   [Redis](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/redis-monitoring-integration)
-   An [auto-scaling](https://aws.amazon.com/autoscaling) ECS cluster running Amazon Linux, CentOS, or RHEL that meets the [infrastructure agent compatibility and requirements](https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/getting-started/compatibility-requirements-new-relic-infrastructure).
-   ECS tasks must have [network mode](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#network_mode) set to `none` or `bridge` (`awsvpc` and `host` not supported).

Limitations:

-   For this install method, our RabbitMQ and Apache integrations do not report inventory data.
-   AWS Fargate is not supported.

## How to enable [#enable-overview]

Before explaining how to enable monitoring of services running in ECS, here's an overview of the process:

1.  [Enable Amazon EC2](#enable-ec2) to install our infrastructure agent on your ECS clusters.
2.  [Enable monitoring of services](#enable-services) using a service-specific configuration file.

## Step 1: Enable EC2 to install the infrastructure agent [#enable-ec2]

First, you must enable Amazon EC2 to install our infrastructure agent on ECS clusters. To do this, you'll first need to update your user data to install the infrastructure agent on launch.

Here are instructions for changing EC2 launch configuration (taken from [Amazon EC2 documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/change-launch-config.html)):

1.  Open the [Amazon EC2 console](https://console.aws.amazon.com/ec2).
2.  On the navigation pane, under **Auto scaling**, choose **Launch configurations**.
3.  On the next page, select the launch configuration you want to update.
4.  Right click and select **Copy launch configuration**.
5.  On the **Launch configuration details** tab, click **Edit details**.
6.  Replace user data with one of the following snippets:

    **For CentOS 6, RHEL 6, Amazon Linux 1**

    Replace the highlighted fields with relevant values:

    ````
    Content-Type: multipart/mixed; boundary="MIMEBOUNDARY"
    MIME-Version: 1.0

    --MIMEBOUNDARY
    Content-Disposition: attachment; filename="init.cfg"
    Content-Transfer-Encoding: 7bit
    Content-Type: text/cloud-config
    Mime-Version: 1.0

    yum_repos:
        newrelic-infra:
            baseurl: https://download.newrelic.com/infrastructure_agent/linux/yum/el/6/x86_64
            gpgkey: https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg
            gpgcheck: 1
            repo_gpgcheck: 1
            enabled: true
            name: New Relic Infrastructure
    write_files:
    -   content: |
            ---
            # New Relic config file
            license_key: <a href="/docs/accounts/install-new-relic/account-setup/license-key">YOUR_LICENSE_KEY</a>
        path: /etc/newrelic-infra.yml
    packages:
      - newrelic-infra
      - nri-*
    runcmd:
      - [ yum, install, newrelic-infra, -y ]
      - [ systemctl, daemon-reload ]
      - [ systemctl, enable, newrelic-infra.service ]
      - [ systemctl, start, --no-block, newrelic-infra.service ]

    --MIMEBOUNDARY
    Content-Transfer-Encoding: 7bit
    Content-Type: text/x-shellscript
    Mime-Version: 1.0

    #!/bin/bash

    # ECS config
    {
      echo "ECS_CLUSTER=YOUR_CLUSTER_NAME"
    } >> /etc/ecs/ecs.config

    start ecs

    echo "Done"
    --MIMEBOUNDARY--
    ```

    ````

    **CentOS 7, RHEL 7**

    Replace the highlighted fields with relevant values:

    ````
    Content-Type: multipart/mixed; boundary="MIMEBOUNDARY"
    MIME-Version: 1.0

    --MIMEBOUNDARY
    Content-Disposition: attachment; filename="init.cfg"
    Content-Transfer-Encoding: 7bit
    Content-Type: text/cloud-config
    Mime-Version: 1.0

    yum_repos:
        newrelic-infra:
            baseurl: https://download.newrelic.com/infrastructure_agent/linux/yum/el/7/x86_64
            gpgkey: https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg
            gpgcheck: 1
            repo_gpgcheck: 1
            enabled: true
            name: New Relic Infrastructure
    write_files:
    -   content: |
            ---
            # New Relic config file
            license_key: <a href="/docs/accounts/install-new-relic/account-setup/license-key">YOUR_LICENSE_KEY</a>
        path: /etc/newrelic-infra.yml
    packages:
      - newrelic-infra
      - nri-*
    runcmd:
      - [ yum, install, newrelic-infra, -y ]
      - [ systemctl, daemon-reload ]
      - [ systemctl, enable, newrelic-infra.service ]
      - [ systemctl, start, --no-block, newrelic-infra.service ]

    --MIMEBOUNDARY
    Content-Transfer-Encoding: 7bit
    Content-Type: text/x-shellscript
    Mime-Version: 1.0

    #!/bin/bash

    # ECS config
    {
      echo "ECS_CLUSTER=YOUR_ECS_CLUSTER_NAME"
    } >> /etc/ecs/ecs.config

    start ecs

    echo "Done"
    --MIMEBOUNDARY--
    ```

    ````

    **Amazon Linux 2**

    Replace the highlighted fields with relevant values:

    ````
    Content-Type: multipart/mixed; boundary="MIMEBOUNDARY"
    MIME-Version: 1.0

    --MIMEBOUNDARY
    Content-Disposition: attachment; filename="init.cfg"
    Content-Transfer-Encoding: 7bit
    Content-Type: text/cloud-config
    Mime-Version: 1.0

    yum_repos:
        newrelic-infra:
            baseurl: https://download.newrelic.com/infrastructure_agent/linux/yum/amazonlinux/2/x86_64
            gpgkey: https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg
            gpgcheck: 1
            repo_gpgcheck: 1
            enabled: true
            name: New Relic Infrastructure
    write_files:
    -   content: |
            ---
            # New Relic config file
            license_key: <a href="/docs/accounts/install-new-relic/account-setup/license-key">YOUR_LICENSE_KEY</a>
        path: /etc/newrelic-infra.yml
    packages:
      - newrelic-infra
      - nri-*
    runcmd:
      - [ yum, install, newrelic-infra, -y ]
      - [ systemctl, daemon-reload ]
      - [ systemctl, enable, newrelic-infra.service ]
      - [ systemctl, start, --no-block, newrelic-infra.service ]

    --MIMEBOUNDARY
    Content-Transfer-Encoding: 7bit
    Content-Type: text/x-shellscript
    Mime-Version: 1.0

    #!/bin/bash

    # ECS config
    {
      echo "ECS_CLUSTER=YOUR_ECS_CLUSTER_NAME"
    } >> /etc/ecs/ecs.config

    start ecs

    echo "Done"
    --MIMEBOUNDARY--
    ```

    ````
7.  Choose **Skip to review**.
8.  Choose **Create launch configuration**.

Next, update the auto scaling group:

1.  Open the [Amazon EC2 console](https://console.aws.amazon.com/ec2).
2.  On the navigation pane, under **Auto scaling**, choose **Auto scaling groups**.
3.  Select the auto scaling group you want to update.
4.  From the **Actions** menu, choose **Edit**.
5.  In the drop-down menu for **Launch configuration**, select the new launch configuration created.
6.  Click **Save**.

To test if the agent is automatically detecting instances, [terminate an EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html) in the auto scaling group: the replacement instance will now be launched with the new user data. After five minutes, you should see data from the new host on the [Hosts page](https://docs.newrelic.com/docs/infrastructure/infrastructure-ui-pages/hosts-new-view).

Next, move on to enabling the monitoring of services.

## Step 2: Enable monitoring of services [#enable-services]

Once you've [enabled EC2 to run the infrastructure agent](#enable-ec2), the agent starts monitoring the containers running on that host.

Next, we'll explain how to monitor services deployed on ECS. For example, you can monitor an ECS task containing an NGINX instance that sits in front of your application server.

Here's a brief overview of how you'd monitor a [supported service](#requirements) deployed on ECS:

1.  Create a YAML configuration file for the service you want to monitor. This will eventually be placed in the EC2 user data section via the AWS console. But before doing that, you can test that the config is working by placing that file in the infrastructure agent folder (`etc/newrelic-infra/integrations.d`) in EC2. That config file must use our [container auto-discovery](https://docs.newrelic.com/docs/integrations/host-integrations/installation/container-auto-discovery) format, which allows it to automatically find containers. The exact config options will depend on the specific [integration](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list).
2.  Check to see that data from the service is being reported to New Relic.
3.  If you are satisfied with the data you see, you can then use the EC2 console to add that configuration to the appropriate launch configuration, in the `write_files` section, and then update the auto scaling group.
4.  In the `runcmd` section, add the `yum` command to install the integration to the appropriate launch configuration.

Here's a detailed example of doing the above procedure for NGINX:

1.  Ensure you have SSH access to the server or access to [AWS Systems Manager Session Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html). Log in to the host running the infrastructure agent.
2.  Via the command line, change the directory to the integrations configuration folder:

    ```shell
    cd /etc/newrelic-infra/integrations.d
    ```
3.  Create a file called `nginx-config.yml` and add the following snippet:

    ```yml
    ---
    discovery:
      docker:
        match:
          image: /nginx/
    integrations:
      - name: nri-nginx
        env:
          STATUS_URL: http://${discovery.ip}:${discovery.port}/status
          REMOTE_MONITORING: true
          METRICS: 1
    ```

    This configuration causes the infrastructure agent to look for containers in ECS that contain `nginx`. Once a container matches, it then connects to the NGINX status page. For details on how the `discovery.ip` snippet works, see [auto-discovery](https://docs.newrelic.com/docs/integrations/host-integrations/installation/container-auto-discovery). For details on general NGINX configuration, see the [NGINX integration](https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/nginx-monitoring-integration#config).
4.  If your NGINX status page is set to serve requests from the `STATUS_URL` on port 80, the infrastructure agent starts monitoring it. After five minutes, verify that NGINX data is appearing in our infrastructure UI (either: **[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Infrastructure > Third party services**, or **[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Infrastructure > Third-party services**).
5.  If the configuration works, place it in the EC2 launch configuration:

    1.  Open the [Amazon EC2 console](https://console.aws.amazon.com/ec2).
    2.  On the navigation pane, under **Auto scaling**, choose **Launch configurations**.
    3.  On the next page, select the launch configuration you want to update.
    4.  Right click and select **Copy launch configuration**.
    5.  On the **Launch configuration details** tab, click **Edit details**.
    6.  In the **User data** section, edit the `write_files` section (in the part marked `text/cloud-config`).
    7.  Add a new file/content entry:

        ```yml
        -   content: |
            ---
            discovery:
              docker:
                match:
                  image: /nginx/
            integrations:
              - name: nri-nginx
                env:
                  STATUS_URL: http://${discovery.ip}:${discovery.port}/status
                  REMOTE_MONITORING: true
                  METRICS: 1
            path: /etc/newrelic-infra/integrations.d/nginx-config.yml
        ```
    8.  Also edit the `runcmd` section to include the `yum` command to install `nri-nginx`:

        ```yml
        runcmd:
          - [ yum, install, newrelic-infra, -y ]
          - [ yum, install, nri-nginx, -y ]
          - [ systemctl, daemon-reload ]
          - [ systemctl, enable, newrelic-infra.service ]
          - [ systemctl, start, --no-block, newrelic-infra.service ]
        ```
6.  Choose **Skip to review**.
7.  Choose **Create launch configuration**.
8.  Next, update the auto scaling group:
    1.  Open the [Amazon EC2 console](https://console.aws.amazon.com/ec2/).
    2.  On the navigation pane, under **Auto scaling**, choose **Auto scaling groups**.
    3.  Select the auto scaling group you want to update.
    4.  From the **Actions** menu, choose **Edit**.
    5.  In the drop down menu for **Launch configuration**, select the new launch configuration created.
    6.  Click **Save**.

When an EC2 instance is terminated, it's replaced with a new one that automatically looks for new NGINX containers.
