aws-samples / amazon-cloudwatch-container-insights

CloudWatch Agent Dockerfile and K8s YAML templates for CloudWatch Container Insights.
MIT No Attribution
162 stars 106 forks source link

Enhance ECS Container Insights by enabling host logs to be sent to CloudWatch #177

Open jenademoodley opened 3 weeks ago

jenademoodley commented 3 weeks ago

Description of the issue

In a container environment, it is important to monitor the host for any host-level issues and/or impacting behaviour. While Container Insights allows the collection of host-level metrics using the CloudWatch agent in daemon mode, logs from the host such as Docker daemon and ECS agent logs. However, instances may sometimes be terminated, or not be configured to allow access, hence it would be impossible in these cases to access the logs and triage the issue. There is a need for an automated log collection for ECS Container Insights.

Description of changes

This pull request introduces the capability to deploy fluent-bit as an additional daemonset to collect the logs from the host and populate them in CloudWatch in the /aws/ecs/containerinsights/${CLUSTER_NAME}/instance-logs log group. The below logs are collected:

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

This PR does not modify the existing CloudWatch agent CFN stack and configurations, hence existing users using these stacks would experience no changes. Fluent-bit is provided as an additional configuration and CFN stack (for existing Container Insights users wanting to upgrade, or for those who simply want to deploy only one option), and there is a third stack which can deploy both CloudWatch agent and Fluent-Bit in a single stack (for new users).

The solution is confirmed to work on the below Operating Systems:

  1. Amazon Linux 2
  2. Amazon Linux 2023
  3. Ubuntu 20.04
  4. Ubuntu 22.04
  5. Ubuntu 24.04
  6. Red Hat Enterprise Linux (RHEL) 8
  7. Red Hat Enterprise Linux (RHEL) 9
  8. CentOS Stream 9

Requirements

Before committing the code, please verify the following: