Prometheus remote write 출력 플러그인
Fluent Bit의 메트릭을 remote write 프로토콜로 Prometheus 서버에 제출하고 싶을 때 쓰는 출력 플러그인입니다. 함께 살펴보겠습니다.
출처: 문서
본문
remote write 프로토콜을 사용해 Prometheus 메트릭을 제출하는 출력 플러그인
{% hint style="info" %}
Supported event types: metrics
{% endhint %}
Prometheus remote write 플러그인은 Fluent Bit에서 메트릭을 가져와 remote write 메커니즘을 통해 Prometheus 서버에 제출할 수 있게 해 줍니다.
Prometheus exporter는 Node Exporter Metrics 같은 메트릭 플러그인에서만 동작합니다.
Configuration parameters
이 플러그인은 다음 파라미터를 지원합니다:
| Key | Description | Default |
|---|---|---|
add_label |
This lets you add custom labels to all metrics sent by the prometheus_remote_write output. You can have multiple of these fields. |
none |
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/. |
none |
aws_region |
Region of your Amazon Managed Service for Prometheus workspace. | none |
aws_role_arn |
AWS IAM Role to assume, used by SigV4 authentication. | none |
aws_service |
AWS destination service code, used by SigV4 authentication. For Amazon Managed Service for Prometheus, the service name is aps. |
aps |
aws_sts_endpoint |
Specify the custom STS endpoint to be used with STS API, used with the aws_role_arn option, used by SigV4 authentication. |
none |
compression |
Payload compression algorithm. Supported options: snappy, gzip, zstd. |
snappy |
header |
Add a HTTP header key/value pair. Multiple headers can be set. | none |
host |
IP address or hostname of the target HTTP server. | 127.0.0.1 |
http_passwd |
Basic Auth password. Requires http_user to be set. |
none |
http_user |
Basic Auth username. | none |
log_response_payload |
Log the response payload within the Fluent Bit log. | true |
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. 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 /someuri. |
none |
workers |
The number of workers to perform flush operations for this output. | 2 |
Stale metric expiration
Stale metric expiration은 Fluent Bit 5.1.2 이상 버전에서 사용할 수 있어요.
Fluent Bit는 remote write 페이로드를 만들기 전에 각 플러시에서 타임스탬프가 1시간보다 오래된 메트릭을 모두 버립니다. Remote write 백엔드는 이렇게 오래된 샘플을 stale로 거부하며, 단일 샘플 거부는 전체 요청을 실패시켜 현재 샘플도 전달되지 않게 만들 수 있어요.
만료는 각 레이블 집합에 별도로 적용되므로, 유휴 시계열은 버려지지만 같은 메트릭의 활발하게 갱신되는 시계열은 여전히 전송됩니다.
이 컷오프는 1시간으로 고정되어 있으며 설정할 수 없습니다. 컷오프보다 오래된 메트릭은 오류 없이 버려지고, 같은 플러시의 나머지 메트릭은 여전히 전송됩니다. 파일시스템 버퍼링에서 복구된 백로그나 아카이브에서의 리플레이가 1시간을 넘어설 때, 플러시가 실행될 때 이미 컷오프보다 오래된 샘플만 버려집니다. 더 새로운 샘플은 여전히 전달 대상으로 남아 있어요. 컷오프는 각 플러시에서 현재 시간을 기준으로 평가되므로, 느린 리플레이는 진행됨에 따라 백로그를 더 많이 만료시킬 수 있습니다.
시작하기
Prometheus remote write 플러그인은 메트릭 입력 플러그인 중 하나가 수집한 메트릭에서만 동작합니다. 아래 예시에서는 node exporter metrics 플러그인이 호스트 메트릭을 수집하고 Prometheus remote write 출력 플러그인이 전달합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
# Node Exporter Metrics + Prometheus remote write output plugin
# -------------------------------------------
# The following example collects host metrics on Linux and delivers
# them through the Prometheus remote write plugin to new relic :
#
service:
flush: 1
log_level: info
pipeline:
inputs:
- name: node_exporter_metrics
tag: node_metrics
scrape_interval: 2
outputs:
- name: prometheus_remote_write
match: node_metrics
host: metric-api.newrelic.com
port: 443
uri: /prometheus/v1/write?prometheus_server=YOUR_DATA_SOURCE_NAME
header: 'Authorization Bearer YOUR_LICENSE_KEY'
log_response_payload: true
tls: on
tls.verify: on
# add user-defined labels
add_label:
- app fluent-bit
- color blue
# Note : it would be necessary to replace both YOUR_DATA_SOURCE_NAME and YOUR_LICENSE_KEY
# with real values for this example to work.
{% endtab %}
{% tab title="fluent-bit.conf" %}
# Node Exporter Metrics + Prometheus remote write output plugin
# -------------------------------------------
# The following example collects host metrics on Linux and delivers
# them through the Prometheus remote write plugin to new relic :
#
[SERVICE]
Flush 1
Log_Level info
[INPUT]
Name node_exporter_metrics
Tag node_metrics
Scrape_Interval 2
[OUTPUT]
Name prometheus_remote_write
Match node_metrics
Host metric-api.newrelic.com
Port 443
Uri /prometheus/v1/write?prometheus_server=YOUR_DATA_SOURCE_NAME
Header Authorization Bearer YOUR_LICENSE_KEY
Log_Response_Payload True
Tls On
Tls.verify On
# add user-defined labels
Add_Label app fluent-bit
Add_Label color blue
# Note : it would be necessary to replace both YOUR_DATA_SOURCE_NAME and YOUR_LICENSE_KEY
# with real values for this example to work.
{% endtab %} {% endtabs %}
예시
다음은 호스팅 서비스와 함께 Prometheus remote write를 사용하는 예시들입니다:
Grafana Cloud
Grafana Cloud 호스팅 메트릭을 사용하면 언급된 특정 호스트를 사용하고 Grafana Cloud 페이지에 제공된 HTTP 사용자 이름과 비밀번호를 지정해야 합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: prometheus_remote_write
match: '*'
host: prometheus-us-central1.grafana.net
uri: /api/prom/push
port: 443
tls: on
tls.verify: on
http_user: <GRAFANA Username>
http_passwd: <GRAFANA Password>
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name prometheus_remote_write
Match *
Host prometheus-us-central1.grafana.net
Uri /api/prom/push
Port 443
Tls on
Tls.verify on
Http_User <GRAFANA Username>
Http_Passwd <GRAFANA Password>
{% endtab %} {% endtabs %}
Logz.io infrastructure monitoring
Logz.io hosted Prometheus를 사용하면 header 옵션을 사용하고 적절한 키로 Authorization Bearer를 추가해야 합니다. 호스트와 포트는 특정 호스팅 인스턴스에 따라 다를 수 있습니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: prometheus_remote_write
match: '*'
host: listener.logz.io
port: 8053
tls: on
tls.verify: on
log_response_payload: true
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name prometheus_remote_write
Match *
Host listener.logz.io
Port 8053
Header Authorization Bearer <LOGZIO Key>
Tls on
Tls.verify on
Log_Response_Payload true
{% endtab %} {% endtabs %}
Coralogix
Coralogix Metrics를 사용하면 URI를 커스터마이즈해야 할 수 있습니다. 또한 Coralogix 개인 키와 함께 header 키를 사용하게 됩니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: prometheus_remote_write
match: '*'
host: metrics-api.coralogix.com
uri: /prometheus/api/v1/write?appLabelName=path&subSystemLabelName=path&severityLabelName=severity
port: 443
header: 'Authorization Bearer <CORALOGIX Key>'
tls: on
tls.verify: on
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name prometheus_remote_write
Match *
Host metrics-api.coralogix.com
Uri /prometheus/api/v1/write?appLabelName=path&subSystemLabelName=path&severityLabelName=severity
Port 443
Header Authorization Bearer <CORALOGIX Key>
Tls on
Tls.verify on
{% endtab %} {% endtabs %}
Levitate
Levitate를 사용하면 Levitate 클러스터별 write URL을 사용해야 하고, Levitate 클러스터용으로 생성된 토큰에 대한 HTTP 사용자 이름과 비밀번호를 지정해야 합니다.
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: prometheus_remote_write
match: '*'
host: app-tsdb.last9.io
uri: /v1/metrics/82xxxx/sender/org-slug/write
port: 443
tls: on
tls.verify: on
http_user: <Levitate Cluster Username>
http_passwd: <Levitate Cluster Password>
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name prometheus_remote_write
Match *
Host app-tsdb.last9.io
Uri /v1/metrics/82xxxx/sender/org-slug/write
Port 443
Tls on
Tls.verify on
Http_User <Levitate Cluster Username>
Http_Passwd <Levitate Cluster Password>
{% endtab %} {% endtabs %}
Prometheus 유사 레이블 추가
일반 Prometheus 클라이언트는 다음 레이블 중 일부를 추가합니다:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
outputs:
- name: prometheus_remote_write
match: your.metric
host: xxxxxxx.yyyyy.zzzz
port: 443
uri: /api/v1/write
header: 'Authorization Bearer YOUR_LICENSE_KEY'
log_response_payload: true
tls: on
tls.verify: on
# add user-defined labels
add_label:
- instance ${HOSTNAME}
- job fluent-bit
{% endtab %}
{% tab title="fluent-bit.conf" %}
[OUTPUT]
Name prometheus_remote_write
Match your.metric
Host xxxxxxx.yyyyy.zzzz
Port 443
Uri /api/v1/write
Header Authorization Bearer YOUR_LICENSE_KEY
Log_Response_Payload True
Tls On
Tls.verify On
# add user-defined labels
Add_Label instance ${HOSTNAME}
Add_Label job fluent-bit
{% endtab %} {% endtabs %}
instance 레이블은 add_label instance ${HOSTNAME}로 흉내낼 수 있습니다. 그리고 다른 레이블은 add_label <key> <value> 설정으로 추가할 수 있어요.