Grafana+Prometheus係統監控之MySql
架構
grafana和prometheus之前安裝配置過,見:Grafana+Prometheus打造全方位立體監控係統
MySql安裝
MySql的地位和重要性就不言而喻了,作為開源產品深受廣大中小企業以及互聯網企業喜愛,所以這裏我們也有必要對其進行相應的監控。
由於最近更換了CentOS7,這裏對MySql重新安裝一遍,順便做個記錄,CentOS7的yum源中默認好像是沒有mysql的。為了解決這個問題,我們要先下載mysql的repo源。
列出所有版本信息:
lsb_release -a
下載mysql的repo源:
wget https://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.gz
tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
mysqld_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: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux1
static_configs:
- targets: ['192.168.1.120:9100']
labels:
instance: sys1
- job_name: linux2
static_configs:
- targets: ['192.168.1.130:9100']
labels:
instance: sys2
- job_name: redis1
static_configs:
- targets: ['192.168.1.120:9121']
labels:
instance: redis1
- job_name: mysql
static_configs:
- targets: ['192.168.1.120:9104']
labels:
instance: db1
保存以後重啟Prometheus,查看targets:
最後登錄grafana查看MySql監控信息:
參考文檔:
https://github.com/prometheus/mysqld_exporter
最後更新:2017-11-16 09:04:14
上一篇:
Logtail技術分享(二) : 多租戶隔離技術+雙十一實戰效果
下一篇:
cacti注意事項
避免出現bitmap內存限製OUT OF MEMORY的一種方法
Java程序員在寫SQL程序時候常犯的10個錯誤
阿裏巴巴移動中台技術與應用
《Linux From Scratch》第三部分:構建LFS係統 第六章:安裝基本的係統軟件- 6.5. 創建目錄
Check Point專家點評移動支付 高回報及低技術門檻為安全軟肋
實現自動備份MySQL數據庫
[JAVA工具]判斷字符串是否為中文
5月31日雲棲精選夜讀:揭密出席第九屆中國雲計算大會的專家—近20個國家學者共話雲計算大數據生態、應用
阿裏“雲棲大會”上的這些前沿動態,你一定不能錯過!
中國航發牽手阿裏雲共同打造:航空新引擎