我有一个用于webbapp的java日志文件,该文件是使用SLF4J,Logback和logstash-logback-encoder创建的,用于logstash 1.4.2。虽然各种配置已成功从日志中检索数据,但实际上没有一个配置返回正确的json。根据我读过的每个指南,以下配置应该有效,但不是。
日志样本
{"@timestamp":"2015-02-04T00:03:43.178+00:00","@version":1,"message":"No token was found, creating new token.","logger_name":"com.company.ws.service.AuthService","thread_name":"ajp-nio-8009-exec-10","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.199+00:00","@version":1,"message":"5f8aaebd-4274-4f00-a2eb-7b2350231ef2","logger_name":"com.company.jaxrs.provider.ParamTest","thread_name":"ajp-nio-8009-exec-1","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.199+00:00","@version":1,"message":"36","logger_name":"com.company.jaxrs.provider.ParamTest","thread_name":"ajp-nio-8009-exec-1","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.218+00:00","@version":1,"message":"5f8aaebd-4274-4f00-a2eb-7b2350231ef2","logger_name":"com.company.jaxrs.provider.ParamTest","thread_name":"ajp-nio-8009-exec-3","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.218+00:00","@version":1,"message":"36","logger_name":"com.company.jaxrs.provider.ParamTest","thread_name":"ajp-nio-8009-exec-3","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.218+00:00","@version":1,"message":"135a2411-ac96-492b-94e9-df6b65974f9f","logger_name":"com.company.jaxrs.provider.ParamTest","thread_name":"ajp-nio-8009-exec-3","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.218+00:00","@version":1,"message":"36","logger_name":"com.company.jaxrs.provider.ParamTest","thread_name":"ajp-nio-8009-exec-3","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
{"@timestamp":"2015-02-04T00:03:43.219+00:00","@version":1,"message":"is string","logger_name":"com.company.jaxrs.parameter.RestParameterFactory","thread_name":"ajp-nio-8009-exec-3","level":"INFO","level_value":20000,"HOSTNAME":"development.company.com"}
input {
lumberjack {
port => 5000
type => "logs"
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
}
filter {
if [type] == "syslog" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST$
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
syslog_pri { }
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
else if [type] == "json" {
source => "message"
}
output {
elasticsearch { host => localhost }
stdout { codec => rubydebug }
}
{
"network": {
"servers": [ "utility.company.com:5000" ],
"timeout": 15,
"ssl ca": "/etc/pki/tls/certs/logstash-forwarder.crt"
},
"files": [
{
"paths": ["/company/apache-tomcat-8.0.9/logs/vhost1.log"],
"fields": { "type": "json" }
}
]
}
我在Kibana能够获得的最佳回报(如果有任何回报)看起来像这样:
{
"_index": "logstash-2015.02.04",
"_type": "json",
"_id": "8l1rDYTZSceBCklFxAuvAg",
"_score": null,
"_source": {
"message": "{\"@timestamp\":\"2015-02-04T06:03:18.794+00:00\",\"@version\":1,\"message\":\"Attribute Count 1\",\"logger_name\":\"com.company.ws.service.ReportSearchService\",\"thread_name\":\"ajp-nio-8009-exec-1\",\"level\":\"INFO\",\"level_value\":20000,\"HOSTNAME\":\"development.company.com\"}",
"@version": "1",
"@timestamp": "2015-02-04T06:13:10.685Z",
"type": "json",
"file": "/company/apache-tomcat-8.0.9/logs/vhost1.log",
"host": "development.company.com",
"offset": "4907321"
},
"sort": [
1423030390685,
1423030390685
]
}
显然,json转换逻辑运行不正常,所以我缺少什么?
使用this guide配置ELK堆栈。
答案 0 :(得分:0)
这看起来非常可疑:
else if [type] == "json" {
source => "message"
}
如果这确实是您的配置文件中的内容,我不明白为什么Logstash不会抱怨它。这应该是它的样子:
else if [type] == "json" {
json {
source => "message"
}
}
或者,如果通过lumberjack协议接收的所有消息都是JSON消息,则可以使用json编解码器为您的伐木工输入。