最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年03月04日 08:37:38   作者:LoyaChen  
Prometheus是源于 Google Borgmon的一個(gè)開源監(jiān)控系統(tǒng),用 Golang開發(fā)。被很多人稱為下一代監(jiān)控系統(tǒng)。Grafana是一個(gè)開源的圖表可視化系統(tǒng),簡單說圖表配置比較方便、生成的圖表比較漂亮。下面就介紹了利用Prometheus與Grafana對Mysql服務(wù)器性能監(jiān)控的方法。

概述

Prometheus是一個(gè)開源的服務(wù)監(jiān)控系統(tǒng),它通過HTTP協(xié)議從遠(yuǎn)程的機(jī)器收集數(shù)據(jù)并存儲在本地的時(shí)序數(shù)據(jù)庫上。它提供了一個(gè)簡單的網(wǎng)頁界面、一個(gè)功能強(qiáng)大的查詢語言以及HTTP接口等等。Prometheus通過安裝在遠(yuǎn)程機(jī)器上的exporter來收集監(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è)開源的功能豐富的數(shù)據(jù)可視化平臺,通常用于時(shí)序數(shù)據(jù)的可視化。它內(nèi)置了以下數(shù)據(jù)源的支持:

并可以通過插件擴(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,端口則是對應(yīng)的exporter的監(jiān)聽端口。

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界面,可以通過http://monitor_host:9090進(jìn)行訪問:

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

4.接下來需要在被監(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

通過http://monitor_host:3000訪問Grafana Web界面(缺省帳號/密碼為admin/admin)

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

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

System Overview:

MySQL Overview:

總結(jié)

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

相關(guān)文章

  • 史上最簡單的MySQL數(shù)據(jù)備份與還原教程(中)(三十六)

    史上最簡單的MySQL數(shù)據(jù)備份與還原教程(中)(三十六)

    這篇文章主要為大家詳細(xì)介紹了史上最簡單的MySQL數(shù)據(jù)備份與還原教程中篇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • MySQL中explain語句的基本使用教程

    MySQL中explain語句的基本使用教程

    這篇文章主要給大家介紹了關(guān)于MySQL中explain語句的基本使用教程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • MySQL實(shí)現(xiàn)自動(dòng)化部署腳本的詳細(xì)教程

    MySQL實(shí)現(xiàn)自動(dòng)化部署腳本的詳細(xì)教程

    在當(dāng)前的DevOps環(huán)境中,自動(dòng)化部署已成為提升運(yùn)維效率的核心手段,本教程將手把手教你編寫一個(gè)智能化的MySQL部署腳本,感興趣的小伙伴跟著小編一起來看看吧
    2025-03-03
  • 一文了解mysql索引的數(shù)據(jù)結(jié)構(gòu)為什么要用B+樹

    一文了解mysql索引的數(shù)據(jù)結(jié)構(gòu)為什么要用B+樹

    這篇文章主要介紹了一文了解mysql索引的數(shù)據(jù)結(jié)構(gòu)為什么用B+樹,在節(jié)點(diǎn)中存儲某段數(shù)據(jù)的首地址,并且B+樹的葉子節(jié)點(diǎn)用了一個(gè)鏈表串聯(lián)起來,便于范圍查找,下文利用各種索引的數(shù)據(jù)結(jié)構(gòu)的方法與B+樹做對比,看看它的優(yōu)勢到底是什么,感興趣的小伙伴可以參考一下
    2022-04-04
  • MySQL之join查詢優(yōu)化方式

    MySQL之join查詢優(yōu)化方式

    這篇文章主要介紹了MySQL之join查詢優(yōu)化方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • MySQL之七種SQL JOINS實(shí)現(xiàn)的圖文詳解

    MySQL之七種SQL JOINS實(shí)現(xiàn)的圖文詳解

    這篇文章主要介紹了MySQL中七種SQL JOINS的實(shí)現(xiàn)方法及圖文詳解,文中也有相關(guān)的代碼示例供大家參考,感興趣的同學(xué)可以參考閱讀下
    2023-06-06
  • 如何將mysql存儲位置遷移到一塊新的磁盤上

    如何將mysql存儲位置遷移到一塊新的磁盤上

    這篇文章主要介紹了如何將mysql存儲位置遷移到一塊新的磁盤上,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • 一站式解決mysql深分頁問題

    一站式解決mysql深分頁問題

    在后端開發(fā)或者面試中,常常會遇到深分頁的問題,深分頁問題會導(dǎo)致用戶體驗(yàn)急劇下降,甚至造成服務(wù)器崩潰,下面就來介紹一下該問題的解決,感興趣的可以了解一下
    2026-02-02
  • MySQL存儲過程的深入講解(in、out、inout)

    MySQL存儲過程的深入講解(in、out、inout)

    這篇文章主要給大家介紹了關(guān)于MySQL存儲過程(in、out、inout)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • MySQL數(shù)據(jù)庫入門之多實(shí)例配置方法詳解

    MySQL數(shù)據(jù)庫入門之多實(shí)例配置方法詳解

    這篇文章主要介紹了MySQL數(shù)據(jù)庫入門之多實(shí)例配置方法,結(jié)合實(shí)例形式分析了MySQL數(shù)據(jù)庫多實(shí)例配置相關(guān)概念、原理、操作方法與注意事項(xiàng),需要的朋友可以參考下
    2020-05-05

最新評論

凤凰县| 泰和县| 孝昌县| 东安县| 琼海市| 镇赉县| 桐城市| 大渡口区| 芜湖市| 安龙县| 富源县| 花垣县| 平原县| 邹平县| 逊克县| 元朗区| 自治县| 松溪县| 山阴县| 阿坝县| 塔河县| 西畴县| 盱眙县| 鄂州市| 龙胜| 花莲县| 镇巴县| 塔河县| 岳池县| 穆棱市| 芦山县| 辛集市| 义马市| 台湾省| 绥滨县| 陆丰市| 岱山县| 嵩明县| 高唐县| 宾阳县| 云南省|