elk 5.1 用于mysql slow 日志
2016-12-27 20:35
387 查看
最近面临一个任务,要对mysql的慢查询日志进行整理输出。之前的Le的时候,写过一个脚本,multiline处理mysql的日志,然后每天发送日志。不过,由于日志格式不同,有些可以解析,但是有些也是解析错误了。
听说elk很牛已经很久了,之前也测试过,当时是为了打造一款日志处理中心,但是需要有RBA功能,role based authorization,区分不同的用户权限,但是当时的测试非常糟糕,一个是不懂elk,一个是RBA需要付费才有,所以后来也就搁浅了。
这次重装上阵,直捣黄龙,目标只有一个,就是解析慢查询日志。
听说elk很牛已经很久了,之前也测试过,当时是为了打造一款日志处理中心,但是需要有RBA功能,role based authorization,区分不同的用户权限,但是当时的测试非常糟糕,一个是不懂elk,一个是RBA需要付费才有,所以后来也就搁浅了。
这次重装上阵,直捣黄龙,目标只有一个,就是解析慢查询日志。
e
下载
配置
# config/elasticsearch.yml node.name: t17 path.data: ./data path.logs: ./logs network.host: 192.168.126.17 http.cors.enabled: true http.cors.allow-origin: "*"
插件 (head)
git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install -f grunt server open http://localhost:9100/[/code]启动
# 直接启动,也不要啥启动脚本了。 ./elasticsearchl
input { #stdin { file { type => "mysql-slow" path => "/opt/elk/logstash-5.1.1/bin/master-slow.log" start_position => "beginning" codec => multiline { pattern => "^# User@Host:" negate => true what => previous } } } 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)^# User@Host: %{USER:user}\[[^\]]+\] @ (?:(?<clienthost>\S*) )?\[(?:%{IP:clientip})?\]\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+.*)\n# Time:.*$" ] #match => [ "message", "# User@Host: %{WORD:test};" ] match => [ "message", "# User@Host:\s+%{WORD:user1}\[%{WORD:user2}\]\s+@\s+\[(?:%{IP:clientip})?\]\s+#\s+Thread_id:\s+%{NUMBER:thread_id:int}\s+Schema:\s+%{WORD:schema}\s+QC_hit:\s+%{WORD:qc_hit}\s+#\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+#\s+Rows_affected:\s+%{NUMBER:rows_affected:int}\s+SET\s+timestamp=%{NUMBER:timestamp};\s+(?<query>(?<action>\w+)\s+.*);"] } date { match => [ "timestamp", "UNIX" ] remove_field => [ "timestamp" ] } } output { elasticsearch { hosts => ["192.168.126.17:9200"] index=>"mysql-slow-log-%{+YYYY.MM.dd}" } stdout { codec => rubydebug } }
最讨厌的就是filter,我们的日志是mariadb10.1.16的,网上还没有发现这种filter,所以参照着写了个。k 暂时不用了
正则表达式 http://www.runoob.com/regexp/regexp-syntax.html
grok正则捕获 http://udn.yyuap.com/doc/logstash-best-practice-cn/filter/grok.html
mysql 慢查询日志 logstash捕获 http://kibana.logstash.es/content/logstash/examples/mysql-slow.html
专业处理mysql http://soft.dog/2016/01/30/logstash-mysql-slow-log/
非常棒的一篇文章 http://www.fblinux.com/?p=40
相关文章推荐
- [置顶] ELK(ElasticSearch5.1, Logstash5.1, Kibana5.1)搭建实时日志分析平台
- Elk实时日志分析平台5.0版本源码安装配置
- elasticsearch + logstash + kibana 搭建 ELK 日志分析系统
- elk系列8之logstash+redis+es的架构来收集apache的日志
- ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台 推荐
- MySQL 5.1以下如何动态抓取查询日志
- ELK显示多行日志
- 分布式实时日志分析解决方案ELK部署架构
- ELK日志监控系统搭建
- ELK系列--实时日志分析系统ELK 部署与运行中的问题汇总
- 日志分析平台ELK部署初学
- ELK 日志分析系统
- 云计算Docker全面项目实战(Maven+Jenkins、日志管理ELK、WordPress博客镜像)
- 错误日志类-也可以用于查看输出结构
- ELK 5.x日志分析 (二) Elasticserach 5.2 安装
- ELK日志管理之——kibana部署
- ELK+Kafka 企业日志收集平台(二)
- 用于主题检测的临时日志(fc2ff039-dc23-4856-bb9f-2c411920014b - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
- python fabric部署elk的filebeat日志收集客户端
- ELK日志分析系统部署