【问题标题】:Parsing nginx error log through fluentd通过fluentd解析nginx错误日志
【发布时间】:2018-06-19 08:13:40
【问题描述】:

我正在寻找解析 nginx 错误日志文件并将解析后的格式放入 elasticsearch。我可以对 access.log 做同样的事情,因为它接受 log_format 指令,但 error.log 没有。我有以下我主要感兴趣的示例错误日志:

2018/01/10 06:26:31 [error] 13485#13485: *64285471 limiting connections by zone "rl_conn", client: xx.xx.xx.xx, server: www.xyz.com, request: "GET /api/xyz HTTP/1.1", host: "www.xyz.com"

我想通过一些解析器来解析它,这样我就可以得到像这样的 json 格式:

{client: "xx.xx.xx.xx", server: "www.xyz.com", host: "www.xyz.com", "request": "GET /api/xyz HTTP/1.1", reason: "limiting connections by zone "rl_conn""}

有人可以帮忙吗?

【问题讨论】:

  • 你找到解决办法了吗?

标签: nginx error-log


【解决方案1】:

@serut 在这个 Github 问题的底部有一个很好的解决方案:https://github.com/fluent/fluentd/issues/2991

# Use NGINX parse for front logs
<label @PARSENGINX>
    <filter front>
        @type parser
        key_name message
        <parse>
            @type nginx
        </parse>
    </filter>
    <filter front>
        # Handle errors
        @type parser
        key_name message
        <parse>
            @type regexp
            expression /^(?<logtime>\d{4}\/\d{1,2}\/\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}) (?<log_level>\[[^\s]+\]) (?<message>.*)$/
            time_key logtime
            time_format %Y/%m/%d %H:%M:%S
        </parse>
    </filter>
    <match **>
        @type copy
        <store>
            @type relabel
            @label @OUTPUT
        </store>
    </match>
</label>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 2022-08-22
    • 2017-05-18
    • 2020-08-07
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    相关资源
    最近更新 更多