input {
#stdin {
file {
type => "mysql-slow"
path => "/data/mysqldata/log/slow.log"
start_position => "end"
codec => multiline {
pattern => "# Time:"
negate => true
what => previous
auto_flush_interval => 5
}
}
}
filter {
# drop sleep events
grok {
match => { "message" => "SELECT SLEEP" }
add_tag => [ "sleep_drop" ]
tag_on_failure => [] # prevent default _grokparsefailure tag on real records
}
if "sleep_drop" in [tags] {
drop {}
}
grok {
match => { "message" => "(?m)^#\s+Time:\s+%{GREEDYDATA:Time}#\s+User@Host:\s+%{USER:user}\[[^\]]+\]\s+@\s+(?:(?<clienthost>\S*) )?\[(?:%{IPV4:clientip})?\]\s+Id:\s+%{NUMBER:row_id:int}.*#\s+Query_time:\s+%{NUMBER:query_time:float}\s+Lock_time:\s+%{NUMBER:lock_time:float}\s+Rows_sent:\s+%{NUMBER:rows_sent:int}\s+Rows_examined:\s+%{NUMBER:rows_examined:int}.*\s*(?:use %{DATA:database};\s*)?SET\s+timestamp=%{NUMBER:timestamp};\s*(?<sql>(?<action>\w+)\b.*;)\s*(?:\n#\s+Time)?.*$" }
match => {"user" => "\s+User@Host:\s+%{USER:user}\[[^\]]+\]\s+"}
}
date {
match => [ "timestamp", "UNIX" ]
remove_field => [ "timestamp" ]
}
}
output {
kafka {
bootstrap_servers => "ip:端口,ip:端口,ip:端口"
codec => json
topic_id => "mysql-slowlog"
}
stdout { codec => rubydebug }
}
logtash 解析slow.log
于 2022-08-22 15:41:41 首次发布