AWS 메타데이터
지원 이벤트 유형:
logs
AWS Filter는 로그에 AWS 메타데이터를 추가해요. 이 플러그인은 로그 레코드에 EC2 인스턴스 ID와 가용 영역(availability zone)을 추가해 줘요. 이 플러그인을 사용하려면 EC2에서 실행 중이어야 하고 인스턴스 메타데이터 서비스가 활성화되어 있어야 해요.
출처: 문서
본문
구성 파라미터
이 플러그인은 다음 구성 파라미터를 지원해요.
| Key | Description | Default |
|---|---|---|
account_id |
The account ID for the current EC2 instance. | false |
ami_id |
The EC2 instance image ID. | false |
az |
The availability zone, such as us-east-1a. |
true |
ec2_instance_id |
The EC2 instance ID. | true |
ec2_instance_type |
The EC2 instance type. | false |
enable_entity |
Enables entity prefix for fields used for constructing entity. | false |
hostname |
The hostname for the current EC2 instance. | false |
imds_version |
Specify which version of the instance metadata service to use. Valid values are v1 and v2. |
v2 |
private_ip |
The EC2 instance private IP. | false |
retry_interval_s |
Defines minimum duration in seconds between retries for fetching EC2 instance tags. | 300 |
tags_enabled |
Specifies whether to attach EC2 instance tags. The EC2 instance must have the instance-metadata-tags option enabled, which is disabled by default. |
false |
tags_exclude |
Defines a list of specific EC2 tag keys not to inject into the logs. Tag keys must be comma-separated (,). Tags not included in this list will be injected into the logs. If both tags_include and tags_exclude are specified, the configuration is invalid and the plugin fails. Example: Name,tag1,tag2 |
none |
tags_include |
Defines a list of specific EC2 tag keys to inject into the logs. Tag keys must be comma-separated (,). Tags not included in this list will be ignored. Example: Name,tag1,tag2. |
none |
vpc_id |
The VPC ID for the current EC2 instance. | false |
컨테이너에서 Fluent Bit를 실행한다면 인스턴스 메타데이터 v1을 사용해야 할 수도 있어요. 플러그인은 어떤 버전을 사용하든 동일하게 동작해요.
명령줄에서 실행하기
명령줄에서 Fluent Bit를 실행해요.
./fluent-bit -c /PATH_TO_CONF_FILE/fluent-bit.conf
다음과 같은 결과가 보일 거예요.
[2020/01/17 07:57:17] [ info] [engine] started (pid=32744)
[0] dummy: [1579247838.000171227, {"message"=>"dummy", "az"=>"us-west-2c", "ec2_instance_id"=>"i-0c862eca9038f5aae", "ec2_instance_type"=>"t2.medium", "private_ip"=>"172.31.6.59", "vpc_id"=>"vpc-7ea11c06", "ami_id"=>"ami-0841edc20334f9287", "account_id"=>"YOUR_ACCOUNT_ID", "hostname"=>"ip-172-31-6-59.us-west-2.compute.internal"}]
[0] dummy: [1601274509.970235760, {"message"=>"dummy", "az"=>"us-west-2c", "ec2_instance_id"=>"i-0c862eca9038f5aae", "ec2_instance_type"=>"t2.medium", "private_ip"=>"172.31.6.59", "vpc_id"=>"vpc-7ea11c06", "ami_id"=>"ami-0841edc20334f9287", "account_id"=>"YOUR_ACCOUNT_ID", "hostname"=>"ip-172-31-6-59.us-west-2.compute.internal"}]
설정 파일
다음은 설정 파일의 예시예요.
fluent-bit.yaml:
pipeline:
inputs:
- name: dummy
tag: dummy
filters:
- name: aws
match: '*'
imds_version: v1
az: true
ec2_instance_id: true
ec2_instance_type: true
private_ip: true
ami_id: true
account_id: true
hostname: true
vpc_id: true
tags_enabled: true
outputs:
- name: stdout
match: '*'
fluent-bit.conf:
[INPUT]
Name dummy
Tag dummy
[FILTER]
Name aws
Match *
Imds_Version v1
Az true
Ec2_Instance_Id true
Ec2_Instance_Type true
Private_Ip true
Ami_Id true
Account_Id true
Hostname true
Vpc_Id true
Tags_Enabled true
[OUTPUT]
Name stdout
Match *
EC2 태그
EC2 태그를 사용하면 커스텀 키-값 쌍을 만들어 EC2 인스턴스에 라벨을 붙이고 정리할 수 있어요. 이 태그들은 리소스 관리, 비용 할당, 자동화에 흔히 사용돼요. Fluent Bit가 생성한 로그에 태그를 포함시키는 것은 거의 필수적이에요.
이를 위해 AWS Filter를 tags_enabled true로 구성하면 관련 EC2 인스턴스 태그로 로그에 태깅할 수 있어요. 이렇게 하면 로그가 적절하게 태깅되어 특정 기준에 따라 로그를 관리하고 분석하기가 쉬워져요.
요구 사항
Fluent Bit에서 tags_enabled true 기능을 사용하려면 Fluent Bit가 실행되는 EC2 인스턴스에서 instance-metadata-tags 옵션이 활성화되어 있어야 해요. 이 옵션이 없으면 Fluent Bit는 EC2 인스턴스와 연결된 태그를 가져올 수 없어요. 하지만 그렇다고 Fluent Bit가 실패하거나 완전히 멈추는 것은 아니에요. instance-metadata-tags 옵션이 활성화되어 있지 않아도 Fluent Bit는 정상적으로 동작하며, 구성에 따라 EC2 인스턴스 ID나 가용 영역 같은 다른 값들을 계속 수집해요.
예시
tags_include
EC2 인스턴스에 많은 태그가 있고, 그중 일부는 수집하려는 로그와 관련 없는 긴 값을 가진다고 가정해 봐요. department와 project 두 태그만 목적에 유용하다면, 다음 설정이 이 요구 사항을 반영해요.
fluent-bit.yaml:
pipeline:
filters:
- name: aws
match: '*'
tags_enabled: true
tags_include: department,project
fluent-bit.conf:
[FILTER]
Name aws
Match *
Tags_Enabled true
Tags_Include department,project
그러면 Fluent Bit 로그는 다음과 같이 보일 수 있어요.
{"log"=>"fluentbit is awesome", "az"=>"us-east-1a", "ec2_instance_id"=>"i-0e66fc7f9809d7168", "department"=>"it", "project"=>"fluentbit"}
tags_exclude
EC2 인스턴스에 Name:fluent-bit-docs-example, project:fluentbit, department:it 세 개의 태그가 있다고 가정해 봐요. 이 예시에서 department 태그는 중복이라 제외할 거예요. 모든 프로젝트가 it 부서에 속하므로 중복 라벨에 저장 공간을 낭비하고 싶지 않아요.
이를 구현한 예시 설정은 다음과 같아요.
fluent-bit.yaml:
pipeline:
filters:
- name: aws
match: '*'
tags_enabled: true
tags_exclude: department
fluent-bit.conf:
[FILTER]
Name aws
Match *
Tags_Enabled true
Tags_Exclude department
결과 로그는 다음과 같이 보일 수 있어요.
{"log"=>"aws is awesome", "az"=>"us-east-1a", "ec2_instance_id"=>"i-0e66fc7f9809d7168", "Name"=>"fluent-bit-docs-example", "project"=>"fluentbit"}