通过fluentd解析nginx错误日志
我希望解析nginx错误日志文件,并将解析后的格式放入elasticsearch。我可以对access.log执行相同的操作,因为它接受log\u格式指令,但error.log不接受。我主要对以下示例错误日志感兴趣:通过fluentd解析nginx错误日志,nginx,error-log,Nginx,Error Log,我希望解析nginx错误日志文件,并将解析后的格式放入elasticsearch。我可以对access.log执行相同的操作,因为它接受log\u格式指令,但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:
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""}
有人能帮忙吗 @serut在这个Github问题的底部有一个非常好的解决方案:
#对前端日志使用NGINX解析
@类型分析器
密钥名称消息
@nginx型
#处理错误
@类型分析器
密钥名称消息
@类型regexp
表达式/^(?\d{4}\/\d{1,2}\/\d{1,2}\d{1,2}:\d{1,2}:\d{1,2})(?\[[^\s]+\])(?*)$/
时间键记录时间
时间\u格式%Y/%m/%d%H:%m:%S
@打印副本
@类型重新标记
@标签@输出
您找到解决方案了吗?
# 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>