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

來源:互聯網
上載者:User

標籤:row   sql   path   技術   logs   資料庫   檔案   set   beginning   

寫在前面:在做ELK logstash 處理MySQL慢查詢日誌的時候出現的問題:1、測試資料庫沒有慢日誌,所以沒有日誌資訊,導致 IP:9200/_plugin/head/介面異常(忽然出現日誌資料,刪除索引後就消失了)2、處理日誌指令碼問題3、目前單節點 配置指令檔/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與連接埠,以及索引名稱[[email protected] config]# ../bin/logstash agent -f slowlog.confSettings: Default pipeline workers: 1Pipeline main started在http://115.28.3.150:9200/_plugin/head/頁面上重新整理:

-------------------------------------------------------------------------------------------------------------------------------

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

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+# [email protected]: %{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
}
}

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.