利用Prometheus和Grafana監(jiān)控MySQL-創(chuàng)新互聯(lián)

 一、 Prometheus 是一個開源的服務(wù)監(jiān)控系統(tǒng)和時間序列數(shù)據(jù)庫。:

創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元營山做網(wǎng)站,已為上家服務(wù),為營山各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792

官方GitHub地址為:https://github.com/prometheus/prometheus

官方地址:https://prometheus.io/

官方拓?fù)鋱D如下

利用Prometheus和Grafana監(jiān)控MySQL

特性:

  • 高維度數(shù)據(jù)模型

  • 自定義查詢語言

  • 可視化數(shù)據(jù)展示

  • 高效的存儲策略

  • 易于運維

  • 提供各種客戶端開發(fā)庫

  • 警告和報警

  • 數(shù)據(jù)導(dǎo)出

二、安裝Prometheus(服務(wù)器環(huán)境為Centos7.2,本實驗服務(wù)端跟被監(jiān)控MySQL在同一臺服務(wù)器)

前提條件請關(guān)閉SELinux與Firewalld(centos6  為iptables)

下載安裝prometheus $ wget https://github.com/prometheus/prometheus/releases/download/v1.7.1/prometheus-1.7.1.linux-amd64.tar.gz $ mkdir  /opt/prometheus $ tar zxf prometheus-1.7.1.linux-amd64.tar.gz  -C /opt/prometheus --strip-components=1 編輯配置prometheus.yml文件,內(nèi)容如下: global:   scrape_interval:     15s   evaluation_interval: 15s   external_labels:       monitor: 'codelab-monitor' rule_files: scrape_configs:   - job_name: 'prometheus'     static_configs:       - targets: ['192.168.1.199:9090']   - job_name: linux     static_configs:       - targets: ['192.168.1.199:9100']         labels:           instance: db1   - job_name: mysql     static_configs:       - targets: ['192.168.1.199:9104']         labels:           instance: db1 后臺啟動prometheus  nohup /opt/prometheus/prometheus -config.file=prometheus.yml &  tail -200f nohup.out  time="2017-06-12T11:51:16+08:00" level=info msg="Starting prometheus (version=1.7.0, branch=master, revision=bfa37c8ee39d11078662dce16c162a61dccf616c)" source="main.go:88"  time="2017-06-12T11:51:16+08:00" level=info msg="Build context (go=go1.8.3, user=root@7a6329cc02bb, date=20170607-09:43:48)" source="main.go:89"  time="2017-06-12T11:51:16+08:00" level=info msg="Host details (Linux 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 monitor (none))" source="main.go:90"  time="2017-06-12T11:51:16+08:00" level=info msg="Loading configuration file prometheus.yml" source="main.go:252"  time="2017-06-12T11:51:16+08:00" level=info msg="Loading series map and head chunks..." source="storage.go:428"  time="2017-06-12T11:51:16+08:00" level=info msg="2200 series loaded." source="storage.go:439"  time="2017-06-12T11:51:16+08:00" level=info msg=" source="web.go:259"Prometheus提供一個內(nèi)置的web界面。我們可以通過http://192.168.1。199:9090訪問

利用Prometheus和Grafana監(jiān)控MySQL

在 Status -> Targets 頁面下,我們可以看到我們配置的兩個Target,它們的 State

利用Prometheus和Grafana監(jiān)控MySQL

三、接下來我們安裝client客戶端

1、安裝client $ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz $ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz $ mkdir /opt/prometheus_exporters $ tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1  && tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1 2、啟動os監(jiān)控client  nohup /opt/prometheus_exporters/node_exporter &  tail -200f nohup.out  time="2017-06-12T11:28:52+08:00" level=info msg=" - hwmon" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info msg=" - netstat" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info msg=" - stat" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info msg=" - vmstat" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info source="node_exporter.go:186" 3、mysqld_exporter需要連接到MySQL,需要授權(quán) mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'monitor'@'localhost' identified by 'test123'; mysql> GRANT SELECT ON performance_schema.* TO 'monitor'@'localhost'; 4、創(chuàng)建 .my.cnf 文件并運行mysqld_exporter [root@monitor prometheus_exporters]# cat .my.cnf  [client] user=monitor password=test123 [root@monitor prometheus_exporters]# export DATA_SOURCE_NAME="monitor:test123@(monitor:3306)/" #####(monitor:3306)/此monitor為主機名 啟動mysqld_exporter nohup /opt/prometheus_exporters/mysqld_exporter -config.my-cnf=".my.cnf" & tail -200f nohup.out time="2017-06-12T11:30:07+08:00" level=info msg="Starting mysqld_exporter (version=0.10.0, branch=master, revision=80680068f15474f87847c8ee8f18a2939a26196a)" source="mysqld_exporter.go:460" time="2017-06-12T11:30:07+08:00" level=info msg="Build context (go=go1.8.1, user=root@3b0154cd9e8e, date=20170425-11:24:12)" source="mysqld_exporter.go:461" time="2017-06-12T11:30:08+08:00" level=info msg=" source="mysqld_exporter.go:479"

我們回到192.168.1.199:9090,可以看到

 Status -> Targets 頁面

利用Prometheus和Grafana監(jiān)控MySQL

四、安裝和運行Grafana

1、安裝Grafana #wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.2-1.x86_64.rpm  #yum localinstall grafana-4.3.2-1.x86_64.rpm  替換grafana的dashboards Grafana 并沒有太多的配置好的圖表模板,除了 Percona 開源的一些外,很多需要自行配置。 下載dashboards(https://github.com/percona/grafana-dashboards) git clone https://github.com/percona/grafana-dashboards.git cp -r grafana-dashboards/dashboards /var/lib/grafana/ 2、編輯配置文件 /etc/grafana/grafana.ini ,修改 dashboards.json 段落下兩個參數(shù)的值: [dashboards.json] enabled = true path = /var/lib/grafana/dashboards 2、運行 Grafana  systemctl start grafana-server # [root@monitor prometheus_exporters]# ps aux |grep grafana root      3211  0.0  0.0 112664   972 pts/1    S+   11:40   0:00 grep --color=auto grafana grafana  21241  0.3  0.8 805720 39620 ?        Ssl  6月12   4:42 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile= cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins

我們可通過 http://192.168.1.199:3000 訪問Grafana網(wǎng)頁界面(缺省的帳號/密碼為admin/admin):

利用Prometheus和Grafana監(jiān)控MySQL

登錄并設(shè)置數(shù)據(jù)源

利用Prometheus和Grafana監(jiān)控MySQL

利用Prometheus和Grafana監(jiān)控MySQL

至此大功告成

我們可以看到os與數(shù)據(jù)庫監(jiān)控數(shù)據(jù)了

利用Prometheus和Grafana監(jiān)控MySQL

利用Prometheus和Grafana監(jiān)控MySQL

利用Prometheus和Grafana監(jiān)控MySQL

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

分享題目:利用Prometheus和Grafana監(jiān)控MySQL-創(chuàng)新互聯(lián)
文章來源:http://bm7419.com/article20/hcsjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、外貿(mào)建站品牌網(wǎng)站設(shè)計、Google網(wǎng)站策劃、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)