logstash 使用

logstash主要是依靠强大的过滤插件,接下来研究和学习下过滤插件。

1. mutate插件

mutate插件几乎是使用最频繁的一个过滤插件,可以对字段进行各种操作,比如重命名、删除、替换、更新等。主要常用操作如下:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

convert #类型转换
gsub #字符串替换
split/join/merge #字符串切割、数组合并为字符串、数组合并为数组
rename #字段重命名
update/replace #字段内容更新或替换
remove_field #删除字段

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

1)remove_filed 

功能:删除字段。

删除字段例子:

[root@localhost logstash]# cat /usr/local/logstash/config/nginxtest.conf
input {
beats {
port => "5044"
}
}

filter {
mutate {
remove_field => ["input","agent","ecs","log","@version"]

}

}

output {
elasticsearch {
hosts => ["http://192.168.146.181:9200"]
index => "tomcat-access-log-%{+YYYY.MM.dd}"
user => "elastic"
password => "123456"

}
stdout {
codec => json_lines
}
}

2)rename

功能:字段重新命名。

[root@localhost logstash]# cat /usr/local/logstash/config/nginxtest.conf
input {
beats {
port => "5044"
}
}

filter {
mutate {
remove_field => ["input","agent","ecs","log","@version"]
rename => ["host","hostryb"]

}

}

output {
elasticsearch {
hosts => ["http://192.168.146.181:9200"]
index => "tomcat-access-log-%{+YYYY.MM.dd}"
user => "elastic"
password => "123456"

}
stdout {
codec => json_lines
}
}

 

posted on 2022-08-30 11:22  永远的大空翼  阅读(193)  评论(0编辑  收藏  举报