Bobcares

Collect logs from ECS container instance automatically

by | Aug 31, 2021

To collect logs from the ECS container instance automatically, we can use the Amazon ECS logs collector script.

Here, at Bobcares, we assist our customers with several AWS queries as part of our AWS Support Services.

Today, let us discuss how we can do this.

 

Collect logs from ECS container instance automatically

With Amazon ECS logs collector we can collect general OS logs as well as Docker and Amazon ECS container agent logs.

Generally, it supports the following operating systems:

  • Amazon Linux
  • Red Hat Enterprise Linux 7
  • Debian 8
  • Ubuntu 14.04
  • Windows 2016

 

How to Collect Logs automatically?

Moving ahead, let us see how our Support Techs perform this query for our customers.

 

  • Download and run the Amazon ECS logs collector for Linux

1. Initially, we connect to the container instance.

2. In order to confirm the installation of curl, we run:

curl --version
curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3

We need to install the curl package if the command doesn’t return the results.

3. Eventually, we download the Amazon ECS logs collector script:

curl -O https://raw.githubusercontent.com/awslabs/ecs-logs-collector/master/ecs-logs-collector.sh

4. Then to collect the logs and create an archive with the script, we run:

[ec2-user ~]$ sudo bash ./ecs-logs-collector.sh

Once we run the script, we can examine the logs in the collect folder. In the folder, we’ll find the collect.tgz file, a compressed archive of all the logs.

 

  • Download and run the Amazon ECS logs collector for Windows

1. First, we connect to the container instance.

2. To download the script, we open Windows PowerShell with administrator privileges, and run:

Invoke-WebRequest -OutFile ecs-logs-collector.ps1 https://raw.githubusercontent.com/awslabs/aws-ecs-logs-collector-for-windows/master/ecs-logs-collector.ps1

3. In the same window, to collect the logs and create the archive, we run:

.\ecs-logs-collector.ps1

Once we run the script, we can examine the logs in the collect folder. The script creates this folder.

 

  • Run the Amazon ECS logs collector in debug mode for Windows

Assume, the logs don’t provide all the information that we need. In that case, we can enable debug logging for the Docker daemon and Amazon ECS container agent with the -RunMode debugs option.

This will allow the script to collect the logs before enabling debug mode.

The script restarts the Docker daemon and Amazon ECS agent and then terminates all containers running on the instance.

However, before we proceed we need to drain the container instance and move any important tasks to other container instances.

To enable debug mode, run the following command using Windows PowerShell with administrator privileges:

.\ecs-logs-collector.ps1 -RunMode debug

[Need help with the log collection? We’d be happy to assist you]

 

Conclusion

In short, we saw how our Support Techs go about automatically collecting logs from ECS container instances.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.