欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

概述

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

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

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

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

架構圖

下面是本次部署的架構圖

安裝并運行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,端口則是對應的exporter的監(jiān)聽端口。

3.啟動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內置了一個web界面,可以通過http://monitor_host:9090進行訪問:

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

4.接下來需要在被監(jiā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í)行文件移動到/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

運行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權限,我們?yōu)槠鋭?chuàng)建用戶并賦予所需的權限:

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文件并運行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,可以看到兩個Target的狀態(tài)已經(jīng)變成UP了:

安裝和運行Grafana

安裝:

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

配置:

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

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

導入Prometheus Dashboard:

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

啟動:

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

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

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

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

System Overview:

MySQL Overview:

總結

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

相關文章

  • MySQL count(*/column)查詢優(yōu)化的實現(xiàn)

    MySQL count(*/column)查詢優(yōu)化的實現(xiàn)

    count()是SQL中一個常用的聚合函數(shù),其被用來統(tǒng)計記錄的總數(shù),本文主要介紹了MySQL count(*/column)查詢優(yōu)化的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2024-09-09
  • 關于加強MYSQL安全的幾點建議

    關于加強MYSQL安全的幾點建議

    現(xiàn)在php+mysql組合越來越多,這里腳本之家小編就為大家分享一下mysql的安裝設置的幾個小技巧
    2016-04-04
  • pymysql.err.DataError:(1264, ")異常的有效解決方法(最新推薦)

    pymysql.err.DataError:(1264, ")異常的有效解決方法(最新推薦)

    遇到pymysql.err.DataError錯誤時,錯誤代碼1264通常指的是MySQL數(shù)據(jù)庫中的Out of range value for column錯誤,這意味著你嘗試插入或更新的數(shù)據(jù)超過了對應數(shù)據(jù)庫列所允許的范圍,這篇文章主要介紹了pymysql.err.DataError:(1264, ")異常的有效問題,需要的朋友可以參考下
    2024-05-05
  • MySQL中group_concat函數(shù)深入理解

    MySQL中group_concat函數(shù)深入理解

    本文通過實例介紹了MySQL中的group_concat函數(shù)的使用方法,需要的朋友可以適當參考下
    2012-11-11
  • MySQL skip-character-set-client-handshake導致的一個字符集問題

    MySQL skip-character-set-client-handshake導致的一個字符集問題

    這篇文章主要介紹了MySQL skip-character-set-client-handshake導致的一個字符集問題,需要的朋友可以參考下
    2014-07-07
  • MYSQL大表加索引的實現(xiàn)

    MYSQL大表加索引的實現(xiàn)

    本文主要介紹了MYSQL大表加索引的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-05-05
  • MySQL多表查詢的具體實例

    MySQL多表查詢的具體實例

    這篇文章主要介紹了MySQL多表查詢的具體實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01
  • mybatis mysql delete in操作只能刪除第一條數(shù)據(jù)的方法

    mybatis mysql delete in操作只能刪除第一條數(shù)據(jù)的方法

    這篇文章主要介紹了mybatis mysql delete in操作只能刪除第一條數(shù)據(jù)的問題及解決方法,需要的朋友可以參考下
    2018-09-09
  • Mysql計算字段長度函數(shù)之LENGTH函數(shù)

    Mysql計算字段長度函數(shù)之LENGTH函數(shù)

    MySQL length是指在MySQL數(shù)據(jù)庫中,用于獲取字符串或二進制數(shù)據(jù)類型的長度,下面這篇文章主要給大家介紹了關于Mysql計算字段長度函數(shù)之LENGTH函數(shù)的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-05-05
  • MySQL中NULL對索引的影響深入講解

    MySQL中NULL對索引的影響深入講解

    這篇文章主要給大家介紹了關于MySQL中NULL對索引的影響的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用MySQL具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-07-07

最新評論