前段時間小編寫了一篇:使用Nginx+Telegraf+Influxb+Grafana構建高逼格Nginx集羣監控系統!文章,詳細了介紹了 採集器telegraf, 時序數據庫influxdb , 數據展現Grafana的部署以及系統主機側的監控添加,圖表的展現。mysql
本文就接着介紹使用 Telegraf+Influxdb+Grafana架構來快速監控MySQL。sql
首先 ,咱們先看下效果圖:shell
由於咱們在前面已經部署好telegraf 了,也已經採集了主機側的一些CPU ,內存,磁盤,網絡流量等信息 , 如今收集Mysql 監控信息,最好仍是與以前的telegraf.conf配置文件分離開。數據庫
[root@fxkj ~]# vim /etc/telegraf/telegraf.d/telegraf_mysql.conf [[outputs.influxdb]] database = "mysql_metrics" urls = ["http://127.0.0.1:8086"] namepass = ["*_mysql"] username = "fxkj" password = "123456" [[inputs.mysql]] servers = ["root:123456@tcp(localhost:3306)/?tls=false"] name_suffix = "_mysql" #database 表示數據庫名稱,採集的數據都放在此庫中 #urls 表示 influxdb 數據庫地址 #servers 裏面包含 了MySQL 受權用戶的 用戶名,密碼 以及鏈接mysql 的地址 #name_suffix 表示名稱後綴
[root@fxkj ~]# systemctl restart telegraf.service [root@fxkj ~]# tail -n 10 /tmp/telegraf.log 2020-08-11T01:37:20Z E! [outputs.influxdb] when writing to [http://localhost:8086]: Post 2020-08-11T01:37:42Z I! Loaded processors: 2020-08-11T01:37:42Z I! Loaded outputs: influxdb influxdb 2020-08-11T01:37:42Z I! Tags enabled: host=fxkjnj.com 2020-08-11T01:37:42Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"fxkj", Flush Interval:10s
[root@aly mysql]# influx -username fxkj -password '123456' Connected to http://localhost:8086 version 1.8.1 InfluxDB shell version: 1.8.1 > show databases; name: databases name ---- _internal telegraf mysql_metrics > use mysql_metrics; Using database mysql_metrics > show measurements; name: measurements name ---- mysql_mysql
能夠看到有一個mysql_metrics的庫以及一個叫mysql_mysql的表。json
查看錶中有哪些字段:vim
> show field keys from mysql_mysql; name: mysql_mysql fieldKey fieldType -------- --------- aborted_clients integer aborted_connects integer access_denied_errors integer busy_time integer bytes_received integer bytes_sent integer commands_admin_commands integer commands_create_index integer commands_create_procedure integer commands_drop_db integer commands_drop_event integer commands_drop_function integer commands_drop_index integer commands_stmt_reprepare integer handler_mrr_key_refills integer handler_read_rnd integer handler_read_rnd_deleted integer handler_read_rnd_next integer handler_rollback integer handler_savepoint integer handler_savepoint_rollback integer innodb_buffer_pool_pages_free integer innodb_buffer_pool_pages_made_not_young integer innodb_buffer_pool_pages_made_young integer innodb_dblwr_writes integer innodb_deadlocks integer innodb_descriptors_memory integer innodb_dict_tables integer innodb_ibuf_merges integer innodb_ibuf_segment_size integer innodb_x_lock_spin_waits integer key_blocks_not_flushed integer not_flushed_delayed_rows integer open_files integer open_streams integer open_table_definitions integer open_tables integer threads_connected integer threads_created integer threads_running integer uptime integer uptime_since_flush_status integer
更多的監控模板,你們能夠到https://grafana.com/grafana/d...。網絡
由於以前作了個主機側的監控,因此爲了方便區分,咱們此次再添加一個influxdb數據源。架構
點擊Configuration ,選擇 Data Sources ,點擊 Add data source數據源名稱:MySQL (我監控模板裏的數據源是這個名稱,最好和我一致,否則模板導入會報錯)app
點擊左側+號 ,選擇import ,—— > 點擊Upload.json file, 上傳模板文件。到此模板就導入成功了tcp
來源: https://www.toutiao.com/i6859...