ELK 读书笔记
第一部分 Logstash
Logstash
1.插件配置
2.场景示例
3.性能与监控
4.扩展方案
bin/logstash -e '
input{
stdin{}
}
outpu{
stdout{
codec=>ruby
}}'
Logstash 自己的DSL
区域,注视,数据类型(布尔值,字符串数值,数组,哈希),条件判断,字段引用。
1. 区段 section
logstash使用{}定义区段。
2. 数据类型
bool
debug => true
字符串 string
host => "hostname"
数值 number
port => 514
数组 array
match => ["datetime","UNIX","ISO8601"]
哈希 hash
options = > {
key1 => "value1",
key2 => "value2"
}
3. 字段引用
Logstash 配置使用字段引用 只需要使用[]就行。
比如 [geoip][location][0]
4. 条件判断
equlity,etc: ==,!=,<,>,<=,>=
regexp: =~, !~
inclusion: in ,not in
boolean: and,or,nand,xor
unary: !()
例子:
if "_grok" not in [tags] {}
eles if [status] !~ /^2\d\d/ and [url] == "/noc.gif"{}
else {}
1.2 命令行参数
logstash提供了shell命令行方便快速运行。参数如下:
-e
"执行",我们在 "hello world" 的时候已经用过这个参数了.
--config 或 -f
bin/logstash -f agent.conf
--configtest 或 -t
测试,用来测试Logstash读取到的配置文件语法是否能够正常解析。
bin/logstash -t agent.conf
--log 或 -l
bin/logstash -f logs/agent.log
输出日志
--pipeline-workers 或 -w
运行filter 和 output的线程数量,默认是CPU核数。
--pipeline-batch-size 或 -b
--pipeline-batch-delay 或 -u
打包批量日志的时候的等待时间,ms,默认是5ms
--pluginpath 或 -P
指定插件路径
--verbose
调试模式
--debug 或 -vv
更多调试日志
1.3 配置文件示例
logstash.yml
pipeline:
workers: 24
batch:
size: 125
delay: 5
1.4 插件安装
所有插件都被单独拆分成gem包。这样所有的插件都可以独立更新。
bin/logstash-plugin -h
bin/logstash-plugin install /path/to/logstash-filter-crash.gem
1.5 长期运行
logstash如何长期运行
这里介绍4种方法
1. 标准的service方式。
2. nohup 方式
nohup command &
3. screen 方式
4. 最推荐的daemontools方式
比如 supervisord为例。
yum -y install supervisord --enablerepo=epel
第二章 插件配置
主要插件有:
1.输入插件。 基于 shipper端的场景,主要有 STDIN,TCP,File等插件
2.编解码插件。 最常用的有json和multiline插件
3.过滤器插件。 名为过滤器,其实各种数据裁剪,和计算都在这类插件完成。 logstash最强大的一环。比如: grok,date,mutate,ruby,metrics等插件的妙用。
4.输出插件。 logstash可以输出到各种找那个不同的地方,比如HDFS,Nagios,ES等