小编典典

Logstash中的JSON解析器会忽略数据吗?

elasticsearch

我已经来了一段时间,感觉好像logstash中的JSON过滤器正在为我删除数据。我最初是从https://www.digitalocean.com/community/tutorials/how-
to-install-elasticsearch-logstash-and-kibana-elk-stack-on-
ubuntu-14-04跟随该教程的

我进行了一些更改,但基本相同。我的grok过滤器如下所示:

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"
}

我认为,导致问题的根源是底部。我的古怪的东西应该都是正确的。当我运行此配置时,我看到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-*/'。但是除非我为filebeat提供新日志,否则logstash不会在elasticsearch中建立新索引。我不知道这是否是另一个问题,只是想我应该提一下。

我希望一切都有意义。

编辑:我只是检查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未在此平台上实现

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

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

阅读 412

收藏
2020-06-22

共1个答案

小编典典

我问了这个问题:json解析器的Logstash输出稍后不会发送到Elasticsearch,并且它具有更多相关的信息,如果有人遇到与我类似的问题,也许可以提供一个更好的答案,您可以查看该链接。

2020-06-22