如何啓動 Metricbeat 中的 MySQL 模塊 - query Metricset


導語



在今天的文章中,我將介紹如上啓動這個 metricset。在使用這個 metricset 時需要做相應的配置。



簡單地說,我們需要使用如下的步驟來進行啓動 MySQL 模塊:

./metricbeat modules enable mysql


我們可以使用如下的命令來檢查這個模塊是否被啓動:

./metricbeat modules modules list


在本次測試中,爲了方便,我們只啓動 MySQL 模塊。我們可以嘗試使用如下的命令來檢查我們的 MySQL 模塊是否配置成功:

 ./metricbeat test modules mysql



上面顯示我們的模塊配置是不成功的。我們需要配置 modules.d/mysql.yml

modules.d/mysql.yml

# Module: mysql# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.x/metricbeat-module-mysql.html - module: mysql  metricsets:    - status  #  - galera_status  #  - performance  #  - query  period: 10s   # Host DSN should be defined as "user:pass@tcp(127.0.0.1:3306)/"  # or "unix(/var/lib/mysql/mysql.sock)/",  # or another DSN format supported by <https://github.com/Go-SQL-Driver/MySQL/>.  # The username and password can either be set in the DSN or using the username  # and password config options. Those specified in the DSN take precedence.  hosts: ["root:1234@tcp(127.0.0.1:3306)/"]    # Username of hosts. Empty by default.  #username: root   # Password of hosts. Empty by default.  #password: secret


請注意上面的 1234 是我的 mysql root 用戶的密碼。我們重新進行測試:

$ ./metricbeat test modules  mysql | grep OK  status...OK


上面表示我們的測試是成功的。我們接下來啓動 query metricset:

modules.d/mysql.yml


如果我們重新測試的話,我們就會發現有這樣的錯誤:

./metricbeat test modules  mysql


從上面的輸出中,我們可以看出來,有一個錯誤信息。我們需要做更多的配置:

modules.d/mysql.yml

# Module: mysql# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.x/metricbeat-module-mysql.html - module: mysql  metricsets:  #  - status  #  - galera_status  #  - performance    - query  period: 10s  namespace: "my_namespace"   # Host DSN should be defined as "user:pass@tcp(127.0.0.1:3306)/"  # or "unix(/var/lib/mysql/mysql.sock)/",  # or another DSN format supported by <https://github.com/Go-SQL-Driver/MySQL/>.  # The username and password can either be set in the DSN or using the username  # and password config options. Those specified in the DSN take precedence.  hosts: ["root:1234@tcp(127.0.0.1:3306)/"]  queries:  - query: "SELECT * FROM data.sensors"    response_format: "table"    query_namespace: "my_first_query_namespace"  - query: "SELECT * FROM data.SalesJan2009"    response_format: "table"    query_namespace: "my_second_query_namespace"   # Username of hosts. Empty by default.  #username: root   # Password of hosts. Empty by default.  #password: secret


在上面 data 是我們在 MySQL 中的數據庫。sensors 以及 SalesJan2009 是 data 數據庫中的表格:


經過上面的配置後,我們重新來進行測試:

$ ./metricbeat test modules  mysql mysql...  query...OK    result:     {     "@timestamp": "2021-03-29T05:24:57.477Z",     "event": {      "dataset": "mysql.query",      "duration": 8743859,      "module": "mysql"     },     "metricset": {      "name": "query",      "period": 10000     },     "mysql": {      "my_namespace": {       "my_first_query_namespace": {        "buildingname": "222 Broadway",        "customer": "Elastic",        "department": "Engineering",        "floor": "Floor 1",        "id": 1,        "latitude": 41,        "locationonfloor": "Desk 102",        "longitude": -74,        "room": 101,        "sensortype": "Temperature"       }      }     },     "service": {      "address": "tcp(127.0.0.1:3306)/?readTimeout=10s\u0026timeout=10s\u0026writeTimeout=10s",      "type": "mysql"     }    }


從上面的輸出中,我們可以看出來我們的測試是成功的。


接下來我們使用如下的配置 Metricbeat:

./metricbeat setup


$ ./metricbeat setupOverwriting ILM policy is disabled. Set `setup.ilm.overwrite: true` for enabling. Index setup finished.Loading dashboards (Kibana must be running and reachable)Loaded dashboards


我們使用如下的命令來啓動 Metricbeat:

./metricbeat -e



我們在 Discover 中可以看到如下的數據:


總結

從上面我們可以看出來。event.dataset 來自 mysql.query 還是有蠻多的數據的。


正文完



 作者:劉曉國

本文編輯:喝咖啡的貓



嗨,互動起來吧!

喜歡這篇文章麼?

歡迎留下你想說的,留言 100% 精選哦!

Elastic 社區公衆號長期徵稿,如果您有 Elastic  技術的相關文章,也歡迎投稿至本公衆號,一起進步! 投稿請添加微信:medcl123



招聘信息

Job board

社區招聘欄目是一個新的嘗試,幫助社區的小夥伴找到心儀的職位,也幫助企業找到所需的人才,爲伯樂和千里馬牽線搭橋。有招聘需求的企業和正在求職的社區小夥伴,可以聯繫微信 medcl123 提交招聘需求和發佈個人簡歷信息。

Elastic中文社區公衆號 (elastic-cn)

爲您彙集 Elastic 社區的最新動態、精選乾貨文章、精華討論、文檔資料、翻譯與版本發佈等。

喜歡本篇內容就請給我們點個[在看]吧



本文分享自微信公衆號 - Elastic中文社區(elastic-cn)。
如有侵權,請聯繫 [email protected] 刪除。
本文參與“OSC源創計劃”,歡迎正在閱讀的你也加入,一起分享。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章