date插件mongodb
filter { date { match => ["create_at", "yyyy-MM-dd HH:mm:ss,SSS", "UNIX"] target => "@timestamp" locale => "cn" } } filter{ date{ match => ["fieldName", "yyyyMMdd","yyyy-MM-dd"] target => "fieldName1" timezone => "Asia/Shanghai" } }
match
第一个参数是字段名。
第二个参数是格式化模式
第三个参数是要转换的时间格式,以下表ruby
ISO8601 - 应解析任何有效的ISO8601时间戳,如2011-04-19T03:44:01.103Z UNIX - 将解析float或int值,表示自1346149001.132以及1326149001.132以来的秒数(以秒为单位) UNIX_MS - 将分析int值表示unix时间(以毫秒为单位),如1366125117000 TAI64N - 将解析tai64n时间值 #输入 input { file { path => ["文件路径"] #自定义类型 type => "自定义" start_position => "beginning" } } #过滤器 filter{ #去除换行符,只对string类型有效 #去除反斜杠和单引号 mutate{ gsub => [ "message", "\r", "" ] , gsub => ["message", "[\\]", "/", "message","'", "" ] } #逗号分割 mutate { split => ["message",","] } #分割后,字段命名与赋值 mutate{ add_field => { "id" => "%{[message][0]}" "mydate" => "%{[message][1]}" "user" => "%{[message][2]}" "pc" => "%{[message][3]}" "to_user" => "%{[message][4]}" "cc" => "%{[message][5]}" "bcc" => "%{[message][6]}" "from_user" => "%{[message][7]}" "size" => "%{[message][8]}" "attachments" => "%{[message][9]}" "content" => "%{[message][10]}" } } #字段里的日期识别,以及时区转换,生成date date { match => [ "mydate", "MM/dd/yyyy HH:mm:ss" ] target => "date" locale => "en" timezone => "+00:00" } #删除无用字段 mutate { remove_field => "message" remove_field => "mydate" remove_field => "@version" remove_field => "host" remove_field => "path" } #将两个字段转换为整型 mutate{ convert => { "size" => "integer" } convert => { "attachments" => "integer" } } } #输出,输出目标为es output { #stdout { codec => rubydebug } elasticsearch { #目标主机 host => ["目标主机1","目标主机2"] #协议类型 protocol => "http" #索引名 index =>"自定义" } }
mongodbelasticsearch
./logstash-plugin install logstash-output-mongodb output { mongodb { collection => "base" database => "fragment" uri => "mongodb://192.168.199.7:27017" } }