【问题标题】:Relay logs to elasticsearch from fluentd by event type将日志从 fluentd 按事件类型中继到 elasticsearch
【发布时间】:2019-02-04 00:29:58
【问题描述】:

我有如下的 json 日志:

{"event": "{"eventType": "pageview","userId": "2122334"}"}
{"event": "{"eventType": "reload","userId": "2122334"}"}

我需要中继事件以根据事件类型分离弹性搜索索引。我在 fluentd 中使用标签、规则中的模式等感到困惑。

一种方法是按类型标记事件,然后将不同的索引发送到 elasticsearch。但我找不到如何做到这一点的示例。

任何帮助表示赞赏。

谢谢

【问题讨论】:

  • 你想做什么,我想基本上你可以使用解析器从记录中获取特定的键。

标签: elasticsearch filter fluentd


【解决方案1】:

鉴于您的日志是 JSON 格式的,您的源代码部分将有类似的内容:

  <parse>
    @type json
    time_key $.log.myTimeField  # optional, just for you to see how to retrieve keys from json.
    keep_time_key true   # optional
  </parse>

那么你可以有这样的比赛:

  <match **>
    @type copy
    <store>
      @type elasticsearch
      host 127.0.0.1
      port 9200
      index_name logs.${myKey}
      include_tag_key true
      <buffer tag, myKey>
        flush_at_shutdown true
        flush_mode immediate
        flush_thread_count 8
      </buffer>
    </store>
  </match>

请注意,您需要缓冲区部分。这个例子很简单,也许你可以尝试这样的方式来满足你的需要:

index_name logs.${event["eventType"]}

我知道这是一个老问题,但希望能有所帮助。祝你好运!

【讨论】:

    猜你喜欢
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2020-01-18
    • 2021-01-05
    • 2018-07-18
    • 2020-05-07
    相关资源
    最近更新 更多