CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
export DATA_SOURCE_NAME='user:password@(hostname:3306)/' ./mysqld_exporter <flags>
[client] user=exporter password=exporter 而後啓動mysqld_exporter mysqld_exporter -config.my-cnf=".my.cnf"
scrape_configs: - job_name: prometheus static_configs: - targets: ['localhost:9090'] labels: instance: prometheus - job_name: linux static_configs: # 192.168.1.7爲node_exporter所在服務器的IP;9100爲node_exporter暴露的端口 - targets: ['192.168.1.7:9100'] labels: #db1爲實例名,之後在Grafana獲取prometheus時,要配置prometheus全部服務器的host爲db1 instance: db1 - job_name: mysql static_configs: # 192.168.1.7爲mysqld_exporter所在服務器的IP;9100爲mysqld_exporter暴露的端口 - targets: ['192.168.1.7:9104'] labels: instance: db1
啓動prometheus,並查看配置的Linux和Mysql節點狀態是否爲Upjava
下載Grafana,並按文檔安裝node
下載Percona提供的Dashboards
若是grafana與prometheus不在一臺服務器,須要指定prometheus的主機名(此例中應該爲db1),access要選擇proxy,表示由grafana處理請求,而不是直接請求prometheus。mysql
正常狀況下能夠看見Mysql和System的儀表盤,若是顯示不出來,請檢查下面幾個方面linux
- 檢查Grafana和grafana-dashboards版本(grafana-4.2 匹配grafana-dashboards-1.3.2,不匹配當前最新版本1.15). - Grafana使用grafana用戶運行,因此須要檢查/etc/grafana,/var/lib/grafana,/usr/grafana目錄全部者和用戶組是不是grafana - 對於grafana 3.X版本,還須要作以下處理,參見[grafana-dashboards](https://github.com/percona/grafana-dashboards) > sed -i 's/expr=\(.\)\.replace(\(.\)\.expr,\(.\)\.scopedVars\(.*\)var \(.\)=\(.\)\.interval/expr=\1.replace(\2.expr,\3.scopedVars\4var \5=\1.replace(\6.interval, \3.scopedVars)/' /usr/share/grafana/public/app/plugins/datasource/prometheus/datasource.js > sed -i 's/,range_input/.replace(\/"{\/g,"\\"").replace(\/}"\/g,"\\""),range_input/; s/step_input:""/step_input:this.target.step/' /usr/share/grafana/public/app/plugins/datasource/prometheus/query_ctrl.js - grafana全部服務器是否配置prometheus全部服務器的IP與Host映射,如上的Prometheus的配置,host應該配置成db1
9.安裝成功結果以下圖:
git