简体   繁体   English

java异常的GROK模式

[英]GROK patterns for java exception

I have a couple of questions :我有一些问题 :

  1. I tried to use a custom tag like mentioned in https://discuss.elastic.co/t/logstash-configuration-with-custom-patterns/141352 but could not get much help.我尝试使用https://discuss.elastic.co/t/logstash-configuration-with-custom-patterns/141352 中提到的自定义标签,但无法获得太多帮助。

  2. I want to match for multiple patterns like one for normal log and one for exception log.我想匹配多种模式,例如一种用于正常日志,一种用于异常日志。

     ^%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level}\\s*%{JAVACLASS:class}\\.%{WORD:method}\\s-\\s%{GREEDYDATA:log}$
  3. We also have java patterns that are inbuilt but i was unable to find them by search, so are they compiled and stored ?我们也有内置的 Java 模式,但我无法通过搜索找到它们,那么它们是否被编译和存储? I wanted to add my patterns in the same file so that i don't get any issues.我想在同一个文件中添加我的模式,这样我就不会遇到任何问题。

Is there another way to get this done apart from writing in the patterns folder?除了在模式文件夹中写入之外,还有其他方法可以完成此操作吗?

I'm working with Elastic Stack 7.6.2.我正在使用 Elastic Stack 7.6.2。

Concatenate stack trace lines into one log entry将堆栈跟踪行连接成一个日志条目

I'm sending logs to Logstash through Filebeat.我正在通过 Filebeat 将日志发送到 Logstash。 I have to configure Filebeat so it treats the whole stack trace as one entry.我必须配置 Filebeat,以便它将整个堆栈跟踪视为一个条目。 I'm using multiline as described in Examples of multiline configuration :我正在使用multiline 行配置示例中所述的多行

#filebeat.yml
filebeat:
  inputs:
    - type: log
      …
      multiline:
        pattern: '^[[:space:]]+(at|\.{3})[[:space:]]+\b|^Caused by:'
        match: after
output:
  logstash:
    hosts: ["logstash:5044"]

Handle two types of log entries处理两种类型的日志条目

In my logstash.conf file I have a filter matching against:在我的logstash.conf文件中,我有一个匹配的过滤器:

  • a regular Spring Boot log entry (not covered here) eg:一个常规的 Spring Boot 日志条目(这里没有介绍),例如:
    2020-05-12 08:31:26.530  INFO 10197 --- [SpringContextShutdownHook] o.s.s.c.ThreadPoolTaskExecutor           : Shutting down ExecutorService 'applicationTaskExecutor'
  • a Java exception eg: Java 异常,例如:
    java.lang.IllegalArgumentException: Exception message
        at in.keepgrowing.springbootlog4j2scaffolding.SpringBootLog4j2ScaffoldingApplication.main(SpringBootLog4j2ScaffoldingApplication.java:14) [classes/:?]
        at com.example.myproject.Author.getBookIds(Author.java:38)
        at com.example.myproject.Bootstrap.main(Bootstrap.java:14)
    Caused by: java.lang.NullPointerException
        at com.example.myproject.Book.getId(Book.java:22)
        at com.example.myproject.Author.getBookIds(Author.java:35)
        ... 1 more

Because I haven't listed multiple patterns in one match , every entry is being checked against both matches (I think the break_on_match is not working in this case).因为我没有在一场match列出多个模式,所以每个条目都针对两个比赛进行检查(我认为break_on_match在这种情况下不起作用)。 As a result the _grokparsefailure tag is added to all entries.结果_grokparsefailure标记被添加到所有条目。 To remove this tag I have to know that a particular entry was successfuly matched by one pattern - the stacktrace or spring_boot_log tag will be present in such a case.要删除此标记,我必须知道特定条目已成功与一个模式匹配 - 在这种情况下将出现stacktracespring_boot_log标记。 Therefore I can safely delete the _grokparsefailure tag for entries that have my tag:因此,我可以安全地删除带有我的标签的条目的_grokparsefailure标签:

# logstash.conf
…
filter {
    grok {
        match => { "message" => "%{JAVACLASS:exception}:\s%{GREEDYDATA:stacktrace}" }
        add_tag => [ "stacktrace" ]
        }
    grok {
        match => { "message" => "%{TIMESTAMP_ISO8601:log_timestamp}…" }
        add_tag => [ "spring_boot_log" ]
        }
    if "stacktrace" in [tags] or "spring_boot_log" in [tags] {
            mutate {
                remove_tag => ["_grokparsefailure"]
                }
    }
}
…

Below you can see the screenshot from my ElasticHQ showing how an example stack trace was parsed.您可以在下面看到来自我的 ElasticHQ 的屏幕截图,其中显示了示例堆栈跟踪是如何解析的。 There are two parts: exception and stacktrace , and my custom tag in the tags array:有两个部分: exceptionstacktrace ,以及我在tags数组中的自定义标记: 在此处输入图片说明

Useful links:有用的链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM