侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Logstash收集单机多个MySQL慢查询日志

2023-11-07 星期二 / 0 评论 / 0 点赞 / 54 阅读 / 4406 字

input {file {path => "/data/order-slave-slow.log"type => "mysql-slow-log"start_position => "beginnin

input {	file {		path => "/data/order-slave-slow.log"		type => "mysql-slow-log"		start_position => "beginning"		codec => multiline {			pattern => "^# User@Host:"			negate => true			what => previous		}	}	file {		path => "/data/other-slave-slow.log"		type => "mysql-slow-log"		start_position => "beginning"		codec => multiline {			pattern => "^# User@Host:"			negate => true			what => previous		}	}	file {		path => "/data/order-master-slow.log"		type => "mysql-slow-log"		start_position => "beginning"		codec => multiline {			pattern => "^# User@Host:"			negate => true			what => previous		}	}	file {		path => "/data/other-master-slow.log"		type => "mysql-slow-log"		start_position => "beginning"		codec => multiline {			pattern => "^# User@Host:"			negate => true			what => previous		}	}}filter {	if [path] =~ "order-slave-slow" { //根据文件内容不同,增加不同的字段		grok {			match => { "message" => "(?m)^#/s+User@Host:/s+%{USER:user}/[[^/]]+/]/s+@/s+(?:(?<clientip>/S*) )?/[(?:%{IPV4:clientip})?/]/s+Id:/s+%{NUMBER:row_id:int}/n#/s+Query_time:/s+%{NUMBER:Query_time:float}/s+Lock_time:/s+%{NUMBER:lock_time:float}/s+Rows_sent:/s+%{NUMBER:Row_sent:int}/s+Rows_examined:/s+%{NUMBER:Rows_examined:int}/n/s*(?:use %{DATA:database};/s*/n)?SET/s+timestamp=%{NUMBER:timestamp};/n/s*(?<sql>(?<action>/w+)/b.*;)/s*(?:/n#/s+Time)?.*$" }			remove_field => [ "message" ]		}		mutate {		    replace => [ "host" , "%{host}" ]			add_field => [ "nsCode", "%{nsCode}" ]			add_field => [ "envCode", "%{envCode}" ]			add_field => [ "mysqlType", "%{mysqlType}" ]			gsub => [ "sql", "/n# Time: /d+/s+/d+:/d+:/d+", "" ]		}	}	if [path] =~ "other-slave-slow" {		grok {			match => { "message" => "(?m)^#/s+User@Host:/s+%{USER:user}/[[^/]]+/]/s+@/s+(?:(?<clientip>/S*) )?/[(?:%{IPV4:clientip})?/]/s+Id:/s+%{NUMBER:row_id:int}/n#/s+Query_time:/s+%{NUMBER:Query_time:float}/s+Lock_time:/s+%{NUMBER:lock_time:float}/s+Rows_sent:/s+%{NUMBER:Row_sent:int}/s+Rows_examined:/s+%{NUMBER:Rows_examined:int}/n/s*(?:use %{DATA:database};/s*/n)?SET/s+timestamp=%{NUMBER:timestamp};/n/s*(?<sql>(?<action>/w+)/b.*;)/s*(?:/n#/s+Time)?.*$" }			remove_field => [ "message" ]		}		mutate {			replace => [ "host" , "%{host}" ]			add_field => [ "nsCode", "%{nsCode}" ]			add_field => [ "envCode", "%{envCode}" ]			add_field => [ "mysqlType", "%{mysqlType}" ]			gsub => [ "sql", "/n# Time: /d+/s+/d+:/d+:/d+", "" ]		}	}	if [path] =~ "order-master-slow" {		grok {			match => { "message" => "(?m)^#/s+User@Host:/s+%{USER:user}/[[^/]]+/]/s+@/s+(?:(?<clientip>/S*) )?/[(?:%{IPV4:clientip})?/]/s+Id:/s+%{NUMBER:row_id:int}/n#/s+Query_time:/s+%{NUMBER:Query_time:float}/s+Lock_time:/s+%{NUMBER:lock_time:float}/s+Rows_sent:/s+%{NUMBER:Row_sent:int}/s+Rows_examined:/s+%{NUMBER:Rows_examined:int}/n/s*(?:use %{DATA:database};/s*/n)?SET/s+timestamp=%{NUMBER:timestamp};/n/s*(?<sql>(?<action>/w+)/b.*;)/s*(?:/n#/s+Time)?.*$" }			remove_field => [ "message" ]		}		mutate {			replace => [ "host" , "%{host}" ]			add_field => [ "nsCode", "%{nsCode}" ]			add_field => [ "envCode", "%{envCode}" ]			add_field => [ "mysqlType", "%{mysqlType}" ]			gsub => [ "sql", "/n# Time: /d+/s+/d+:/d+:/d+", "" ]		}	}	if [path] =~ "other-master-slow" {		grok {			match => { "message" => "(?m)^#/s+User@Host:/s+%{USER:user}/[[^/]]+/]/s+@/s+(?:(?<clientip>/S*) )?/[(?:%{IPV4:clientip})?/]/s+Id:/s+%{NUMBER:row_id:int}/n#/s+Query_time:/s+%{NUMBER:Query_time:float}/s+Lock_time:/s+%{NUMBER:lock_time:float}/s+Rows_sent:/s+%{NUMBER:Row_sent:int}/s+Rows_examined:/s+%{NUMBER:Rows_examined:int}/n/s*(?:use %{DATA:database};/s*/n)?SET/s+timestamp=%{NUMBER:timestamp};/n/s*(?<sql>(?<action>/w+)/b.*;)/s*(?:/n#/s+Time)?.*$" }			remove_field => [ "message" ]		}		mutate {			replace => [ "host" , "%{host}" ]			add_field => [ "nsCode", "%{nsCode}" ]			add_field => [ "envCode", "%{envCode}" ]			add_field => [ "mysqlType", "%{mysqlType}" ]			gsub => [ "sql", "/n# Time: /d+/s+/d+:/d+:/d+", "" ]		}	}}output {	if [type] == "mysql-slow-log" {		redis {			host => "%{ES_SEVER}"			data_type => "list"			key => "mysql-slow-log"		}	}}

 

广告 广告

评论区