Logstash analyzing MySQL Slow query log

Source: Internet
Author: User
Tags system log mysql slow query log logstash

Recently in the use of Elkstack to the System log analysis, on the internet also saw the use of logstash cases, but found that can not be resolved properly, and then re-take the time to do regular calculations, the main code is as follows:

input {  file {    type =>  "Mysql-slow"      path =>  "/var/lib/mysql/slow.log"         start_ position => beginning                 sincedb_write_interval => 0    codec =>  multiline {      pattern =>  "^# [email protected]:"       negate => true      what = >  "Previous"     }  }}filter {if [message] =~  "^tcp"  {        drop {}}if [message] =~  "^time"  {        drop {}}if [message] =~  "^\/USR"  {        drop {}}  grok {    match =>  {  "message"  =>  "Select sleep"  }    add_tag => [   "Sleep_drop"  ]    tag_on_failure => []  }  if   "Sleep_drop"  in [tags] {    drop {}  }     grok {    match => {  "Message"  =>  "(? m) ^#  [email protected]: %{USER:User}\[[^\]]+\] @  (?:(? <clienthost>\s*)   \[(?:%{ip:client_ip})? \]\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:.*$ " }     }  date {    match => [  " Timestamp ", " UNIX " ]    remove_field => [ " timestamp "&NBSP;]   }}output {            redis  {                host = >  "192.168.1.2:6379"                  data_type =>  "List"                  key =>  "Logstash:mysql_slow_log"              }}

Description

When used with codec/multiline, it is important to note that the grok and normal regular are not supported by matching carriage return line by default. Just like you need =~//m, you need to specify it individually, by adding (? m) markers at the beginning of the expression


At the beginning of the time has not added (? m), in the http://grokdebug.herokuapp.com/debugging normal pass, but to the logstash execution is not normal parsing.





This article is from "Maple Night" blog, please be sure to keep this source http://fengwan.blog.51cto.com/508652/1758920

Logstash analyzing MySQL Slow query log

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.