您的位置:首页 > 其它

Logstash配置——变量的使用

2017-07-24 00:00 253 查看
摘要: 使用Logstash的grok filter plugin可以定义变量,从而可以实现通过变量定义输出的文件名等。

前置条件:Linux Logstash 5.5.0(其他版本请查阅一下文档)

使用logstash把日志从文件输出到文件,根据输入文件的路径,确定输出文件的文件名。配置如下:

input {
stdin{}
file {
path => "/tmp/app1/instance1/access.log"
start_position => "beginning"
}
}
filter {
grok {
match => {
"path" => "(?<app_name>app\d?)"
}
}
grok {
match => {
"path" => "(?<app_instance>instance\d?)"
}
}
grok {
match => {
"message" => "^(?<request_time>\d{4}-\d{2}-\d{2})\t"
}
}

}
output {
stdout {
codec => "json"
}
file {
codec => "json"
path => "/tmp/%{app_name}_%{app_instance}_%{request_time}.olog"
}
}

如果不想用多个grok,可以配置一个grok,然后将属性break_on_match设置为false。

grok {

break_on_match => false
match => {
"path" => "(?<app_name>app\d?)"

"path" => "(?<app_instance>instance\d?)"

"message" => "^(?<request_time>\d{4}-\d{2}-\d{2})\t"
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  logstash grok 变量
相关文章推荐