我正在从我的Django应用程序将日志写入日志文件,从那里我将这些日志发送到elasticsearch。因为我也想分割字段,所以我在filebeat和elasticsearch之间使用logstash。
以下是示例日志字段:
2019-03-19 13:39:06 logfile INFO save_data {'field1':无,'时间':'13:39:06','移动':'9876543210','list_item':“[{'item1' :10,'item2':'path / to / file'}]“,'response':'{some_complicated_json}}','field2':'some data','date':'19 -03-2019', 'field3':'其他一些数据'}
我试着写一个GROK匹配模式,但所有字段都进入message
字段:
%{TIMESTAMP_ISO8601:temp_date}%{SPACE} %{WORD:logfile} %{LOGLEVEL:level} %{WORD:save_data} %{GREEDYDATA:message}
如何编写可以分解上述日志条目的GROK匹配模式。
我不知道你怎么能用Grok做到这一点,但我们这样做的方式是使用弹性json processor的ingest node pipeline。像这样的东西:
{
"my-log-pipeline": {
"description": "My log pipeline",
"processors": [{
"json": {
"field": "message",
"target_field": "messageFields"
}
}]
}
}
然后你只需要告诉你的源(filebeat / logstash)在摄取时使用这个管道。