3

logstash过滤器(3)dissect

 2 years ago
source link: https://wakzz.cn/2019/01/17/logstash/%E8%BF%87%E6%BB%A4%E5%99%A8(3)dissect/
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.

logstash过滤器(3)dissect

祈雨的博客
2019-01-17

Dissect过滤器是一种拆分操作。与常规拆分操作(其中一个分隔符应用于整个字符串)不同,此操作将一组分隔符应用于字符串值。Dissect不使用正则表达式,速度非常快。

filter {
dissect {
mapping => {
"message" => "%{ts} %{+ts} %{+ts} %{src} %{} %{prog}[%{pid}]: %{msg}"
}
}
}

我们看到上面使用了和Grok很类似的%{}语法来表示字段,这显然是基于习惯延续的考虑。不过示例中%{+ts}的加号就不一般了。dissect 除了字段外面的字符串定位功能以外,还通过几个特殊符号来处理字段提取的规则:

  • %{+key}这个+表示,前面已经捕获到一个key字段了,而这次捕获的内容,自动添补到之前 key 字段内容的后面。
  • %{+key/2}这个/2表示,在有多次捕获内容都填到 key字段里的时候,拼接字符串的顺序谁前谁后。/2表示排第2位。
  • %{}是一个空的跳过字段。
  • %{?string}这个?表示,这块只是一个占位,并不会实际生成捕获字段存到事件里面。
  • %{?string} %{&string}当同样捕获名称都是string,但是一个?一个&的时候,表示这是一个键值对。

字段的->后缀例如%{function->},表示忽略它右边的填充,否则右边的多余填充将拆分到下一个字段中。

例如有填充->

%{id} %{function->} %{server}
f3000a3b Calc            machine-123
{
"server" => "machine-123",
"@timestamp" => 2019-01-17T15:04:01.694Z,
"function" => "Calc",
"@version" => "1",
"host" => "VM_0_10_centos",
"id" => "f3000a3b",
"message" => "f3000a3b Calc machine-123"
}

例如无填充->

%{id} %{function} %{server}
f3000a3b Calc            machine-123
{
"server" => " machine-123",
"@timestamp" => 2019-01-17T15:04:53.972Z,
"function" => "Calc",
"@version" => "1",
"host" => "VM_0_10_centos",
"id" => "f3000a3b",
"message" => "f3000a3b Calc machine-123"
}

参数 类型 是否必须 默认值

convert_datatype hash 否 {}

mapping hash 否 {}

convert_datatype

使用此设置intfloat数据类型进行转换。

filter {
dissect {
convert_datatype => {
"cpu" => "float"
"code" => "int"
}
}
}

mapping

解析事件。如果需要匹配换行符,使用单引号定义值,并在单引号内使用实际的换行符来匹配换行,如下:

filter {
dissect {
mapping => {
# 单引号中使用实际换行匹配换行
"message" => '"%{field1}" "%{field2}"
"%{description}"'
"description" => "%{field3} %{field4} %{field5}"
}
}
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK