gpt4 book ai didi

logstash - 如何在Logstash中放置空行

转载 作者:行者123 更新时间:2023-12-04 08:52:02 26 4
gpt4 key购买 nike

在我的logstash日志中,有时会有空行或只有空格的行。

为了删除空行,我创建了一个dropemptyline过滤器文件

# drop empty lines
filter {
if [message] =~ /^\s*$/ {
drop { }
}
}

但是空行过滤器无法按预期工作,主要是因为此特定过滤器位于其他过滤器链中,此后又有过滤器。
00_input.conf
05_syslogfilter.conf
06_dropemptylines.conf
07_classifier.conf

因此,我认为我的特定过滤器将是唯一可行的,但不是。
2015-02-11 15:02:12.347  WARN 1 --- [tp1812226644-23] o.eclipse.jetty.servlet.ServletHandler   : 

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]

我的问题是如何退出所有过滤器并直接进入输出?

最佳答案

您可以使用grok过滤器完全忽略空行,

%{GREEDYDATA:1st}(\n{1,})%{GREEDYDATA:2nd}

它会产生,
{
"1st": [
[
"2015-02-11 15:02:12.347 WARN 1 --- [tp1812226644-23] o.eclipse.jetty.servlet.ServletHandler : "
]
],
"2nd": [
[
"org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]"
]
]
}

或更优雅的方式
(?m)%{GREEDYDATA:log}

输出:
{
"log": [
[
"2015-02-11 15:02:12.347 WARN 1 --- [tp1812226644-23] o.eclipse.jetty.servlet.ServletHandler : \n\n\n\norg.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]"
]
]
}

关于logstash - 如何在Logstash中放置空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28457936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com