公号:码农充电站pro
主页:
Logstash 是一款免费开放的服务器端数据处理管道,能够从多个来源采集并转换数据,然后将数据发送到后端存储中。
Logstash 的处理流程分为三个阶段,这三个阶段合称为一个 Pipeline:
同时在输入/输出阶段可以对数据进行编解码处理。
用户通过配置文件告诉 Logstash 如何处理数据。
Logstash 的每个处理阶段都由一个或多个插件来完成,Logstash 目前支持 200 多个插件。
Logstash 的一些常用插件:
Logstash 在实际处理数据时,会先将输入数据放入队列中,作为缓冲。
Logstash Queue 分为两种:
queue.max_bytes
参数设置队列能存放的数据大小,默认为 1G。Logstash 通过 -e
参数在命令行指定一个 pipeline,通过 -f
参数指定一个配置文件。
通过 -e
在命令行指定一个 pipeline:
logstash -e "input{stdin{codec=>line}}output{stdout{codec=>rubydebug}}"
logstash -e "input{stdin{codec=>json}}output{stdout{codec=>rubydebug}}"
logstash -e "input{stdin{codec=>line}}output{stdout{codec=>dots}}"
数据示例,一个 movies.csv
文件:
movieId,title,genres
1,Toy Story (1995),Adventure|Animation|Children|Comedy|Fantasy
2,Jumanji (1995),Adventure|Children|Fantasy
3,Grumpier Old Men (1995),Comedy|Romance
4,Waiting to Exhale (1995),Comedy|Drama|Romance
5,Father of the Bride Part II (1995),Comedy
6,Heat (1995),Action|Crime|Thriller
7,Sabrina (1995),Comedy|Romance
8,Tom and Huck (1995),Adventure|Children
9,Sudden Death (1995),Action
10,GoldenEye (1995),Action|Adventure|Thriller
11,"American President, The (1995)",Comedy|Drama|Romance
12,Dracula: Dead and Loving It (1995),Comedy|Horror
13,Balto (1995),Adventure|Animation|Children
14,Nixon (1995),Drama
15,Cutthroat Island (1995),Action|Adventure|Romance
16,Casino (1995),Crime|Drama
17,Sense and Sensibility (1995),Drama|Romance
18,Four Rooms (1995),Comedy
19,Ace Ventura: When Nature Calls (1995),Comedy
20,Money Train (1995),Action|Comedy|Crime|Drama|Thriller
配置文件
input { # 定义 inputsfile { # 一个 file inputpath => "/path/movies.csv"start_position => "beginning"sincedb_path => "/dev/null"}
}filter { # 定义 filterscsv { # 一个 csv filterseparator => ","columns => ["id","content","genre"]}mutate { # 一个 mutate filtersplit => { "genre" => "|" }remove_field => ["path", "host","@timestamp","message"]}mutate { # 一个 mutate filtersplit => ["content", "("]add_field => { "title" => "%{[content][0]}"}add_field => { "year" => "%{[content][1]}"}}mutate { # 一个 mutate filterconvert => {"year" => "integer"}strip => ["title"]remove_field => ["path", "host","@timestamp","message","content"]}
}output { # 定义 outputselasticsearch { # 一个 elasticsearch outputhosts => "localhost:9200"index => "movies"document_id => "%{id}"}stdout {} # 一个 stdout output
}
Beats 是一个轻量型数据采集器,能够方便的与 Logstash 和 ElasticSearch 配合使用。
Beats 是基于 Golang 开发的。
Beats 官方提供了一些具体的 beats 供我们使用:
(本节完。)
欢迎关注作者公众号,获取更多技术干货。
本文发布于:2024-02-05 07:35:27,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170727513864524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |