Amazon ECS

Amazon Elastic Container Service (Amazon ECS) is a fully managed container orchestration service that helps you easily deploy, manage, and scale containerized applications.

With the Infrastructure Agent (Infra Agent), you can effectively monitor your ECS containers and tasks running on ECS EC2 instances and ECS Fargate in your cloud, on-prem, and hybrid architectures.

Database Integrations and the Amazon ECS Anywhere approach are not currently supported.

Fargate Setup

Use the Middleware and AWS Fargate integration to monitor your applications without having to manage servers.

Create a Sidecar

For Each ECS Task that you want to monitor, add the following sidecar container in your task definition.

Collect Metrics

Adding the sidecar container mentioned above will automatically collect metrics data from your ECS tasks and containers. The Infra Agent uses the AWS ECS Task Metadata Endpoint to fetch metrics data.

Collect Logs

Forward your ECS Task logs to Middleware. The mw-agent sidecar, mentioned above, must be running before proceeeding.

Step 1: Add a Fluent sidecar in your ECS task

Step 2: Add a log Configuration in your main container

The Infra Agent sidecar will fetch these logs and send them to Middleware.

Parsing JSON Structured Logs [Optional]

Firelens by default sends a JSON blob which Middleware displays as the log body. Parsing the JSON logs allows the Message of the log being displayed while the attributes will be viewable on expansion.

To change the behavior you will need to add the below options to the firelensConfiguration created in Step 1.

The JSON structured logs generated need to have a Message field. Otherwise Middleware will not know what should be shown as a body of the log.

EC2 Setup

Step 1: Create & Configure a Infra Agent ECS Task Definition

Begin by creating a Task Definition for the Infra Agent container.

Step 2: Register Your Task Definition File

You can register your Task Definition File using the the AWS CLI or the Amazon Web Console.

AWS CLI
AWS Web UI

Execute the following command to register your Task Definition File in AWS. Learn more about the Amazon ECS CLI here.

Complete the following steps in the AWS Management Console to register your Task Definition File.

  1. Log in to your AWS Management Console and navigate to the Elastic Container Service (ECS) section
  2. In the left-hand menu, click on Task Definitions
  3. Create a new Task Definition under the JSON tab
  4. Copy and paste the configuration from your Task Definition file
  5. Save your Task Definition JSON file
  6. Click Create to register the Task Definition in AWS

Step 3: Schedule the Infra Agent as a Daemon Service

Set up the Infra Agent Task Definition as a Daemon Service to ensure only one Infra Agent container is running on each EC2 instance of the ECS cluster

  1. Log in to your AWS Management Console and navigate to the Elastic Container Service (ECS) section

  2. Choose the ECS cluster you will run the Infra Agent on

  3. Create a new service within the selected cluster

  4. Setup the Environment section

    a. Select Launch type under compute options

    b. Select EC2 as the Launch type

  5. Setup the Deployment Configureation section

    a. Select Service as the Application type

    b. Specify the Task Definition you created earlier under the Family section

    c. Provide a unique Service Name

    d. Choose DAEMON as the Service Type

  6. Proceed to create the service

Container Trace and Log Collection

Begin collecting container trace and log data in your EC2 instance. The Infra Agent will collect ECS container logs emitted to the stdout and stderr log stream and receive traces from your application and send to your Middleware account.

The Infra Agent must be running as an app before setting up collection. If not, attempted trace collection will throw an error while connecting to the agent and logs will not be sent at all.

Modify your Application Task Definition

You can setup container trace and log monitoring by modifying your Task Definition JSON file or following the below steps in the AWS Management Console.

JSON
AWS Management Console
  1. To collect traces, configure the environment variable in the Task Definition
  2. To collect logs, configure the logConfiguration variable to enable the fluentd logging driver

You do not need to collect container traces and log data at the same time.

  1. Navigate to the Amazon Elastic Container Service section in the AWS Management Console

  2. Click on Task Definition and select your desired Task Definition

  3. Create a new revision

Skip steps 4 or 5 if you do not want to enable container traces or logs

  1. Enable container traces in your application

    a. Under the Environment Variables section, select Add environment variable

    b. Add MW_AGENT_SERVICE environment variable and set the value to 172.17.0.1

  2. Enable container logging in your application

    a. Navigate to Logging

    b. Check Use logging collection

    c. Add Parameters as seen below

  3. Click Create to update your Task Definition

  4. Update the Services/Daemon definition to use the latest version of the Task Definition

Visualize Your Data

Quickly access your Amazon ECS data with Middleware’s default ECS dashboard. Navigate to the Dashboard Builder and select the AWS ECS Dashboard.

Your AWS ECS data comes from the awsecscontainermetricsreceiver whereas your container data comes from the dockerstatsreceiver.

Troubleshooting

Missing Integrations Menu

If you do not see the Integrations Menu in Middlware, that means your account has not been granted Installation permissions. Contact your system administrator to add the Installation permission to your user role in Settings.

Need assistance or want to learn more about Middleware? Contact our support team in Slack.