Logstash-Beats入门
source link: https://codeshellme.github.io/2021/03/es-logstash-beats/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
公号:码农充电站pro
Logstash 是一款免费开放的服务器端数据处理管道,能够从多个来源采集并转换数据,然后将数据发送到后端存储中。
1,Logstash 处理流程
Logstash 的处理流程分为三个阶段,这三个阶段合称为一个 Pipeline:
同时在输入/输出阶段可以对数据进行编解码处理。
用户通过配置文件告诉 Logstash 如何处理数据。
2,Logstash 插件
Logstash 的每个处理阶段都由一个或多个插件来完成,Logstash 目前支持 200 多个插件。
Logstash 的一些常用插件:
- Inputs 阶段:
- stdin、file
- beats、log4j
- elasticsearch、jdbc、kafka、rabbitmq、redis
- jmx、http、websocket、tcp、udp
- Filters 阶段:
- mutate
- metrics
- Outputs 阶段:
- email、pageduty
- elasticsearch、kafka、mongodb
- http、tcp、websocket
- 编码处理:
- line、multiline
- json、dots
3,Logstash Queue
Logstash 在实际处理数据时,会先将输入数据放入队列中,作为缓冲。
Logstash Queue 分为两种:
- Memory Queue(默认方式):放在内存中;如果意外宕机数据会丢失。
- Persistent Queue:会进行持久化;意外宕机数据不会丢失。
- 可通过
queue.max_bytes
参数设置队列能存放的数据大小,默认为 1G。
- 可通过
4,Logstash 使用示例
Logstash 通过 -e
参数在命令行指定一个 pipeline,通过 -f
参数指定一个配置文件。
4.1,-e 参数
通过 -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}}"
4.2,-f 参数
数据示例,一个 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
配置文件 logstash.conf
:
input { # 定义 inputs
file { # 一个 file input
path => "/path/movies.csv"
start_position => "beginning"
sincedb_path => "/dev/null"
filter { # 定义 filters
csv { # 一个 csv filter
separator => ","
columns => ["id","content","genre"]
mutate { # 一个 mutate filter
split => { "genre" => "|" }
remove_field => ["path", "host","@timestamp","message"]
mutate { # 一个 mutate filter
split => ["content", "("]
add_field => { "title" => "%{[content][0]}"}
add_field => { "year" => "%{[content][1]}"}
mutate { # 一个 mutate filter
convert => {"year" => "integer"}
strip => ["title"]
remove_field => ["path", "host","@timestamp","message","content"]
output { # 定义 outputs
elasticsearch { # 一个 elasticsearch output
hosts => "http://localhost:9200"
index => "movies"
document_id => "%{id}"
stdout {} # 一个 stdout output
5,Beats 介绍
Beats 是一个轻量型数据采集器,能够方便的与 Logstash 和 ElasticSearch 配合使用。
Beats 是基于 Golang 开发的。
Beats 官方提供了一些具体的 beats 供我们使用:
(本节完。)
欢迎关注作者公众号,获取更多技术干货。
Recommend
-
96
你应该了解的5个 Logstash Filter 插件 原文:5 Logstash Filter Plugins You Need to Know About 译者:
-
136
Beats - The Lightweight Shippers of the Elastic Stack The Beats are lightweight data shippers, written in Go, that you install on your servers to capture all sorts of operational...
-
67
一、前言1、ELK简介ELK是Elasticsearch+Logstash+Kibana的简称 ElasticSearch是一个基于Lucene的分布式全文搜索引擎,提供 RESTful API进行数据读写 Logstash是一个收集,处理和转发事件和日志消息的工具 Kibana是Elasticsearch的开源数据可视化插件,...
-
63
logstash实现nginx日志status报警
-
47
中文官网:https://www.elastic.co/cn/products/logstashlogstash理念:数据输入》数据加工》数据输出rpm包安装即可,需要java依赖简单的启动测试:bin/logstash -e 'input{stdin{}}output{stdout{codec=>rubydebug}}'(-e 加载配置文件)log...
-
71
filebeat ELK 数据收集的者,logstash 是数据的传输和过滤者,同时logstash还可以通过过滤关键字,达到告警功能
-
64
filebeat 指定tags,logstash filter 过滤出自己想要的日志格式
-
61
一、logstash Logstash: 是一个灵活的数据传输和处理系统,在beats出来之前,还负责进行数据收集。Logstash的任务,就是将各种各样的数据,经过配置转化规则,统一化存入Elasticsearch。使用Ruby开发的Logstash在灵活性上,非...
-
26
Logstash 入门 Logstash 是什么 Logstash 就是一个开源的数据流工具,它会做三件事: 从数据源拉取数据 对数据进行过滤、转换等处理 将处理后的数据写入目标地 ...
-
13
参考官方网站 Logstash 二、测试安装 首先,让我们通过运行最基本的Logstash管道来测试Logstash安装。 Logstash管道具有两个必需元素input和output,以及一个可选元素fi...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK