ECS 메타데이터 (ECS metadata)
ECS Filter는 AWS Elastic Container Service 메타데이터로 로그를 풍부하게 만들어 줘요. 이 플러그인은 태스크(task), 클러스터(cluster), 컨테이너(container) 메타데이터로 로그를 보강할 수 있어요.
출처: 문서
본문
지원 이벤트 유형:
logs
ECS Filter는 AWS Elastic Container Service 메타데이터를 로그에 추가해줘요. 이 플러그인은 태스크, 클러스터, 컨테이너 메타데이터로 로그를 보강할 수 있어요. 플러그인은 ECS Agent introspection API를 사용해서 메타데이터를 얻어와요. 이 필터는 ECS EC2 실행 유형(launch type)에서만 동작해요. 또 Fluent Bit가 ECS EC2 컨테이너 인스턴스에서 실행 중이고 ECS Agent introspection API에 접근할 수 있을 때만 동작해요.
이 필터는 ECS Fargate에서는 지원되지 않아요. ECS Fargate에서 메타데이터를 얻으려면 내장 FireLens 메타데이터나 AWS for Fluent Bit init 프로젝트를 사용하세요.
Configuration parameters (설정 매개변수)
이 플러그인은 다음 설정 매개변수를 지원해요:
| Key | Description | Default |
|---|---|---|
add |
Similar to the add option in the modify filter. You can specify it multiple times. It takes two arguments: a KEY name and VALUE. The value uses Fluent Bit record_accessor syntax to create a template that uses ECS Metadata values. See the list of supported metadata templating keys. This option lets you control both the key names for metadata and the format for metadata values. |
none |
agent_endpoint_retries |
Number of retries for failed metadata requests to the ECS Agent Introspection endpoint. The most common cause of failed metadata requests is that the container the metadata request was made for isn't part of an ECS Task. | 2 |
cluster_metadata_only |
When enabled, the plugin only attempts to attach cluster metadata values. Use to attach cluster metadata to system or OS logs from processes that don't run as part of containers or ECS Tasks. | false |
ecs_meta_cache_ttl |
The filter builds a hash table in memory mapping each unique container short ID to its metadata. This option sets a max TTL for objects in the hash table. Set this if you have frequent container or task restarts. For example, if your cluster runs short-running batch jobs that complete in less than 10 minutes, set this parameter to 10m. |
1h |
ecs_meta_host |
The host name at which the ECS Agent Introspection endpoint is reachable. | 127.0.0.1 |
ecs_meta_port |
The port at which the ECS Agent Introspection endpoint is reachable. | 51678 |
ecs_tag_prefix |
Similar to the kube_tag_prefix option in the Kubernetes filter and performs the same function. The full log tag should be prefixed with this string and after the prefix the filter must find the next characters in the tag to be the Docker Container Short ID (the first 12 characters of the full container ID). The filter uses this to identify which container the log came from so it can find which task it's a part of. If not specified, defaults to empty string, meaning that the tag must be prefixed with the 12-character container short ID. If you want to attach cluster metadata to system or OS logs from processes that don't run as part of containers or ECS Tasks, don't set this parameter and enable cluster_metadata_only. |
"" |
Supported templating variables for the add option (add 옵션용 지원 템플릿 변수)
add 옵션의 값에 사용할 수 있는 템플릿 변수는 다음과 같아요. 예시는 뒤따르는 튜토리얼 섹션을 참고하세요.
| Variable | Description | Supported with cluster_metadata_only on |
|---|---|---|
$ClusterName |
The ECS cluster name. Fluent Bit is running on EC2 instances that are part of this cluster. | Yes |
$ContainerID |
The ID of the container from which the log originated. This is the full 64-character-long container ID. | No |
$ContainerInstanceArn |
The full ARN of the ECS EC2 Container Instance. This is the instance that Fluent Bit is running on. | Yes |
$ContainerInstanceID |
The ID of the ECS EC2 Container Instance. | Yes |
$DockerContainerName |
The name of the container from which the log originated. This is the name obtained from Docker and is the name shown if you run docker ps on the instance. |
No |
$ECSAgentVersion |
The version string of the ECS Agent running on the container instance. | Yes |
$ECSContainerName |
The name of the container from which the log originated. This is the name in your ECS Task Definition. | No |
$TaskARN |
The full ARN of the ECS Task from which the log originated. | No |
$TaskDefinitionFamily |
The family name of the task definition for the task from which the log originated. | No |
$TaskDefinitionVersion |
The version or revision of the task definition for the task from which the log originated. | No |
$TaskID |
The ID of the ECS Task from which the log originated. | No |
Configuration file (설정 파일)
다음 설정들은 파서 파일과 Fluent Bit 설정의 서비스 섹션에 정의된 storage.path 변수가 제대로 구성되어 있다고 가정해요(보이지는 않음).
Example 1: Attach Task ID and cluster name to container logs (컨테이너 로그에 Task ID와 클러스터 이름 붙이기)
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: tail
tag: ecs.*
path: /var/lib/docker/containers/*/*.log
docker_mode: on
docker_mode_flush: 5
docker_mode_parser: container_firstline
parser: docker
db: /var/fluent-bit/state/flb_container.db
mem_buf_limit: 50MB
skip_long_lines: on
refresh_interval: 10
rotate_wait: 30
storage.type: filesystem
read_from_head: off
filters:
- name: ecs
match: '*'
ecs_tag_prefix: ecs.var.lib.docker.containers.
add:
- ecs_task_id $TaskID
- cluster $ClusterName
outputs:
- name: stdout
match: '*'
format: json_lines
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name tail
Tag ecs.*
Path /var/lib/docker/containers/*/*.log
Docker_Mode On
Docker_Mode_Flush 5
Docker_Mode_Parser container_firstline
Parser docker
DB /var/fluent-bit/state/flb_container.db
Mem_Buf_Limit 50MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 30
Storage.Type filesystem
Read_From_Head Off
[FILTER]
Name ecs
Match *
Ecs_Tag_Prefix ecs.var.lib.docker.containers.
Add ecs_task_id $TaskID
Add cluster $ClusterName
[OUTPUT]
Name stdout
Match *
Format json_lines
{% endtab %} {% endtabs %}
출력 로그는 다음과 비슷할 거예요:
{
"date":1665003546.0,
"log":"some message from your container",
"ecs_task_id": "1234567890abcdefghijklmnop",
"cluster": "your_cluster_name",
}
Example 2: Attach customized resource name to container logs (컨테이너 로그에 맞춤 리소스 이름 붙이기)
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: tail
tag: ecs.*
path: /var/lib/docker/containers/*/*.log
docker_mode: on
docker_mode_flush: 5
docker_mode_parser: container_firstline
parser: docker
db: /var/fluent-bit/state/flb_container.db
mem_buf_limit: 50MB
skip_long_lines: on
refresh_interval: 10
rotate_wait: 30
storage.type: filesystem
read_from_head: off
filters:
- name: ecs
match: '*'
ecs_tag_prefix: ecs.var.lib.docker.containers.
add: resource $ClusterName.$TaskDefinitionFamily.$TaskID.$ECSContainerName
outputs:
- name: stdout
match: '*'
format: json_lines
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name tail
Tag ecs.*
Path /var/lib/docker/containers/*/*.log
Docker_Mode On
Docker_Mode_Flush 5
Docker_Mode_Parser container_firstline
Parser docker
DB /var/fluent-bit/state/flb_container.db
Mem_Buf_Limit 50MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 30
Storage.Type filesystem
Read_From_Head Off
[FILTER]
Name ecs
Match *
Ecs_Tag_Prefix ecs.var.lib.docker.containers.
Add resource $ClusterName.$TaskDefinitionFamily.$TaskID.$ECSContainerName
[OUTPUT]
Name stdout
Match *
Format json_lines
{% endtab %} {% endtabs %}
출력 로그는 다음과 비슷할 거예요:
{
"date":1665003546.0,
"log":"some message from your container",
"resource": "cluster.family.1234567890abcdefghijklmnop.app",
}
resource 키 값의 템플릿 변수들은 점(dot) 문자로 구분돼요. 템플릿 변수 뒤에는 점과 쉼표(.와 ,)만 올 수 있어요. 자세한 내용은 Record accessor limitation's section을 참고하세요.
Example 3: Attach cluster metadata to non-container logs (컨테이너가 아닌 로그에 클러스터 메타데이터 붙이기)
이 예시는 cluster_metadata_only 옵션을 사용해서 ECS Agent 로그에 클러스터 메타데이터를 붙이는 사용 사례를 보여줘요.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: tail
tag: ecsagent.*
path: /var/log/ecs/*
db: /var/fluent-bit/state/flb_ecs.db
mem_buf_limit: 50MB
skip_long_lines: on
refresh_interval: 10
rotate_wait: 30
storage.type: filesystem
# Collect all logs on instance
read_from_head: on
filters:
- name: ecs
match: '*'
cluster_metadata_only: on
add: cluster $ClusterName
outputs:
- name: stdout
match: '*'
format: json_lines
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name tail
Tag ecsagent.*
Path /var/log/ecs/*
DB /var/fluent-bit/state/flb_ecs.db
Mem_Buf_Limit 50MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 30
Storage.Type filesystem
# Collect all logs on instance
Read_From_Head On
[FILTER]
Name ecs
Match *
Cluster_Metadata_Only on
Add cluster $ClusterName
[OUTPUT]
Name stdout
Match *
Format json_lines
{% endtab %} {% endtabs %}