Development

Elasticsearch + Fluent Bit + Kibana

Medeev 2025. 4. 28. 10:55

이전글에 Fluent Bit + ES + Grafana 관련내용으로 글을 썻는데 Grafana는 사용성이 시계열 데이터를 그래픽적으로 보여주는데 주요 기능이 있었다.

 

Grafana로는 GPT가 제시한 방법으로는 로그의 세부적인 Search가 불가능하여 결론적으로 게임서버에서 쓸만하지 못하여

Elasticsearch + Fluent Bit + Kibana 조합으로 변경했다.

 

1. Fluent Bit 설정

[SERVICE]
    # Flush
    # =====
    # set an interval of seconds before to flush records to a destination
    flush        1

    # Daemon
    # ======
    # instruct Fluent Bit to run in foreground or background mode.
    daemon       Off

    # Log_Level
    # =========
    # Set the verbosity level of the service, values can be:
    #
    # - error
    # - warning
    # - info
    # - debug
    # - trace
    #
    # by default 'info' is set, that means it includes 'error' and 'warning'.
    #log_level    info
    log_level    debug

    # Parsers File
    # ============
    # specify an optional 'Parsers' configuration file
    parsers_file parsers.conf

    # Plugins File
    # ============
    # specify an optional 'Plugins' configuration file to load external plugins.
    plugins_file plugins.conf

    # HTTP Server
    # ===========
    # Enable/Disable the built-in HTTP Server for metrics
    http_server  Off
    http_listen  0.0.0.0
    http_port    2020

    # Storage
    # =======
    # Fluent Bit can use memory and filesystem buffering based mechanisms
    #
    # - https://docs.fluentbit.io/manual/administration/buffering-and-storage
    #
    # storage metrics
    # ---------------
    # publish storage pipeline metrics in '/api/v1/storage'. The metrics are
    # exported only if the 'http_server' option is enabled.
    #
    storage.metrics on

    # storage.path
    # ------------
    # absolute file system path to store filesystem data buffers (chunks).
    #
    # storage.path /tmp/storage
    storage.path C:/Data/fluentbit/storage

    # storage.sync
    # ------------
    # configure the synchronization mode used to store the data into the
    # filesystem. It can take the values normal or full.
    #
    # storage.sync normal

    # storage.checksum
    # ----------------
    # enable the data integrity check when writing and reading data from the
    # filesystem. The storage layer uses the CRC32 algorithm.
    #
    # storage.checksum off

    # storage.backlog.mem_limit
    # -------------------------
    # if storage.path is set, Fluent Bit will look for data chunks that were
    # not delivered and are still in the storage layer, these are called
    # backlog data. This option configure a hint of maximum value of memory
    # to use when processing these records.
    #
    # storage.backlog.mem_limit 5M
    Lua_Path     script.lua

[INPUT]
    Name tail
    Path D:\Work\Server\Binary\Debug\Log\Game_*.json
    Tag game.logs
    DB C:/Data/fluentbit/fluentbit.db
    Parser json
    Refresh_Interval 10
    Rotate_Wait 5

[OUTPUT]
    Name  es
    Match *
    Host  localhost
    Port  9200
    Index log-router
    Pipeline logtype-router
    # es7.8 type field generate block!!!!
    Suppress_Type_Name On
    Compress gzip

 

주의점 :

 - Tab으로 conf파일을 수정하면 에러가난다.

 - Suppress_Type_Name On 해야 Elasticsearch에서 Type관련 에러가 나지 않는다.

 - script.lua파일을 통해 ES 에 보내는 키형식을 나누보고 하고 싶었으나 결론적으로 Fluent-bit에서는 Index를 동적으로 수정하지 못했다. Index의 동적 수정 방식은 제공하지 않는다는것을 알았다. [Output]을 여러개 두어 Match별로 Index를 정적으로 여러가 두는 방법은 생각해 볼 수 있었으나. 원래의 목적은 jsonLog상의 logtype 커스텀 필드의 값에 따라 인덱스를 동적으로 생성하고 싶었기때문에 이방식은 쓰지 않았다.

 - Pipeline logtype-router 는 ES에서 전달된 로그를 수정하는 방식인데 이것을 사용하여 jsonLog의 logtype 커스텀필드의 값에 따라 ES에서 인덱스를 동적 생성하게 했다. Pipeline에서 지정된 이름으로 여기서는 logtype-router 이름이다.

 

2. Elasticsearch 설정

PUT _ingest/pipeline/logtype-router
{
  "description": "Route logs to index based on logtype field",
  "processors": [
    {
      "lowercase": {
        "field": "logtype",
        "ignore_missing": true
      }
    },
    {
      "set": {
        "field": "_index",
        "value": "logtype-{{logtype}}",
        "if": "ctx.logtype != null"
      }
    },
    {
      "set": {
        "field": "_index",
        "value": "logtype-unknown",
        "if": "ctx.logtype == null"
      }
    }
  ]
}

 

위와 같은 설정으로 jsonLog의 logtype 필드의 값에 따라 logtype-system, logtype-content 등의 Index가 나눠지게 설정하였다.

위 파이프라인은 

Elasticsearch -> Management -> Console -> Shell 에 넣어서 실행해주었다.

 

테스트 완료!!

 

 

'Development' 카테고리의 다른 글

Fluent Bit + ES + Grafana  (1) 2025.04.11
Windows OpenSSH 서버 Git저장소 Clone하기  (0) 2024.05.05
[Jenkins] 젠킨스 설치 방법 (Windows)  (0) 2024.03.28