Logstash:如何在文件名中使用日期/时间作为导入的字段 [英] Logstash: How to use date/time in a filename as an imported field
本文介绍了Logstash:如何在文件名中使用日期/时间作为导入的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮忙?
谢谢
解决方案
使用 grok过滤器来提取日期和时间:
filter {
grok {
match => [
path,
^%{GREEDYDATA} / [^ /] + _%{INT:date} _%{TIME:time} \.txt $
]
}
}
根据什么而不是XXXXXX_XX,您可能更喜欢更严格的表达此外,GREEDYDATA不是很有效率。这可能会产生更好的表现:
filter {
grok {
match => [
path,^(?:/ [^ /] +)+ / [^ /] + _%{INT:date} _%{TIME:time} \.txt $
]
}
}
I have a bunch of log files that are named as 'XXXXXX_XX_yymmdd_hh:mm:ss.txt' - I need to include the date and time (separate fields) from the filename in fields that are added to Logstash.
Can anyone help?
Thanks
解决方案
Use a grok filter to extract the date and time:
filter {
grok {
match => [
"path",
"^%{GREEDYDATA}/[^/]+_%{INT:date}_%{TIME:time}\.txt$"
]
}
}
Depending on what goes instead of XXXXXX_XX you might prefer a stricter expression. Also, GREEDYDATA isn't very efficient. This might yield better performance:
filter {
grok {
match => [
"path", "^(?:/[^/]+)+/[^/]+_%{INT:date}_%{TIME:time}\.txt$"
]
}
}
这篇关于Logstash:如何在文件名中使用日期/时间作为导入的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文