HTTP 출력 플러그인
레코드를 HTTP 엔드포인트로 보내고 싶을 때 쓰는 출력 플러그인입니다. 함께 살펴보겠습니다.
출처: 문서
본문
HTTP 출력 플러그인은 레코드를 HTTP 엔드포인트로 플러시할 수 있게 해 줍니다. MessagePack(또는 JSON) 형식의 데이터 레코드로 POST나 PUT 요청을 발행합니다.
Configuration parameters
| Key | Description | Default |
|---|---|---|
allow_duplicated_headers |
Specify if duplicated headers are allowed. If a duplicated header is found, the latest key/value set is preserved. | true |
aws_auth |
Enable AWS SigV4 authentication. | false |
aws_external_id |
External ID for the AWS IAM Role specified with aws_role_arn, used by SigV4 authentication. |
none |
aws_profile |
AWS Profile name. AWS Profiles can be configured with AWS CLI and are usually stored in $HOME/.aws/ directory. |
none |
aws_region |
Specify the AWS region of your service, used by SigV4 authentication. | none |
aws_role_arn |
AWS IAM Role to assume, used by SigV4 authentication. | none |
aws_service |
Specify the AWS service code of your service, used by SigV4 authentication (for example, es, xray). Usually found in the service endpoint's subdomains, protocol://service-code.region-code.amazonaws.com. |
none |
aws_sts_endpoint |
Specify the custom STS endpoint to be used by STS API. Used with the aws_role_arn option and by SigV4 authentication. |
none |
body_key |
Specify the key to use as the body of the request (must prefix with $). The key must contain either a binary or raw string, and the content type can be specified using headers_key, which must be passed whenever body_key is present. When this option is present, each msgpack record will create a separate request. |
none |
compress |
Set payload compression mechanism. Allowed values: gzip, snappy, zstd. |
none |
format |
Specify the data format to be used in the HTTP request body. Supported formats: gelf, json, json_stream, json_lines, msgpack. |
json |
gelf_full_message_key |
Specify the key to use for the full message in gelf format. |
none |
gelf_host_key |
Specify the key to use for the host in gelf format. |
none |
gelf_level_key |
Specify the key to use for the level in gelf format. |
none |
gelf_short_message_key |
Specify the key to use as the short message in gelf format. |
none |
gelf_timestamp_key |
Specify the key to use for timestamp in gelf format. |
none |
header |
Add a HTTP header key/value pair. Multiple headers can be set. | none |
header_tag |
Specify an optional HTTP header field for the original message tag. | none |
headers_key |
Specify the key to use as the headers of the request (must prefix with $). The key must contain a map, which will have the contents merged on the request headers. This can be used for many purposes, such as specifying the content type of the data contained in body_key. |
none |
host |
IP address or hostname of the target HTTP Server. | 127.0.0.1 |
http.read_idle_timeout |
Set maximum allowed time between two consecutive reads. If set to 0s, uses the io_timeout value from the network setup. |
0s |
http.response_timeout |
Set maximum time to wait for a server response. | 60s |
http_method |
Specify POST versus PUT HTTP method. |
POST |
http_passwd |
Basic Auth password. Requires http_user to be set. |
none |
http_user |
Basic Auth username. | none |
json_date_format |
Specify the format of the date. Supported formats: double, epoch, epoch_ms, iso8601, java_sql_timestamp. |
none |
json_date_key |
Specify the name of the time key in the output record. To disable the time key, set the value to false. |
date |
log_response_payload |
Specify if the response payload should be logged or not. | true |
oauth2.audience |
Optional OAuth 2.0 audience parameter. |
none |
oauth2.auth_method |
OAuth 2.0 client authentication method. Supported values: basic, post, private_key_jwt. |
basic |
oauth2.client_id |
Required when oauth2.enable is true. OAuth 2.0 client ID. |
none |
oauth2.client_secret |
Required when oauth2.enable is true and oauth2.auth_method is basic or post. OAuth 2.0 client secret. |
none |
oauth2.connect_timeout |
Connect timeout for OAuth 2.0 token requests. |
0s |
oauth2.enable |
Enable OAuth 2.0 client credentials for outgoing requests. |
false |
oauth2.jwt_aud |
Audience for private_key_jwt JSON Web Token (JWT) assertion. Defaults to the value of oauth2.token_url when not set. |
none |
oauth2.jwt_cert_file |
Required when oauth2.enable is true and oauth2.auth_method is private_key_jwt. Path to certificate file used by private_key_jwt. Fluent Bit derives the oauth2.jwt_header thumbprint from this certificate. |
none |
oauth2.jwt_header |
JWT header claim name for the private_key_jwt certificate thumbprint. Supported values are kid (hexadecimal SHA-1), x5t (base64url SHA-1), and x5t#S256 (base64url SHA-256). Fluent Bit doesn't validate this value: an unrecognized name is sent as the claim name with a hexadecimal SHA-1 thumbprint. |
kid |
oauth2.jwt_key_file |
Required when oauth2.enable is true and oauth2.auth_method is private_key_jwt. Path to PEM private key file used by private_key_jwt. |
none |
oauth2.jwt_ttl_seconds |
Lifetime in seconds for private_key_jwt JWT client assertions. |
300 |
oauth2.refresh_skew_seconds |
Seconds before expiry at which to refresh the access token. | 60 |
oauth2.resource |
Optional OAuth 2.0 resource parameter. |
none |
oauth2.scope |
Optional OAuth 2.0 scope. |
none |
oauth2.timeout |
Timeout for OAuth 2.0 token requests. Defaults to http.response_timeout when unset. |
0s |
oauth2.token_url |
Required when oauth2.enable is true. OAuth 2.0 token endpoint URL. Must use the http or https scheme. Use https in production: with http, Fluent Bit sends the client credentials without TLS. |
none |
oauth2.user_agent |
Optional User-Agent header value to include in OAuth 2.0 token requests. If omitted, no User-Agent header is sent. |
none |
port |
TCP port of the target HTTP Server. | 80 |
proxy |
Specify an HTTP Proxy. The expected format of this value is http://HOST:PORT. HTTPS isn't supported. It's recommended to configure the HTTP proxy environment variables instead as they support both HTTP and HTTPS. |
none |
uri |
Specify an optional HTTP URI for the target web server. For example, /somepath. |
none |
workers |
The number of workers to perform flush operations for this output. | 2 |
TLS / SSL
HTTP 출력 플러그인은 TLS/SSL을 지원합니다. 사용 가능한 속성과 일반 구성에 대한 자세한 내용은 TLS/SSL을 참고하세요.
시작하기
HTTP 서버에 레코드를 삽입하려면 명령줄에서 또는 구성 파일을 통해 플러그인을 실행할 수 있어요.
명령줄
HTTP 플러그인은 -p 인자(속성)를 통해 또는 서비스 URI를 직접 설정해서 명령줄에서 파라미터를 읽을 수 있습니다. URI 형식은 다음과 같습니다:
http://host:port/something
지정된 형식을 사용해 다음으로 Fluent Bit를 시작할 수 있어요:
fluent-bit -i cpu -t cpu -o http://192.168.2.3:80/something -m '*'
구성 파일
주 구성 파일에 다음을 추가합니다:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: cpu
tag: cpu
outputs:
- name: http
match: '*'
host: 192.168.2.3
port: 80
uri: /something
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name cpu
Tag cpu
[OUTPUT]
Name http
Match *
Host 192.168.2.3
Port 80
Uri /something
{% endtab %} {% endtabs %}
기본적으로 URI가 메시지의 태그가 되고, 원본 태그는 무시됩니다. 태그를 유지하려면 여러 구성 섹션을 만들고 둘 이상의 URI로 플러시해야 합니다.
지원되는 또 다른 접근 방식은 원본 메시지 태그를 구성 가능한 헤더로 보내는 것입니다. 그 헤더 필드로 무엇을 할지는 수신자가 정하면 됩니다. 예를 들어, 그것을 파싱해서 태그로 사용하는 거죠.
이 동작을 구성하려면 다음 구성을 추가하세요:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: http
match: '*'
host: 192.168.2.3
port: 80
uri: /something
format: json
header_tag: FLUENT-TAG
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name http
Match *
Host 192.168.2.3
Port 80
Uri /something
Format json
Header_Tag FLUENT-TAG
{% endtab %} {% endtabs %}
데이터 수신자로 Fluentd를 사용한다면 in_http와 out_rewrite_tag_filter를 결합해 이 HTTP 헤더를 활용할 수 있어요.
<source>
@type http
add_http_headers true
</source>
<match something>
@type rewrite_tag_filter
<rule>
key HTTP_FLUENT_TAG
pattern /^(.*)$/
tag $1
</rule>
</match>
Fluent Bit는 URI 경로에서 온 태그를 커스텀 헤더로 덮어씁니다.
헤더 추가
이 예시는 헤더를 추가합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: http
match: '*'
host: 127.0.0.1
port: 9000
header:
- X-Key-A Value_A
- X-Key-B Value_B
uri: /something
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name http
Match *
Host 127.0.0.1
Port 9000
Header X-Key-A Value_A
Header X-Key-B Value_B
Uri /something
{% endtab %} {% endtabs %}
Sumo Logic HTTP collector
다음은 iso8601 타임스탬프와 함께 json_lines을 사용하는 Sumo Logic용 권장 구성입니다. PrivateKey는 구성된 HTTP collector에 특정합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: http
match: '*'
host: collectors.au.sumologic.com
port: 443
uri: /receiver/v1/http/[PrivateKey]
format: json_lines
json_date_key: timestamp
json_date_format: iso8601
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name http
Match *
Host collectors.au.sumologic.com
Port 443
Uri /receiver/v1/http/[PrivateKey]
Format json_lines
Json_Date_Key timestamp
Json_Date_Format iso8601
{% endtab %} {% endtabs %}
CPU 입력용 Sumo Logic 쿼리 예시입니다. (timestamp 필드에 iso8601 날짜 형식의 json_lines 형식이 필요합니다).
_sourcecategory="my_fluent_bit"
| json "cpu_p" as cpu
| timeslice 1m
| max(cpu) as cpu group by _timeslice
PUT 메서드 사용
다음 예시는 HTTP 출력 플러그인을 기본 POST 메서드 대신 PUT 메서드를 사용하도록 구성하는 방법을 보여줍니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: http
match: '*'
host: 192.168.2.3
port: 80
uri: /api/endpoint
http_method: PUT
format: json
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name http
Match *
Host 192.168.2.3
Port 80
Uri /api/endpoint
Http_Method PUT
Format json
{% endtab %} {% endtabs %}