0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FluentbitでAzure Blobにデータを送る際、ファイル名に日付を付与する。

Posted at

概要

FluentbitでAzure Blobにデータを送信する際、AWS S3のように日付毎に分けることが出来ません。
そのため、Blob上の同じファイルにデータを送り続け、ローテーションされない状態となります。
以下の方法でTAGに日付を付与する事で、ファイルのローテーションを可能とします。

手順

Configファイル内容
/fluent-bit/etc/fluent-bit.conf

[INPUT]
    name   tail
    path   /var/log/hoge.log
    tag    hoge

[FILTER]
    Name   lua
    Match  *
    script /scripts/append_datetime.lua
    call   append_datetime

[FILTER]
    Name          rewrite_tag
    Match         hoge_log
    Rule          $datetime .* $datetime.$TAG.log false
    Emitter_Name  re_emitted

[OUTPUT]
    name                  azure_blob
    match                 *
    account_name          <account_name>
    shared_key            <secret_key>
    path                  hogelog
    container_name        logs
    auto_create_container on
    tls                   on

日付取得スクリプト
/scripts/append_datetime.lua

function append_datetime(tag, timestamp, record)
    new_record = record
    new_record["datetime"] = os.date("%Y-%m-%d-%H-%M-%S")
    return 1, timestamp, new_record
end

説明

[FILTER] luaでスクリプトで実行時の日付を取得し、次のrewrite_tagでタグを書き換え「YYYY-mm-dd-HH-MM-SS.hoge.log」の名前でBlobに保存されます。保存される名前は $datetime.$TAG.log を修正することで好きにつけることが可能です。
また、このままだと秒ごとにファイルが作成されてしまうので、 append_datetime.lua をos.date("%Y-%m-%d-%H-%M-%S")からos.date("%Y-%m-%d")にするなど各自調整を行ってください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?