利用filebeat推送mysql慢查询日志

介绍通过利用filebeat来收集mysql的慢查询日志,logstash解析后推送到elasticsearch,并创建自定义的索引,最终通过kibana进行web展示。

环境介绍:
操作系统版本:CentOS Linux release 7.3.1611 (Core) 64bit
Mysql版本: 5.6.28
Logstash版本: logstash 5.3.0
Elasticsearch版本:elasticsearch 5.3.0
Kibana版本:Kibana 5.3.0
Java版本:1.8.0_121

Mysql版本: 5.6.28及mysql慢日志

# Time: 170420 1:41:04
# User@Host: root[root] @ [192.168.1.178] Id: 2238895756
# Query_time: 3.887598 Lock_time: 0.000099 Rows_sent: 19 Rows_examined: 19
SET timestamp=1492623664;
select * from users_test;
# User@Host: root[root] @ [192.168.1.178] Id: 2238895828
# Query_time: 3.161184 Lock_time: 0.000150 Rows_sent: 28 Rows_examined: 28
SET timestamp=1492623664;
select * from users_test;
# Time: 170420 1:41:12

filebeat及logstash配置

filebeat.yml配置文件

filebeat:
prospectors:
-
paths:
- /data/mysql/xxx-slow.log
document_type: mysqlslow
multiline:
pattern: "^# User@Host: "
negate: true
match: after
registry_file: /var/lib/filebeat/registry
output:
logstash:
hosts: ["192.168.1.63:5044"]

logstash.conf

input {
beats {
port => 5044
}
}
filter {

grok {
match => [ "message", "(?m)^# User@Host: %{USER:query_user}\[[^\]]+\] @ (?:(?<query_host>\S*) )?\[(?:%{IP:query_ip})?\]\s*Id: %{NUMBER:id:int}\s+# Query_time: %{NUMBER:query_time:float}\s+Lock_time: %{NUMBER:lock_time:float}\s+Rows_sent: %{NUMBER:rows_sent:int}\s+Rows_examined: %{NUMBER:rows_examined:int}\s*(?:use %{DATA:database};\s*)?SET timestamp=%{NUMBER:timestamp};\s*(?<query>(?<action>\w+)\s+.*)" ]
}
grok {
match => { "message" => "# Time: " }
add_tag => [ "drop" ]
tag_on_failure =>[]
}
if "drop" in [tags] {
drop {}
}
date {
match => [ "timestamp", "UNIX", "YYYY-MM-dd HH:mm:ss"]
remove_field => [ "timestamp" ]
}

}
output {
elasticsearch {
hosts => "192.168.1.63:9200"
manage_template => false
index => "%{[@metadata][beat]}-%{[type]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}

kibana日志输出展示

利用filebeat推送mysql慢查询日志

mysql慢日志kibana展示

利用filebeat推送mysql慢查询日志

mysql慢日志kibana展示

您可以选择一种方式赞助本站

支付宝转账赞助

支付宝扫一扫赞助

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

图片 表情