我正在使用tomcat安装logstash并且有抓住java堆栈跟踪调用的问题,以下是我的配置
input {
udp {
type => "tomcat"
port => "514"
format => "plain"
}
}
filter{
multiline {
pattern => "(^.+Exception.*)|(^\s+at .+)|(^\s+... \d+ more)|(^\s*Caused by:.+)"
what => "previous"
}
}
以下是tomcat的示例日志
2014-03-24 19:08:53,246 [thread-pool8] ERROR org.apache.catalina.core.ContainerBase.[engine].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/error/error500.jsp]
org.apache.jasper.JasperException: java.lang.NullPointerException
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:338)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
at org.apache.jsp.error.error500_jsp._jspService(error500_jsp.java:266)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
... 21 more
我累了所有的组合,没有工作:(我不知道它对其他人有用..
我已经尝试过以及它也不起作用
pattern => "^%{TIMESTAMP_ISO8601}"
negate => true
以下是结果
filter received {:event=>{"message"=>"<139>2014-03-24 21:07:58,908 [] [] [thread-pool4] ERROR org.apache.catalina.core.ContainerBase.[engine].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/error/error500.jsp]\n", "@version"=>"1", "@timestamp"=>"2014-03-25T01:07:59.128Z", "type"=>"tomcat", "host"=>"10.3.68.22"}, :level=>:debug, :file=>"(eval)", :line=>"15"}
<139>2014-03-24 21:07:58,908 [] [] [thread-pool4] ERROR org.apache.catalina.core.ContainerBase.[engine].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/error/error500.jsp]
{:pattern=>"^%{TIMESTAMP_ISO8601} ", :match=>false, :negate=>true, :level=>:debug, :file=>"logstash/filters/multiline.rb", :line=>"160"}
filter received {:event=>{"message"=>"<139>org.apache.jasper.JasperException: java.lang.NullPointerException", "@version"=>"1", "@timestamp"=>"2014-03-25T01:07:59.131Z", "type"=>"tomcat", "host"=>"10.3.68.22"}, :level=>:debug, :file=>"(eval)", :line=>"15"}
<139>org.apache.jasper.JasperException: java.lang.NullPointerException {:pattern=>"^%{TIMESTAMP_ISO8601} ", :match=>false, :negate=>true, :level=>:debug, :file=>"logstash/filters/multiline.rb", :line=>"160"}
filter received {:event=>{"message"=>"<139> at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)", "@version"=>"1", "@timestamp"=>"2014-03-25T01:07:59.134Z", "type"=>"tomcat", "host"=>"10.3.68.22"}, :level=>:debug, :file=>"(eval)", :line=>"15"}
我使用udp协议在调试模式下运行logstash,<139>
中出现了一些奇怪的数字@messages
,请参阅以下调试输出,如果我使用nc
命令发送样本日志它可以工作但是以某种方式与tomcat syslog无法正常工作
{
"message" => "<139>2014-03-28 13:52:25,548 [] [] [thread-pool2] ERROR org.apache.catalina.core.ContainerBase.[engine].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/error/error500.jsp]\n",
"@version" => "1",
"@timestamp" => "2014-03-28T17:52:26.116Z",
"host" => "10.3.68.22"
}
{
"message" => "<139>org.apache.jasper.JasperException: java.lang.NullPointerException",
"@version" => "1",
"@timestamp" => "2014-03-28T17:52:26.134Z",
"host" => "10.3.68.22"
}
{
"message" => "<139> at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)",
"@version" => "1",
"@timestamp" => "2014-03-28T17:52:26.151Z",
"host" => "10.3.68.22"
}
{
"message" => "<139> at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)",
"@version" => "1",
"@timestamp" => "2014-03-28T17:52:26.166Z",
"host" => "10.3.68.22"
}
{
"message" => "<139> at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)",
"@version" => "1",
"@timestamp" => "2014-03-28T17:52:26.183Z",
"host" => "10.3.68.22"
}
答案 0 :(得分:1)
是否所有日志都以日期时间开头?
您可以将其用作模式。例如,
input {
stdin {
}
}
filter {
multiline {
pattern => "^%{TIMESTAMP_ISO8601} "
negate => true
what => previous
}
}
output {
stdout {debug => true}
}
此过滤器在我的日志上工作。希望它可以帮助你:))