【20180417】ELK日誌管理之filebeat收集分析mysql慢日誌

來源:互聯網
上載者:User

標籤:filebeat   slow log   pipeline   slowlog   

環境版本

filebeat: 6.2.3
mysql: 5.6.38

錯誤資訊
{  "_index": "mysql-slow-2018.04.17",  "_type": "doc",  "_id": "AWLRiDqYhjFMCbqrK5ez",  "_version": 1,  "_score": null,  "_source": {    "@timestamp": "2018-04-17T02:56:22.823Z",    "offset": 100619865,    "beat": {      "hostname": "test-db1",      "name": "test-db1",      "version": "6.2.3"    },    "prospector": {      "type": "log"    },    "source": "/var/log/mysql_3306/mysql-slow.log",    "fileset": {      "module": "mysql",      "name": "slowlog"    },    "message": "# [email protected]: test_db[test_table] @  [10.10.10.10]  Id: 1874266\n# Query_time: 2.088465  Lock_time: 0.000086 Rows_sent: 67  Rows_examined: 18862\nSET timestamp=1523933781;\nselect id, dct, mh, topcolor, bit_count(dct^1144174128272565460) as dist from image_feature where topcolor=\"278522176103c518c774fe2a73b20569\" and created_at<\"2018-04-17 10:54:16\" and id not in (120251270,120251181,120251202,120251209,120251221,120251229,120251240,120251252,120251259,120251270,120251278) having dist<=20 order by dist;",    "error": {      "message": "Provided Grok expressions do not match field value: [# [email protected]: test_db[test_table] @  [10.10.10.10]  Id: 1874266\\n# Query_time: 2.088465  Lock_time: 0.000086 Rows_sent: 67  Rows_examined: 18862\\nSET timestamp=1523933781;\\nselect id, dct, mh, topcolor, bit_count(dct^1144174128272565460) as dist from image_feature where topcolor=\\\"278522176103c518c774fe2a73b20569\\\" and created_at<\\\"2018-04-17 10:54:16\\\" and id not in (120251270,120251181,120251202,120251209,120251221,120251229,120251240,120251252,120251259,120251270,120251278) having dist<=20 order by dist;]"    }  },  "fields": {    "@timestamp": [      1523933782823    ]  },  "highlight": {    "beat.name": [      "@[email protected]@/[email protected]"    ]  },  "sort": [    1523933782823  ]}
{  "_index": "mysql-slow-2018.04.17",  "_type": "doc",  "_id": "AWLRb2nl6-SuKroP98i-",  "_version": 1,  "_score": null,  "_source": {    "@timestamp": "2018-04-17T02:29:21.535Z",    "offset": 100614853,    "beat": {      "hostname": "test-db1",      "name": "test-db1",      "version": "6.2.3"    },    "prospector": {      "type": "log"    },    "source": "/var/log/mysql_3306/mysql-slow.log",    "message": "# Time: 180417 10:29:18",    "fileset": {      "module": "mysql",      "name": "slowlog"    },    "error": {      "message": "Provided Grok expressions do not match field value: [# Time: 180417 10:29:18]"    }  },  "fields": {    "@timestamp": [      1523932161535    ]  },  "highlight": {    "error.message": [      "Provided Grok expressions do not match field value: [# @[email protected]@/[email protected]: 180417 10:29:18]"    ]  },  "sort": [    1523932161535  ]}

上面的這些資訊可以在Kibana的Discover中可以查詢得到。

  1. 從上面的JSON資訊我們可以很明確的擷取得到倆個資訊:

    • 一個就是Kibana無法解析MySQL執行個體的slow日誌。
    • 另外一個就是類似 "# Time: 180417 10:26:11"這樣子的時間資訊也被當作了MySQL的SQL資訊發送給Kibana。
  2. 其實主要問題就是在於pipeline,
問題解決
  1. 修改module/mysql/slowlog/config/slowlog.yml
    修改之前:exclude_lines: [‘^[\/\w\.]+, Version: .* started with:.*‘]   # Exclude the header修改之後:exclude_lines: [‘^[\/\w\.]+, Version: .* started with:.*‘,‘^# Time.*‘]   # Exclude the header
  2. 修改module/mysql/slowlog/ingest/pipeline.json
    修改之前:"patterns":[    "^# [email protected]: %{USER:mysql.slowlog.user}(\\[[^\\]]+\\])? @ %{HOSTNAME:mysql.slowlog.host} \\[(%{IP:mysql.slowlog.ip})?\\](\\s*Id:\\s* %{NUMBER:mysql.slowlog.id})?\n# Query_time: %{NUMBER:mysql.slowlog.query_time.sec}\\s* Lock_time: %{NUMBER:mysql.slowlog.lock_time.sec}\\s* Rows_sent: %{NUMBER:mysql.slowlog.rows_sent}\\s* Rows_examined: %{NUMBER:mysql.slowlog.rows_examined}\n(SET timestamp=%{NUMBER:mysql.slowlog.timestamp};\n)?%{GREEDYMULTILINE:mysql.slowlog.query}"            ]修改之後:  "patterns":[    "^# [email protected]: %{USER:mysql.slowlog.user}(\\[[^\\]]+\\])? @ %{HOSTNAME:mysql.slowlog.host} \\[(IP:mysql.slowlog.ip)?\\](\\s*Id:\\s* %{NUMBER:mysql.slowlog.id})?\n# Query_time: %{NUMBER:mysql.slowlog.query_time.sec}\\s* Lock_time: %{NUMBER:mysql.slowlog.lock_time.sec}\\s* Rows_sent: %{NUMBER:mysql.slowlog.rows_sent}\\s* Rows_examined: %{NUMBER:mysql.slowlog.rows_examined}\n(SET timestamp=%{NUMBER:mysql.slowlog.timestamp};\n)?%{GREEDYMULTILINE:mysql.slowlog.query}"            ],

【20180417】ELK日誌管理之filebeat收集分析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.