ELK logstash 處理MySQL慢查詢日誌(初步)

寫在前面:在作ELK logstash 處理MySQL慢查詢日誌的時候出現的問題:
一、測試數據庫沒有慢日誌,因此沒有日誌信息,致使 IP:9200/_plugin/head/界面異常(突然出現日誌數據,刪除索引後就消失了)
二、處理日誌腳本問題
三、目前單節點
 
配置腳本文件/usr/local/logstash-2.3.0/config/slowlog.conf【詳細腳本文件見最後】
 
output {
  elasticsearch {
    hosts => "115.28.3.150:9200"
    index => "mysql-slowlog"
    workers => 1
    flush_size => 20000
    idle_flush_time => 10
    template_overwrite => true
  }
}
在outpout定義Elasticsearch的IP與端口,以及索引名稱
[root@iZ28o76f668Z config]# ../bin/logstash agent -f slowlog.conf
Settings: Default pipeline workers: 1
Pipeline main started
在http://115.28.3.150:9200/_plugin/head/頁面上刷新:

-------------------------------------------------------------------------------------------------------------------------------mysql

cat /usr/local/logstash-2.3.0/config/slowlog.confsql

input {數據庫

file {
type => "mysql-slow"
path => "/mnt/data/mysql/mysql-slow.log"
start_position => "beginning"
codec => multiline {
pattern => "^# Time:"
negate => true
what => "previous"
}
}
}
filter {
grok {
match => { "message" => "SELECT SLEEP" }
add_tag => [ "sleep_drop" ]
tag_on_failure => []
}
if "sleep_drop" in [tags] {
drop {}
}
grok {
match => [ "message", "(?m)^# Time:.*\s+# User@Host: %{USER:user}\[[^\]]+\] @ (?:(?<clienthost>\S*) )?\[(?:%{IP:clientip})?\]\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+.*)$" ]
}
date {
match => [ "timestamp", "UNIX" ]
remove_field => [ "timestamp" ]
}
}
output {
elasticsearch {
hosts => "192.168.98.163:9200"
index => "mysql-slowlog"
workers => 1
flush_size => 20000
idle_flush_time => 10
template_overwrite => true
}
}
elasticsearch

相關文章
相關標籤/搜索