当前位置 博文首页 > zcy_wxy的博客:FileBeat替换@timestamp的四种方法

    zcy_wxy的博客:FileBeat替换@timestamp的四种方法

    作者:[db:作者] 时间:2021-08-04 08:51

    1) 使用processors

    processors:
      - timestamp:
          # 格式化时间值 给 时间戳 
          field: start_time
          # 使用我国东八区时间  解析log时间
          timezone: Asia/Shanghai
          layouts:
            - '2006-01-02 15:04:05'
            - '2006-01-02 15:04:05.999'
          test:
            - '2019-06-22 16:33:51'

    2) 修改fields.xml文件(不推荐,具体看参考文章3)

    3) 使用属性覆盖

    在input部分配置

    json.keys_under_root: true
    json.overwrite_keys: true

    且输入的json的 @timestamp 的值得格式化方式必须为

    yyyy-MM-ddTHH:mm:ss.fffZ #其中fff表示毫秒,因为编程语言的不同要进行相应的更换

    4) 使用codec.format

    output.kafka:
      hosts: ["139.224.106.236:9092"]
      topic: '%{[fields.kafka_topic]}' #当使用了json.keys_under_root,直接使用指定属性名即可
      version: 0.11.0.0
      compression: gzip
      max_message_bytes: 1000000
      # 只输出message
      codec.format:
        string: '%{[message]}'

    参考文章:

    1) https://blog.csdn.net/qq_27818541/article/details/108063235

    2) https://blog.csdn.net/qq_41566159/article/details/110560654

    3) https://www.jianshu.com/p/e300d13f9e94

    cs