input { file { path => "/data/mysqldata/mysql-slow.log" type => "mysql-slow-log" start_position =
input { file { path => "/data/mysqldata/mysql-slow.log" type => "mysql-slow-log" start_position => "beginning" codec => multiline { pattern => "^# User@Host:" negate => true what => previous } }}filter { grok { match => { "message" => "(?m)^#/s+User@Host:/s+%{USER:user}/[[^/]]+/]/s+@/s+(?:(?<clientip>/S*) )?/[(?:%{IPV4:clientip})?/]/s+Id:/s+%{NUMBER:row_id:int}/n#/s+Query_time:/s+%{NUMBER:Query_time:float}/s+Lock_time:/s+%{NUMBER:lock_time:float}/s+Rows_sent:/s+%{NUMBER:Row_sent:int}/s+Rows_examined:/s+%{NUMBER:Rows_examined:int}/n/s*(?:use %{DATA:database};/s*/n)?SET/s+timestamp=%{NUMBER:timestamp};/n/s*(?<sql>(?<action>/w+)/b.*;)/s*(?:/n#/s+Time)?.*$" } remove_field => [ "message" ] } mutate { replace => [ "host" , "主机地址" ] add_field => [ "nsCode", "项目名称" ] add_field => [ "envCode", "环境名称" ] add_field => [ "mysqlType", "数据库类型" ] gsub => [ "sql", "/n# Time: /d+/s+/d+:/d+:/d+", "" ] }}output { if [type] == "mysql-slow-log" { elasticsearch { hosts => "es地址:端口" index => "%{type}-%{+YYYY.MM.dd}" } } }