我有以下形式的nginx错误日志: -
2015/09/30 22:19:38 [错误] 32317#0:*23 [lua] responses.lua:61:handler():Cassandra错误:UNIQUE检查错误:Cassandra错误:连接被拒绝,客户端:127.0. 0.1,server :, request:"POST/consumers/HTTP/1.1",host:"localhost:8001"
如上所述,我能够解析这些日志.
我的过滤器配置如下: -
filter { grok { match => { "message" => [ "%{DATESTAMP:mydate} \[%{DATA:severity}\] (%{NUMBER:pid:int}#%{NUMBER}: \*%{NUMBER}|\*%{NUMBER}) %{GREEDYDATA:mymessage}", "%{DATESTAMP:mydate} \[%{DATA:severity}\] %{GREEDYDATA:mymessage}", "%{DATESTAMP:mydate} %{GREEDYDATA:mymessage}" ] } add_tag => ["nginx_error_pattern"] } if ("nginx_error_pattern" in [tags]) { grok { match => { "mymessage" => [ "server: %{DATA:[request_server]}," ] } } grok { match => { "mymessage" => [ "host: \"%{IPORHOST:[request_host]}:%{NUMBER:[port]}\"" ] } } grok { match => { "mymessage" => [ "request: \"%{WORD:[request_method]} %{DATA:[request_uri]} HTTP/%{NUMBER:[request_version]:float}\"" ] } } grok { match => { "mymessage" => [ "client: %{IPORHOST:[clientip]}", "client %{IP:[clientip]} " ] } } grok { match => { "mymessage" => [ "referrer: \"%{DATA:[request_referrer]}\"" ] } } } }
mydate
有形式的日期: -
"mydate" => "15/09/30 22:19:38"
有人可以让我知道如何添加一个字段的log_day
日期(让我们说)2015-09-30
?
将时间/日期保存在类型字段中始终是个好主意date
.它使您可以使用Elasticsearch或Kibana 执行复杂范围查询.
您可以使用logstash的日期过滤器来解析日期.
过滤:
date { match => [ "mydate", "YY/MM/dd HH:mm:ss" ] }
结果:
"@timestamp" => "2015-09-30T20:19:38.000Z"
日期过滤器@timestamp
默认将结果放在字段中.
要避免默认映射到@timestamp
字段,请指定目标字段,如"log_day",如下所示:
过滤:
date { match => [ "mydate", "YY/MM/dd HH:mm:ss" ] target => "log_day" }
结果:
"log_day" => "2015-09-30T20:19:38.000Z"
一旦有了类型字段,date
就可以继续进行进一步的操作了.您可以使用date_formatter过滤器以特殊格式创建另一个日期字段.
date_formatter { source => "log_day" pattern => "YYYY-MM-dd" }
结果: "log_day" => "2015-09-30"