时间:2021-07-01 10:21:17 帮助过:43人阅读
介绍通过利用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慢日志
[bash]# 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[/bash]
filebeat及logstash配置
filebeat.yml配置文件
[bash]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"][/bash]
logstash.conf
[bash]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]}" } }[/bash]
kibana日志输出展示
本文出自 “olinux运维琐事” 博客,请务必保留此出处http://93489.blog.51cto.com/83489/1917982
利用filebeat推送mysql慢查询日志
标签:elk