濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 利用Prometheus與Grafana對(duì)Mysql服務(wù)器的性能監(jiān)控詳解

利用Prometheus與Grafana對(duì)Mysql服務(wù)器的性能監(jiān)控詳解

熱門(mén)標(biāo)簽:趙縣地圖標(biāo)注 永州智能外呼系統(tǒng) 電銷機(jī)器人市場(chǎng)價(jià) 地圖標(biāo)注直通車 dq8 全地圖標(biāo)注 遂寧400電話申請(qǐng) 哈爾濱云外呼系統(tǒng)運(yùn)營(yíng)商 邯鄲400電話注冊(cè)辦理 南寧智能電銷機(jī)器人價(jià)格

概述

Prometheus是一個(gè)開(kāi)源的服務(wù)監(jiān)控系統(tǒng),它通過(guò)HTTP協(xié)議從遠(yuǎn)程的機(jī)器收集數(shù)據(jù)并存儲(chǔ)在本地的時(shí)序數(shù)據(jù)庫(kù)上。它提供了一個(gè)簡(jiǎn)單的網(wǎng)頁(yè)界面、一個(gè)功能強(qiáng)大的查詢語(yǔ)言以及HTTP接口等等。Prometheus通過(guò)安裝在遠(yuǎn)程機(jī)器上的exporter來(lái)收集監(jiān)控?cái)?shù)據(jù),這里用到了以下兩個(gè)exporter:

  1. node_exporter – 用于機(jī)器系統(tǒng)數(shù)據(jù)
  2. mysqld_exporter – 用于Mysql服務(wù)器數(shù)據(jù)

Grafana是一個(gè)開(kāi)源的功能豐富的數(shù)據(jù)可視化平臺(tái),通常用于時(shí)序數(shù)據(jù)的可視化。它內(nèi)置了以下數(shù)據(jù)源的支持:

并可以通過(guò)插件擴(kuò)展支持的數(shù)據(jù)源。

架構(gòu)圖

下面是本次部署的架構(gòu)圖

安裝并運(yùn)行Prometheus

1.在 Monitor 上安裝 Prometheus

安裝至/opt/prometheus

$ wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz
$ tar zxvf prometheus-1.5.2.linux-amd64.tar.gz
$ mv prometheus-1.5.2.linux-amd64 /opt/prometheus

2.在安裝目下編輯配置文件 prometheus.yml

vim /opt/prometheus/prometheus.yml
# my global config
global:
 scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
 evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
 # scrape_timeout is set to the global default (10s).
 # Attach these labels to any time series or alerts when communicating with
 # external systems (federation, remote storage, Alertmanager).
 external_labels:
 monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
 # - "first.rules"
 # - "second.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
 # The job name is added as a label `job=job_name>` to any timeseries scraped from this config.
 - job_name: 'prometheus'
 # metrics_path defaults to '/metrics'
 # scheme defaults to 'http'.
 static_configs:
 - targets: ['localhost:9090']
 # 以下是添加的部分
 - job_name: linux
 static_configs:
 - targets: ['172.30.251.214:9100']
 labels:
 instance: db1
 - job_name: mysql
 static_configs:
 - targets: ['172.30.251.214:9104']
 labels:
 instance: db1

其中:172.30.251.214是MySQL的IP,端口則是對(duì)應(yīng)的exporter的監(jiān)聽(tīng)端口。

3.啟動(dòng)Prometheus

[loya@centos6 prometheus]$ ./prometheus
INFO[0000] Starting prometheus (version=1.5.2, branch=master, revision=bd1182d29f462c39544f94cc822830e1c64cf55b) source=main.go:75
INFO[0000] Build context (go=go1.7.5, user=root@a8af9200f95d, date=20170210-14:41:22) source=main.go:76
INFO[0000] Loading configuration file prometheus.yml source=main.go:248
INFO[0000] Loading series map and head chunks... source=storage.go:373
INFO[0000] 0 series loaded. source=storage.go:378
INFO[0000] Starting target manager... source=targetmanager.go:61
INFO[0000] Listening on :9090 source=web.go:259

Prometheus內(nèi)置了一個(gè)web界面,可以通過(guò)http://monitor_host:9090進(jìn)行訪問(wèn):

在Status->Targets頁(yè)面下,可以看到我們配置的兩個(gè)Target,它們的State為DOWN。

4.接下來(lái)需要在被監(jiān)控機(jī)器上安裝并運(yùn)行exporter

下載exporters并解壓:

$ mkdir /opt/prometheus/prometheus_exporters
$ cd /opt/prometheus/prometheus_exporters
$ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0-rc.1/node_exporter-0.14.0-rc.1.linux-amd64.tar.gz
$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.9.0/mysqld_exporter-0.9.0.linux-amd64.tar.gz
$ tar zxvf node_exporter-0.14.0-rc.1.linux-amd64.tar.gz
$ tar zxvf mysqld_exporter-0.9.0.linux-amd64.tar.gz
# 將各自的可執(zhí)行文件移動(dòng)到/opt/prometheus/prometheus_exporters
$ ll /opt/prometheus/prometheus_exporters
total 24464
-rwxr-xr-x 1 root root 12182376 Feb 23 19:01 mysqld_exporter
-rwxr-xr-x 1 root root 12862209 Feb 23 19:01 node_exporter

運(yùn)行node_exporter

$ cd /opt/prometheus/prometheus_exporters
$ ./node_exporter 
INFO[0000] Starting node_exporter (version=0.14.0-rc.1, branch=master, revision=5a07f4173d97fa0dd307db5bd3c2e6da26a4b16e) source="node_exporter.go:136"
INFO[0000] Build context (go=go1.7.4, user=root@ed143c8f2fcd, date=20170116-16:00:03) source="node_exporter.go:137"
INFO[0000] No directory specified, see --collector.textfile.directory source="textfile.go:57"
INFO[0000] Enabled collectors: source="node_exporter.go:156"
INFO[0000] - entropy source="node_exporter.go:158"
INFO[0000] - loadavg source="node_exporter.go:158"
INFO[0000] - stat source="node_exporter.go:158"
INFO[0000] - diskstats source="node_exporter.go:158"
INFO[0000] - textfile source="node_exporter.go:158"
INFO[0000] - vmstat source="node_exporter.go:158"
INFO[0000] - meminfo source="node_exporter.go:158"
INFO[0000] - filefd source="node_exporter.go:158"
INFO[0000] - filesystem source="node_exporter.go:158"
INFO[0000] - mdadm source="node_exporter.go:158"
INFO[0000] - netdev source="node_exporter.go:158"
INFO[0000] - sockstat source="node_exporter.go:158"
INFO[0000] - time source="node_exporter.go:158"
INFO[0000] - zfs source="node_exporter.go:158"
INFO[0000] - edac source="node_exporter.go:158"
INFO[0000] - hwmon source="node_exporter.go:158"
INFO[0000] - netstat source="node_exporter.go:158"
INFO[0000] - uname source="node_exporter.go:158"
INFO[0000] - conntrack source="node_exporter.go:158"
INFO[0000] Listening on :9100 source="node_exporter.go:176"

mysqld_exporter需要連接到MySQL,所以需要MySQL權(quán)限,我們?yōu)槠鋭?chuàng)建用戶并賦予所需的權(quán)限:

mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'prom'@'localhost' identified by 'abc123';
mysql> GRANT SELECT ON performance_schema.* TO 'prom'@'localhost';

創(chuàng)建.my.cnf文件并運(yùn)行mysqld_exporter:

$ cd /opt/prometheus/prometheus_exporters
$
$ cat  EOF > .my.cnf
[client]
user=prom
password=abc123
EOF
$
$ ./mysqld_exporter -config.my-cnf=".my.cnf"
INFO[0000] Starting mysqld_exporter (version=0.9.0, branch=master, revision=8400af20ccdbf6b5e0faa2c925c56c48cd78d70b) source=mysqld_exporter.go:432
INFO[0000] Build context (go=go1.6.3, user=root@2c131c66ca20, date=20160926-18:28:09) source=mysqld_exporter.go:433
INFO[0000] Listening on :9104 source=mysqld_exporter.go:451

回到Prometheus web界面Status->Targets,可以看到兩個(gè)Target的狀態(tài)已經(jīng)變成UP了:

安裝和運(yùn)行Grafana

安裝:

Grafana 的安裝官方文檔比較清晰,這里不再贅述。

配置:

編輯配置文件/etc/grafana/grafana.ini,修改dashboards.json段落下兩個(gè)參數(shù)的值:

[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards

導(dǎo)入Prometheus Dashboard:

$ git clone https://github.com/percona/grafana-dashboards.git
$ cp -r grafana-dashboards/dashboards /var/lib/grafana

啟動(dòng):

$ /etc/init.d/grafana-server start

通過(guò)http://monitor_host:3000訪問(wèn)Grafana Web界面(缺省帳號(hào)/密碼為admin/admin)

登錄后,通過(guò)Data Sources頁(yè)面添加數(shù)據(jù)源:

然后就可以通過(guò)選擇不同的儀表盤(pán)(左上角)和時(shí)間段(右上角)來(lái)呈現(xiàn)圖表了:

System Overview:

MySQL Overview:

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

您可能感興趣的文章:
  • 使用Grafana+Prometheus監(jiān)控mysql服務(wù)性能
  • SpringBoot使用prometheus監(jiān)控的示例代碼
  • springboot2.X整合prometheus監(jiān)控的實(shí)例講解
  • SpringBoot+Prometheus+Grafana實(shí)現(xiàn)應(yīng)用監(jiān)控和報(bào)警的詳細(xì)步驟
  • Prometheus的安裝和配置教程詳解
  • Prometheus 入門(mén)教程之SpringBoot 實(shí)現(xiàn)自定義指標(biāo)監(jiān)控
  • Prometheus開(kāi)發(fā)中間件Exporter過(guò)程詳解
  • springboot集成普羅米修斯(Prometheus)的方法
  • 使用 prometheus python 庫(kù)編寫(xiě)自定義指標(biāo)的方法(完整代碼)
  • 使用prometheus統(tǒng)計(jì)MySQL自增主鍵的剩余可用百分比
  • 使用Prometheus+Grafana的方法監(jiān)控Springboot應(yīng)用教程詳解
  • Prometheus 監(jiān)控MySQL使用grafana展示

標(biāo)簽:定西 南寧 上海 張家界 浙江 阿里 鄂州 中衛(wèi)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《利用Prometheus與Grafana對(duì)Mysql服務(wù)器的性能監(jiān)控詳解》,本文關(guān)鍵詞  利用,Prometheus,與,Grafana,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《利用Prometheus與Grafana對(duì)Mysql服務(wù)器的性能監(jiān)控詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于利用Prometheus與Grafana對(duì)Mysql服務(wù)器的性能監(jiān)控詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    南漳县| 噶尔县| 乃东县| 长岭县| 桐乡市| 抚远县| 阿拉善盟| 当雄县| 永兴县| 师宗县| 临沭县| 绩溪县| 方山县| 鹤岗市| 水城县| 包头市| 云梦县| 临潭县| 朝阳县| 泸州市| 齐齐哈尔市| 四子王旗| 太康县| 夏邑县| 辉县市| 汕尾市| 九寨沟县| 西乡县| 平果县| 安徽省| 新河县| 吴旗县| 定陶县| 综艺| 团风县| 永和县| 兴业县| 静乐县| 怀集县| 安平县| 崇明县|