-
-
Save mitchang/c47fa800ff1ae418cb0371dcbcce519c to your computer and use it in GitHub Desktop.
Fluent Bitを用いてログ行に含まれる時刻情報をパースし、New Relic上のタイムスタンプとして扱う設定の例です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 入力プラグイン tail の設定 | |
# https://docs.fluentbit.io/manual/pipeline/inputs/tail | |
# Path: 対象ログファイルのフルパス | |
# Path_Key: ログファイルのパスを指定した属性名で付与します。ここでは New Relic の logs 属性の標準に合わせてキャメルケースを使用しています。 | |
# Key: ログが解析されなかった場合、デフォルトの 'log' 属性を New Relic の logs 属性の標準に合わせて 'message' に変更します。 | |
[INPUT] | |
Name tail | |
Path /var/log/httpd/access_log | |
Path_Key filePath | |
Key message | |
Tag httpd.access | |
# フィルタープラグインの設定 | |
# https://docs.fluentbit.io/manual/pipeline/filters/parser | |
# Match: 付与されたタグが一致するエントリに処理を適用します。 | |
# Parser: parsers_file 内で定義される Parser 名と一致させます。 | |
# Key_Name: Parser に読み込ませる属性です。 | |
# Preserve_Key: Parser で処理済みの message フィールドを削除しないようにします。 | |
# Reserve_Data: [INPUT]で付与したタグを保持します。 | |
[FILTER] | |
Name parser | |
Match httpd.access | |
Parser httpd_access_timestamp | |
Key_Name message | |
Preserve_Key On | |
Reserve_Data On |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parser 設定 | |
# https://docs.fluentbit.io/manual/pipeline/parsers/configuring-parser | |
# Regex: 正規表現を用いてマッチ条件を記述します。ここで名前付きグループとしてキャプチャされた値は New Relic 上でも属性として保持されます。 | |
# ここでは Apache の Common Log Format を解析する例を記載しています。 | |
# Time_Key: どのフィールドをタイムスタンプとして扱うかを指定します。 | |
# Time_Format: Time_Key で指定したフィールドを解析するための時刻フォーマットを指定します。 | |
[PARSER] | |
Name httpd_access_timestamp | |
Format regex | |
Regex ^(?<host>\S+) \S+ (?<user>\S+) \[(?<time>[^\]]+)\] "(?<method>\S+) +(?<path>.+?) (\S+)?" (?<code>\d{3}) | |
Time_Key time | |
Time_Format %d/%b/%Y:%H:%M:%S %z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/newrelic-infra/logging.d/fluentbit.yml (拡張子が.ymlであればファイル名は任意です) | |
# config_file および parsers_file の配置先パスは任意です。 | |
logs: | |
- name: fluentbit-external-config | |
fluentbit: | |
config_file: /etc/newrelic-infra/logging.d/fluentbit-config.conf | |
parsers_file: /etc/newrelic-infra/logging.d/fluentbit-parsers.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment