JSON logstash 中的解析器忽略了数据?

JSON parser in logstash ignoring data?

我已经有一段时间了,我觉得 logstash 中的 JSON 过滤器正在为我删除数据。我最初遵循 https://www.digitalocean.com/community/tutorials/how-to-install-elasticsearch-logstash-and-kibana-elk-stack-on-ubuntu-14-04

中的教程

我做了一些改动,但基本上是一样的。我的神交过滤器看起来像这样:

uuid #uuid and fingerprint to avoid duplicates
{
    target => "@uuid"
    overwrite => true
}
fingerprint
{
    key => "78787878"
    concatenate_sources => true
}
grok #Get device name from the name of the log
{
    match => { "source" => "%{GREEDYDATA}%{IPV4:DEVICENAME}%{GREEDYDATA}" }
}

grok  #get all the other data from the log
{
    match => { "message" => "%{NUMBER:unixTime}..." }
}
date #Set the unix times to proper times.
{
    match => [ "unixTime","UNIX" ]
    target => "TIMESTAMP"
}


grok #Split up the message if it can
{
    match => { "MSG_FULL" => "%{WORD:MSG_START}%{SPACE}%{GREEDYDATA:MSG_END}" }
}
json 
{
    source => "MSG_END"
    target => "JSON"
}

所以我认为导致问题的是底部。我的 gork 东西应该都是正确的。当我 运行 此配置时,我看到 kibana 中的所有内容都正确显示,除了所有包含 JSON 代码的日志(并非所有日志都包含 JSON)。当我在没有 JSON 过滤器的情况下再次 运行 它时,它会显示所有内容。 我尝试使用 IF 语句,以便它仅 运行 包含 JSON 代码的 JSON 过滤器,但这并没有解决任何问题。

但是,当我仅将 IF 语句添加到 运行 特定 JSON 格式时(因此,如果 MSG_START = x、y 或 z,则 MSG_END 将有不同的 json 格式。在这种情况下,假设我只解析 z 格式),然后在 kibana 中我会看到所有包含 x 和 y JSON 格式的日志(尽管未解析) ,但它不会显示 z。所以我确定这一定与我使用 JSON 过滤器的方式有关。

此外,每当我想用新数据进行测试时,我都会开始清除 elasticsearch 中的旧数据,这样如果它有效,我就知道是我的 logstash 在工作,而不仅仅是来自 elasticsearch 的 运行 内存。我使用 XDELETE 'http://localhost:9200/logstash-*/' 完成了此操作。但是 logstash 不会在 elasticsearch 中创建新索引,除非我为 filebeat 提供新日志。我不知道这是否是另一个问题,只是觉得我应该提一下。

我希望一切都有意义。

编辑:我刚刚检查了 logstash.stdout 文件,事实证明它正在解析 json,但它只在 kibana 中显示带有“_jsonparsefailure”的东西Elastisearch 一定是出了问题。可能是。不知道,脑补一下:)

示例日志:

1452470936.88 1448975468.00 1 7 mfd_status 000E91DCB5A2 load {"up":[38,1.66,0.40,0.13],"mem":[967364,584900,3596,116772],"cpu":[1299,812,1791,3157,480,144],"cpu_dvfs":[996,1589,792,871,396,1320],"cpu_op":[996,50]}

MSG_START 是负载,MSG_END 是上例中之后的所有内容,所以 MSG_END 是我要解析的有效 JSON。

下面的日志中没有 JSON,但我的 logstash 将尝试解析 "Inf:" 之后的所有内容并发出“_jsonparsefailure”。

1452470931.56 1448975463.00 1 6 rc.app 02:11:03.301 Inf: NOSApp: UpdateSplashScreen not implemented on this platform

这也是我在 logstash 中的输出,因为我现在觉得这很重要:

elasticsearch 
{ 
    hosts => ["localhost:9200"] 
    document_id => "%{fingerprint}"
}
stdout { codec => rubydebug }

我问了这个问题: 稍后,它有更多相关信息,如果有人遇到与我类似的问题,也许是更好的答案,你可以查看 link.

我遇到了类似的问题,发现我的一些日志使用的是 UTC time/date 戳,而另一些则没有。 修复了代码以专门使用 UTC 并为我解决了问题。