[elk]logstash grok原理
logstash语法
http://www.ttlsa.com/elk/elk-logstash-configuration-syntax/
https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html
logstash grok原理
参考:
https://www.kancloud.cn/hanxt/elk/155901
https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html
正则表达式参考:
https://github.com/kkos/oniguruma/blob/master/doc/RE
grok的意思: (用感觉感知,而非动脑思考)to understand sth completely using your feelings rather than considering the facts
- 这个目录下有各种定义好的正则字段
/usr/local/logstash/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.1.2/patterns
或者直接访问这个:
https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns
$ ls /usr/local/logstash/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.1.2/patterns/
aws bind exim grok-patterns httpd junos maven mcollective-patterns nagios rails ruby
bacula bro firewalls haproxy java linux-syslog mcollective mongodb postgresql redis squid
如apache日志解析: logstash过滤解析apache日志
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}"}
}
}
logstash内置的pattern的定义(嵌套调用)
再举个例子
%{IP:client} 这里意思是: 用IP正则去匹配日志内容,匹配到的内容存储在key client里.
input {
file {
path => "/var/log/http.log"
}
}
filter {
grok {
match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }
}
}
output {
stdout { codec => rubydebug }
}
grok的remove_field
参考:
https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html
https://doc.yonyoucloud.com/doc/logstash-best-practice-cn/filter/grok.html
我们只需要request_time字段,默认仅match会读取message某字段赋给新字段,这样就造成了数据重复,为了解决这个问题,干掉message字段
input {stdin{}}
filter {
grok {
match => {
"message" => "\s+(?<request_time>\d+(?:\.\d+)?)\s+"
}
}
}
output {stdout{ codec => rubydebug }}
begin 123.456 end
{
"@version" => "1",
"host" => "ip-70.32.1.32.hosted.by.gigenet.com",
"@timestamp" => 2017-11-29T03:47:15.377Z,
"request_time" => "123.456",
"message" => "begin 123.456 end"
}
input {stdin{}}
filter {
grok {
match => {
"message" => "\s+(?<request_time>\d+(?:\.\d+)?)\s+"
}
remove_field => ["message"]
}
}
output {stdout{ codec => rubydebug }}
begin 123.456 end
{
"@version" => "1",
"host" => "ip-70.32.1.32.hosted.by.gigenet.com",
"@timestamp" => 2017-11-29T03:51:01.135Z,
"request_time" => "123.456"
}
自定义pattern
参考: https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html
可以写文件里,也可以直接指定,如上一个例子.
$ cat /var/sample.log
Jan 1 06:25:43 mailserver14 postfix/cleanup[21403]: BEF25A72965: message-id=<20130101142543.5828399CCAF@mailserver14.example.com>
$ cat ./patterns/postfix:
POSTFIX_QUEUEID [0-9A-F]{10,11}
input {
file {
path => "/var/sample.log"
}
}
filter {
grok {
patterns_dir => ["./patterns"]
match => { "message" => "%{SYSLOGBASE} %{POSTFIX_QUEUEID:queue_id}: %{GREEDYDATA:syslog_message}" }
}
}
output {
stdout { codec => rubydebug }
}
grok解析apache日志,并修改date格式
参考:http://blog.51cto.com/irow10/1828077 这里格式有问题,我修复了.
input {
stdin {}
}
filter {
grok {
match => { "message" => "%{IPORHOST:addre} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] \"%{WORD:http_method} %{NOTSPACE:request} HTTP/%{NUMBER:httpversion}\" %{NUMBER:status} (?:%{NUMBER:bytes}|-) \"(?:%{URI:http_referer}|-)\" \"%{GREEDYDATA:User_Agent}\"" }
remove_field => ["message"]
}
date {
match => [ "timestamp", "dd/MMM/YYYY:HH:mm:ss Z" ]
}
}
output {
stdout { codec => rubydebug }
}
192.168.10.97 - - [19/Jul/2016:16:28:52 +0800] "GET / HTTP/1.1" 200 23 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
{
"request" => "/",
"auth" => "-",
"ident" => "-",
"User_Agent" => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
"addre" => "192.168.10.97",
"@timestamp" => 2016-07-19T08:28:52.000Z,
"http_method" => "GET",
"bytes" => "23",
"@version" => "1",
"host" => "no190.pp100.net",
"httpversion" => "1.1",
"timestamp" => "19/Jul/2016:16:28:52 +0800",
"status" => "200"
}
grok在线检测
参考: http://grokdebug.herokuapp.com/
192.168.10.97 - - [19/Jul/2016:16:28:52 +0800] "GET / HTTP/1.1" 200 23 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
%{IPORHOST:addre} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] \"%{WORD:http_method} %{NOTSPACE:request} HTTP/%{NUMBER:httpversion}\" %{NUMBER:status} (?:%{NUMBER:bytes}|-) \"(?:%{URI:http_referer}|-)\" \"%{GREEDYDATA:User_Agent}\"
logstash mutate插件-给整个条目添加个字段
参考: https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html
input { stdin { } }
filter {
mutate { add_field => { "show" => "This data will be in the output" } }
}
output {
if [@metadata][test] == "Hello" {
stdout { codec => rubydebug }
}
}
sdf
{
"@version" => "1",
"host" => "ip-70.32.1.32.hosted.by.gigenet.com",
"show" => "This data will be in the output",
"@timestamp" => 2017-11-29T09:23:44.160Z,
"message" => "sdf"
}
logstash input添加字段-add_field
参考: http://www.21yunwei.com/archives/5296
input {
file {
path => "/logs/nginx/access.log"
type => "nginx"
start_position => "beginning"
add_field => { "key"=>"value"}
codec => "json"
}
}
output {
stdout{
codec => rubydebug{ }
}
}
logstash 5大插件--待了解
参考:
http://blog.51cto.com/irow10/1828077
https://segmentfault.com/a/1190000011721483
https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html
date插件可以对日期格式定义
mutate插件可以增删字段,可以改写字段格式
kv插件可...
使用上面的日志作为示例,使用 mutate 插件的 lowercase 配置选项,我们可以将“log-level”字段转换为小写:
filter {
grok {...}
mutate { lowercase => [ "log-level" ] }
}
kv filter 来指示 Logstash 如何处理它
kv插件可以拆解
filter {
kv {
source => "metadata"
trim => "\""
include_keys => [ "level","service","customerid",”queryid” ]
target => "kv"
}
}
[elk]logstash grok原理的更多相关文章
- ELK——Logstash 2.2 date 插件【翻译+实践】
官网地址 本文内容 语法 测试数据 可配置选项 参考资料 date 插件是日期插件,这个插件,常用而重要. 如果不用 date 插件,那么 Logstash 将处理时间作为时间戳.时间戳字段是 Log ...
- ELK logstash 处理MySQL慢查询日志(初步)
写在前面:在做ELK logstash 处理MySQL慢查询日志的时候出现的问题: 1.测试数据库没有慢日志,所以没有日志信息,导致 IP:9200/_plugin/head/界面异常(忽然出现日志数 ...
- logstash -grok插件语法介绍
介绍 logstash拥有丰富的filter插件,它们扩展了进入过滤器的原始数据,进行复杂的逻辑处理,甚至可以无中生有的添加新的 logstash 事件到后续的流程中去!Grok 是 Logsta ...
- logstash grok内置规则
logstash grok 内置正则 https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns USERNAME [ ...
- ELK(Logstash+Elasticsearch+Kibana)的原理和详细搭建
一. Elastic Stack Elastic Stack是ELK的官方称呼,网址:https://www.elastic.co/cn/products ,其作用是“构建在开源基础之上, Elast ...
- [elk]logstash的grok匹配逻辑grok+date+mutate
重点参考: http://blog.csdn.net/qq1032355091/article/details/52953837 logstash的精髓: grok插件原理 date插件原理 kv插件 ...
- ELK——为调试 Logstash Grok 表达式,安装 GrokDebuger 环境
内容 安装 RVM 安装 Ruby 和 Gems 安装 Rails 安装 jls-grok Ruby grok 解析 调试 grok 注意:不要用 root 执行以下操作. 用 logstash ...
- ELK学习实验011:Logstash工作原理
Logstash事件处理管道包括三个阶段:输入→过滤器→输出.输入会生成事件,过滤器会对其进行修改,输出会将它们发送到其他地方.输入和输出支持编解码器,使您可以在数据进入或退出管道时对其进行编码或解码 ...
- 【ELK】【docker】【elasticsearch】2.使用elasticSearch+kibana+logstash+ik分词器+pinyin分词器+繁简体转化分词器 6.5.4 启动 ELK+logstash概念描述
官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod ...
随机推荐
- linux安装Node(Centos)
步骤 1.打开node官网,找到node版本的下载地址 这里我找到的地址是: https://npm.taobao.org/mirrors/node/v8.2.1/node-v8.2.1-linux- ...
- Windows 10新增的6个快捷键:
Win+方向箭头:调整窗口贴边位置 Alt+Tab:切换窗口,按住不松时会有一个全新的界面方便你在不同的窗口间选择 Win+Tab:切换任务,这个松开后界面不会消失 Win+Ctrl+D:创建新的虚拟 ...
- 使用Busybox制作CRAMFS文件系统成功
转:http://www.360doc.com/content/11/1013/22/7775902_155877501.shtml 这几天在使用Busybox制作FS2410开发板的CRAMFS文件 ...
- JS的数组相关知识
创建数组方法一: var a1=new Array(5); console.log(a1.length); console.log(a1); //[] ,数组是空的 var a2=new Array( ...
- Windows系统下将目录挂载为一个磁盘并分配盘符
Windows系统下subst可以临时将目录分配一个盘符. 将路径与驱动器号关联. SUBST [drive1: [drive2:]path]SUBST drive1: /D drive1: 指定要分 ...
- 流畅的python第二章序列构成的数组学习记录
python内置序列类型概览 列表推导和生成器表达式 列表推导是构建列表的快捷方式,而生成器表达式可以用来创建其他任何类型的序列 列表推导的示例 >>>test = [i*2 for ...
- 详解vue静态资源打包中的坑与解决方案
本文主要解决: 1.vue-cli默认配置打包后部署至特定路径下静态资源路径错误问题; 2.静态资源打包使用相对路径后css文件引入图片路径错误问题. 一.问题 vue-cli 脚手架生成的默认打包配 ...
- Sense编辑器(Sense Editor)
Sense编辑器(Sense Editor) 学习了:https://blog.csdn.net/AbnerGong/article/details/50776605 Sense是一个方便的控制台,用 ...
- VB 在Visio 2010 以编程方式创建子进程图
在2010年Visio以编程方式创建子进程图 Office 2010 https://msdn.microsoft.com/en-us/library/gg650651.aspx 简介: 学习如 ...
- EXCEL在使用中,jar导入问题
报错:The type org.apache.poi.ss.usermodel.Workbook cannot be resolved. It is indirectly referenced fro ...