oracle or使用速度快马_使用mysqld_exporter监控MySQL并展示数据
mysqld_exporter是Prometheus用于監(jiān)控MySQL指標的一個導出器,支持對MySQL 5.5以上進行監(jiān)控。用來抓取mysql的相關信息,下面是mysqld_exporter 安裝的相關信息
環(huán)境: 192.168.31.40 MariaDB-5.5.68 mysqld_exporter_0.12.1
一、下載mysqld_exporter 并安裝
官方網址:https://prometheus.io/download/
選擇對應的版本下載
[root@node-1 ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
#解壓 ,移動到/usr/local 路徑下 并從命名為 mysqld_exporter
[root@node-1 ~]# tar -xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@node-1 ~]# mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter
二、登陸數據庫,創(chuàng)建授權賬戶
[root@node-1 ~]# mysql -uroot -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or g.Your MariaDB connection id is 278Server version: 5.5.68-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.MariaDB [(none)]> grant PROCESS, REPLICATION CLIENT, SELECT on *.* to 'exporter'@'localhost' identified by 'fxkjnj';MariaDB [(none)]> flush privileges;#注意: 這里我只授權了本機登陸,因為 mysqld_exporter 也安裝在數據庫這臺主機上
#退出驗證,使用exporter 用戶登陸數據庫
[root@node-1 ~]# mysql -uroot -p'fxkjnj'Welcome to the MariaDB monitor. Commands end with ; or g.Your MariaDB connection id is 286Server version: 5.5.68-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.MariaDB [(none)]> show grants;+----------------------------------------------------------------------------------------------------------------------------------------+| Grants for root@localhost |+----------------------------------------------------------------------------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*A88C2B91E04CF458B1EFF3228824DEA7CE4ABA22' WITH GRANT OPTION || GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |+----------------------------------------------------------------------------------------------------------------------------------------+2 rows in set (0.00 sec)MariaDB [(none)]>三、創(chuàng)建mysqld_exporter 的配置文件 my.cnf
[root@node-1 mysqld_exporter]# vim /usr/local/mysqld_exporter/my.cnf
[client]
host=192.168.31.40
port=3306
user=exporter
password=fxkjnj
四、創(chuàng)建mysql_exporter 啟動文件,使用systemd 管理
[root@node-1 mysqld_exporter]# vim /etc/systemd/system/mysqld_exporter.service [Unit]Description=mysqld_exporterDocumentation=mysqld_exporter-doc [Service]ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf [Install]WantedBy=multi-user.target#初始化并啟動mysqld_exporter
[root@node-1 mysqld_exporter]# systemctl daemon-reload
[root@node-1 mysqld_exporter]# systemctl start mysqld_exporter.service
#查看進程及端口
[root@node-1 ~]# ps -ef | grep mysqld_exporter | grep -v grep
root 60884 1 0 16:55 ? 00:00:02 /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf
[root@node-1 ~]# netstat -ntlup | grep mysqld_export
tcp6 0 0 :::9104 :::* LISTEN 60884/mysqld_export
五、修改prometheus 配置文件 指定 mysqld_exporter 采集器地址
[root@prometheus ~]#vim /etc/prometheus/prometheus.yml
[root@prometheus ~]#vim /etc/prometheus/prometheus.yml..............scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['192.168.31.250:9090'] - job_name: 'mysql' static_configs: - targets: ['192.168.31.40:9104']..............#熱加載prometheus
[root@prometheus ~]# ps -ef | grep prometheus | grep -v grep | awk '{print $2}' | xargs kill -HUP
#登陸到prometheus 控制臺,可以在status/targets 里看到 mysqld_exporter 采集器相關信息
點擊 http://192.168.31.40:9104/metrics 可以看到相關數據
六、使用grafana 展示 mysqld_exporter 采集器采集的數據
PS: grafana 添加 prometheus 數據源 過程 省略。。。。。。。。。。
為了最終的效果,我們使用 Grafana 官網小伙伴提供的dashboard 來展示數據
模板地址: https://grafana.com/grafana/dashboards/7362 ID: 7362
點擊 Download JSON , 下載完后 登陸Grafana ,默認地址 http://IP:3000
找到左側 + 號,import 導入剛剛下載的json 文件
選擇好數據源
稍等片刻,就可以看到 最終的效果
本篇只涉及到 使用mysqld_exporter 收集mysql 數據并展示 ,并沒有寫到 觸發(fā)器的配置告警,這個等后面再更新
總結
以上是生活随笔為你收集整理的oracle or使用速度快马_使用mysqld_exporter监控MySQL并展示数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cv岗工作做什么_中字头施工单位的党建岗
- 下一篇: d3中文案例_D3.js柱状图例子