【问题标题】:Logstash not writing to ElasticsearchLogstash 未写入 Elasticsearch
【发布时间】:2014-09-29 21:28:06
【问题描述】:

当消息属性包含分层消息数据时,我遇到了一个错误,即 Logstash 没有将解析文档写入 elasticsearch。当消息属性不包含分层数据时,它可以正常工作。以下是一些有效的数据:

{
  "Layer": "Web",
  "DurationMilliseconds": 65,
  "CreatedOn": "2014-09-29T20:44:40.5380157Z",
  "Enviroment": "Dev",
  "AssemblyName": "LoggingTest",
  "ClassName": "HomeController",
  "MethodName": "Index",
  "WindowsIdentity": "XXX\\YYY",
  "SessionId": "wrm11rken3lc442humrxyhoe",
  "Application": "LoggingTest",
  "Machine": "XXX.XXX.XXX.XXX",
  "Browser": "Chrome",
  "@version": "1",
  "@timestamp": "2014-09-29T20:45:38.432Z",
  "type": "Perf"
}

以下是一些不起作用的数据:

{
  "Enviroment": "Dev",
  "Level": "Fatal",
  "CreatedOn": "2014-09-29 20:46:30.5042",
  "WindowsIdentity": "XXX\\XXX",
  "Application": "LoggingTest",
  "UserAgent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36",
  "SessionId": "wrm11rken3lc442humrxyhoe",
  "URL": "/LoggingTest/jsnlog.logger",
  "UserAddress": "XXX.XXX.XXX.XXX",
  "Message": {
    "stack": "TypeError: undefined is not a function\n    at Log (http://XXX/LoggingTest/:58:16)\n    at HTMLInputElement.onclick (http://XXX/LoggingTest/:66:141)",
    "message": "undefined is not a function",
    "name": "TypeError",
    "logData": "JS Fatal Exception"
  },
  "@version": "1",
  "@timestamp": "2014-09-29T20:46:30.331Z",
  "type": "JS"
}

这是我的 logstash 配置:

input {
    redis {
        host => "127.0.0.1"
        type => "JS"
        data_type => "list"
        key => "JS"
    }
}

filter
{
    json{ source => "message"}
}

output {
    stdout { codec => rubydebug}

    elasticsearch { 
        host => localhost 
        index => dev
    }
}

当我通过第一项运行上述代码时,第一项成功解析到我的弹性搜索中,但第二项消失了,logstash 没有写入任何错误。

【问题讨论】:

    标签: elasticsearch logstash


    【解决方案1】:

    我对您的日志进行了更改。这是我的配置,

    input {
        stdin{}
    }
    
    filter{
        json{ source => "message"}
    }
    
    output {
        stdout {
                codec => "rubydebug"
        }
        elasticsearch {
                host => localhost
                cluster => "BENLIM"
        }
    }
    

    通过这个配置,当我将不工作的日志发送到logstash时,它可以解析并输出到elasticsearch。供参考。

    【讨论】:

    • 我可以从标准输出中得知消息正在从 Redis 队列中检索并被解析为有效的 JSON。我尝试将集群名称添加到 elasticsearch 输出,但没有解决问题。第一个仍然添加到 elasticsearch,第二个没有。
    • 我能够通过将子消息解析成单独的字段而不是保持它们嵌套来完成这项工作
    猜你喜欢
    • 2015-08-27
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    相关资源
    最近更新 更多