Grafana+Prometheus系统监控之MySql
架構
grafana和prometheus之前安裝配置過,見:Grafana+Prometheus打造全方位立體監控系統
MySql安裝
MySql的地位和重要性就不言而喻了,作為開源產品深受廣大中小企業以及互聯網企業喜愛,所以這里我們也有必要對其進行相應的監控。
由于最近更換了CentOS7,這里對MySql重新安裝一遍,順便做個記錄,CentOS7的yum源中默認好像是沒有mysql的。為了解決這個問題,我們要先下載mysql的repo源。
列出所有版本信息:
lsb_release -a下載mysql的repo源:
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm安裝mysql-community-release-el7-5.noarch.rpm包:
rpm -ivh mysql-community-release-el7-5.noarch.rpm安裝mysql:
yum install mysql-server -y修改權限,否則會報錯:
chown -R root:root /var/lib/mysql重啟mysql服務:
service mysqld restart登錄并重置密碼:
## 直接回車進入mysql控制臺 mysql -u root mysql > use mysql; mysql > update user set password=password('123456') where user='root'; mysql > exit;mysqld_exporter安裝
下載并解壓:
https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gztar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gzmysqld_exporter需要連接Mysql,首先為它創建用戶并賦予所需的權限:
GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'localhost' identified by '123456';GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';flush privileges;創建.my.cnf文件 vi .my.cnf:
[client] user=exporter password=123456運行mysqld_exporter:
./mysqld_exporter -config.my-cnf=".my.cnf" &Prometheus配置
修改prometheus.yml加入MySql節點:
global:scrape_interval: 15sevaluation_interval: 15sscrape_configs:- job_name: prometheusstatic_configs:- targets: ['localhost:9090']labels:instance: prometheus- job_name: linux1static_configs:- targets: ['192.168.1.120:9100']labels:instance: sys1- job_name: linux2static_configs:- targets: ['192.168.1.130:9100']labels:instance: sys2- job_name: redis1static_configs:- targets: ['192.168.1.120:9121']labels:instance: redis1- job_name: mysqlstatic_configs:- targets: ['192.168.1.120:9104']labels:instance: db1保存以后重啟Prometheus,查看targets:
最后登錄grafana查看MySql監控信息:
參考文檔:
https://github.com/prometheus/mysqld_exporter
轉載于:https://www.cnblogs.com/smallSevens/p/7852980.html
總結
以上是生活随笔為你收集整理的Grafana+Prometheus系统监控之MySql的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【DevExpress v17.2新功能
- 下一篇: python +Django 搭建web