作者:ll平安是福简单是快乐 | 来源:互联网 | 2023-05-19 14:58
ELK-logstash在搬运日志的时候会出现多行日志,普通的搬运会造成保存到ES中日志一条一条的保存,很丑,而且不方便读取,logstash-filter-multiline可以解决该问题。接下
ELK-logstash在搬运日志的时候会出现多行日志,普通的搬运会造成保存到ES中日志一条一条的保存,很丑,而且不方便读取,logstash-filter-multiline可以解决该问题。
接下来演示下问题:
普通日志如下:
2018-08-31 15:04:41.375 [http-nio-18081-exec-1] ERROR c.h.h.control.**-自定义的msg java.lang.ArithmeticException: / by zero at com.hikvision.hikserviceassign.control.ServiceMonitorManageController.reAssign(ServiceMonitorManageController.java:170) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) .....省略
记录到es的记录则是:
2018-08-31 15:04:41.375 [http-nio-18081-exec-1] ERROR c.h.h.control.**-自定义的msg 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]java.lang.ArithmeticException: / by zero 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]at com.hikvision.hikserviceassign.control.ServiceMonitorManageController.reAssign(ServiceMonitorManageController.java:170) 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]at java.lang.reflect.Method.invoke(Method.java:497) 2018-08-31 15:04:41.375 [http-nio-18081-exec-1]at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) .....省略
我们希望的结果肯定是这样的
接下来就是安装logstash-filter-multiline,进入logstash/bin目录下使用命令
$ ./logstash-plugin install logstash-filter-multiline
如果报错 certificate verify failed 则在install 后面加上 --no-verify
安装成功后,增加config,demo如下:
input { tcp { port => 4560 codec => json } } filter { multiline { pattern => "^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}" negate => true what => "previous" } } output { elasticsearch { hosts => "127.0.0.1:9200" index => "es-message-%{+YYYY.MM.dd}" } stdout { codec => rubydebug } }