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

Prometheus 監(jiān)控MySQL使用grafana展示

 更新時(shí)間:2021年08月27日 17:18:30   作者:老楊伏櫪  
這篇文章主要介紹prometheus通過(guò)mysql exporter+node exporter監(jiān)控mysql,并使用grafana進(jìn)行圖表展示的相關(guān)內(nèi)容,感興趣的效果版可以參考下文

prometheus通過(guò)exporter監(jiān)控mysql,并用grafana圖表展示

概述:

prometheus是由SoundCloud開發(fā)的開源監(jiān)控告警系統(tǒng)并且自帶時(shí)序數(shù)據(jù)庫(kù),基于Go語(yǔ)言。Prometheus根據(jù)配置的任務(wù)(job)以周期性pull的方式獲取指定目標(biāo)(target)上的指標(biāo)(metric)。

Prometheus 生態(tài)圈中包含了多個(gè)組件:

  • Prometheus Server: 根據(jù)配置完成數(shù)據(jù)采集, 服務(wù)發(fā)現(xiàn)以及數(shù)據(jù)存儲(chǔ)。
  • Push Gateway : 為應(yīng)對(duì)部分push場(chǎng)景提供的插件,監(jiān)控?cái)?shù)據(jù)先推送到 Push Gateway 上,然后再由 Prometheus Server 端采集 pull 。用于存在時(shí)間較短,可能在 Prometheus 來(lái) pull 之前就消失了的 jobs (若 Prometheus Server 采集間隔期間,Push Gateway 上的數(shù)據(jù)沒(méi)有變化, Prometheus Server 將采集到2次相同的數(shù)據(jù),僅時(shí)間戳不同)
  • Exporters(探針): 是Prometheus的一類數(shù)據(jù)采集組件的總稱。它負(fù)責(zé)從目標(biāo)處搜集數(shù)據(jù),并將其轉(zhuǎn)化為Prometheus支持的格式。與傳統(tǒng)的數(shù)據(jù)采集組件不同的是,它并不向中央服務(wù)器發(fā)送數(shù)據(jù),而是等待中央服務(wù)器主動(dòng)前來(lái)抓取。
  • Alertmanager: Prometheus server 主要負(fù)責(zé)根據(jù)基于PromQL的告警規(guī)則分析數(shù)據(jù),如果滿足PromQL定義的規(guī)則,則會(huì)產(chǎn)生一條告警,并發(fā)送告警信息到Alertmanager,Alertmanager則是根據(jù)配置處理告警信息并發(fā)送。常見的接收方式有:電子郵件,webhook 等。Alertmanager三種處理告警信息的方式:分組,抑制,靜默。

接下來(lái)開始演示

1、測(cè)試機(jī)器

prometheus-server 192.168.56.140
MySQL host01 192.168.56.103
MySQL host02 192.168.56.104

 2、配置mysql host01

MySQL使用版本:

8.0.25 MySQL Community Server

3、創(chuàng)建exporter帳號(hào)

mysqld_exporter通過(guò)查詢mysql的狀態(tài)表及狀態(tài)命令獲取數(shù)據(jù)。所以,需要先在mysql內(nèi),創(chuàng)建相應(yīng)帳號(hào)

create user 'exporter'@'%' identified by 'Xiaopang*803';
GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'%';
GRANT SELECT ON performance_schema.* TO 'exporter'@'%';
flush privileges;

4、下載,安裝mysqld_exporter

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
tar xvzf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local/.
cd /usr/local && ln -s mysqld_exporter-0.13.0.linux-amd64/ mysqld_exporter

4.1 編輯文件輸入密碼

編緝?nèi)缦挛募?,輸入exporter用戶句與密碼(與前面mysql內(nèi)創(chuàng)建的帳號(hào)密碼一致)

[root@host01 mysqld_exporter]# vi .my.cnf
[client]
user=exporter
password=Xiaopang*803

4.2 添加啟動(dòng)服務(wù)文件

[root@host01 ~]# vi /etc/systemd/system/mysqld_exporter.service

[Unit]
Description=mysqld_exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
Restart=on-failure

[Install]
WantedBy=multi-user.target

 4.3 啟動(dòng)mysqld_exporter

service mysqld_exporter start

4.4 測(cè)試驗(yàn)證

mysqld_exporter默認(rèn)使用9104端口,我們可以在瀏覽器內(nèi)輸入如下地址。查看是否有數(shù)據(jù)輸出。

輸入 http://192.168.56.103:9104/metrics

輸出信息類似如下:

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 2.5395e-05
go_gc_duration_seconds{quantile="0.25"} 3.5372e-05
go_gc_duration_seconds{quantile="0.5"} 3.9393e-05
go_gc_duration_seconds{quantile="0.75"} 5.5068e-05
go_gc_duration_seconds{quantile="1"} 0.062537624
go_gc_duration_seconds_sum 0.453204071
go_gc_duration_seconds_count 2131
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge

5、下載,安裝node_exporter

如果只安裝mysqld_exporter則無(wú)法監(jiān)控OS相關(guān)的數(shù)據(jù),所以需要安裝node_exporter進(jìn)行OS監(jiān)控。

wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz

tar xvzf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/.
cd /usr/local && ln -s node_exporter-1.2.2.linux-amd64/ node_exporter

5.1 添加啟動(dòng)服務(wù)文件

[root@host01 ~]# vi /etc/systemd/system/node_exporter.service
[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

 5.2 啟動(dòng)node_exporter

service node_exporter start

5.3 測(cè)試驗(yàn)證

node_exporter默認(rèn)使用9100端口,我們可以在瀏覽器內(nèi)輸入如下地址。查看是否有數(shù)據(jù)輸出。

輸入 http://192.168.56.103:9100/metrics

輸出結(jié)果類似如下:

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 2.5934e-05
go_gc_duration_seconds{quantile="0.25"} 4.0072e-05
go_gc_duration_seconds{quantile="0.5"} 4.7616e-05
go_gc_duration_seconds{quantile="0.75"} 6.726e-05
go_gc_duration_seconds{quantile="1"} 0.228887598
go_gc_duration_seconds_sum 0.550266258
go_gc_duration_seconds_count 793
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge

6、安裝prometheus+grafana

 使用版本:

prometheus 2.28

grafana 6.7.6

6.1 安裝

下載軟件包

wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz

6.2 解壓并添加軟鏈接

tar xvzf prometheus-2.28.1.linux-amd64.tar.gz -C /usr/local/.
cd /usr/local/
ln -s prometheus-2.28.1.linux-amd64/ prometheus

6.3 增加啟動(dòng)服務(wù)

[root@prometheus-server prometheus]# vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path="data/" \
--storage.tsdb.retention.time=15d \
--web.max-connections=512 \
--web.listen-address=:9090

 6.4 添加mysql監(jiān)控

vi /usr/local/prometheus/prometheus.yml

scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  - job_name: 'mysql'
    static_configs:
      - targets: ['192.168.56.103:9104']
        labels:
          instance: mysql_instance1
  - job_name: 'linux'
    static_configs:
      - targets: ['192.168.56.103:9100']
        labels:
          instance: mysql_instance1


6.5 啟動(dòng)prometheus

service prometheus start

6.7 查看prometheus

prometheus默認(rèn)監(jiān)控端口

http://192.168.56.140:9090/

點(diǎn)擊status->target。如果一切正常,可以看到如下mysql/linux的state為UP

7、下載,安裝grafana

wget https://dl.grafana.com/oss/release/grafana-6.7.6-1.x86_64.rpm

rpm -ivh grafana-6.7.6-1.x86_64.rpm

7.1 訪問(wèn)grafana

prometheus的展示功能很弱,為了更好的進(jìn)行圖形展示,所以我們需要grafana

輸入 http://192.168.56.140:3000/

配置data source為proemtheus的HTTP鏈接(注意是HTTP,而不是HTTPS)

 7.2導(dǎo)入mysql監(jiān)控模板

grafana數(shù)據(jù)的展示是通過(guò)模板實(shí)現(xiàn)的。grafana網(wǎng)站上面有很多共享的模板,你可以自行探索。

本例模板,我是從如下鏈接下載的。

https://grafana.com/api/dashboards/9623/revisions/4/download

版本不匹配問(wèn)題

因?yàn)榘姹静惶ヅ涞脑?,完成后有些?xiàng)目如法正常顯示。它使用的版本是grafana5.0版本,我的是6.x版本。

但是這點(diǎn)小問(wèn)題,難不倒我,我自己修改了一下。就能正常顯示了,如下是修改后的JSON文件。

josn_jb51.rar

修改過(guò)程

很多時(shí)候,很多東西并不完全能拿來(lái)即用。我們需要根據(jù)自己的需要進(jìn)行一些修改。

接下來(lái)大概花了半個(gè)多小時(shí),弄清楚了如何修改了。而后大概又花了兩小時(shí),修改完成的相應(yīng)的項(xiàng)目。

修改過(guò)程中,碰到的問(wèn)題,主要就兩類:

   1)grafana 5.x和6.x組件的名稱發(fā)生了變化。

"Buffer Pool Size of Total RAM"無(wú)法正常顯示,原因是6.0和5.0組件名不同。

替換 pmm-singlestat-panel  -> singlestat搞定

   2)exporter提取的屬性名字發(fā)生了變化

我用的是node_exporter-1.2.2,這里面關(guān)于OS提取的屬性與JSON文件的定義屬性名不匹配。

方法是直接在“http://192.168.56.103:9100/metrics”里面搜索新的屬性名,替換JSON文件里面的舊的屬性名。

例如:

替換 node_memory_MemTotal->node_memory_MemTotal_bytes
替換 node_memory_MemTotal->node_memory_MemTotal_bytes

進(jìn)行導(dǎo)入

因?yàn)槲疫M(jìn)行了一些修改,你可以import的時(shí)候,直接把JSON的內(nèi)容輸入進(jìn)去。

點(diǎn)擊Load加載,接下來(lái),選擇數(shù)據(jù)源為prometheus。

 

7.3 啟動(dòng)sysbench壓測(cè)工具

開啟sysbench工具的目的是通過(guò)壓測(cè)生成有數(shù)據(jù)變化的圖表(不然,沒(méi)有流量,數(shù)據(jù)也不會(huì)動(dòng))。

這里,我從遠(yuǎn)端壓測(cè)(在另一臺(tái)機(jī)器host02上運(yùn)行sysbench)。目的是為了生成網(wǎng)絡(luò)流量數(shù)據(jù)。

[root@host02 ~]# sysbench /usr/share/sysbench/oltp_read_write.lua --time=9180 --mysql-host=host01 --mysql-port=3306 --mysql-user=dbusr --mysql-password=Xiaopang*803 --mysql-db=db1 --table-size=50000 --tables=15 --threads=15 --report-interval=10 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 15
Report intermediate results every 10 second(s)
Initializing random number generator from current time


Initializing worker threads...

Threads started!

[ 10s ] thds: 15 tps: 112.68 qps: 2268.92 (r/w/o: 1589.76/452.30/226.85) lat (ms,95%): 277.21 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 15 tps: 113.91 qps: 2282.81 (r/w/o: 1598.47/456.52/227.81) lat (ms,95%): 211.60 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 15 tps: 109.80 qps: 2192.95 (r/w/o: 1536.66/436.69/219.59) lat (ms,95%): 240.02 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 15 tps: 112.70 qps: 2265.36 (r/w/o: 1583.17/456.79/225.40) lat (ms,95%): 193.38 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 15 tps: 101.00 qps: 2013.42 (r/w/o: 1413.32/398.10/202.00) lat (ms,95%): 325.98 err/s: 0.00 reconn/s: 0.00

7.4查看grafana,完成后效果

這里只貼出了部分圖表。

到此這篇關(guān)于Prometheus MySQL監(jiān)控使用grafana展示的文章就介紹到這了,更多相關(guān) MySQL grafana內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

  • 刪除mysql數(shù)據(jù)庫(kù)中的重復(fù)數(shù)據(jù)記錄

    刪除mysql數(shù)據(jù)庫(kù)中的重復(fù)數(shù)據(jù)記錄

    mysql中select distinct * from text不能顯示不重復(fù)的記錄,而是直接全部顯示
    2008-06-06
  • mysql字段名和關(guān)鍵字沖突的問(wèn)題

    mysql字段名和關(guān)鍵字沖突的問(wèn)題

    這篇文章主要介紹了mysql字段名和關(guān)鍵字沖突的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • MySQL數(shù)據(jù)庫(kù)的索引原理與慢SQL優(yōu)化的5大原則

    MySQL數(shù)據(jù)庫(kù)的索引原理與慢SQL優(yōu)化的5大原則

    這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)的索引原理與慢SQL優(yōu)化的5大原則,包括:建立索引的原則,慢查詢優(yōu)化基本步驟,慢查詢優(yōu)化案例,explain使用,需要的朋友可以參考下
    2023-02-02
  • mysql備份腳本以及刪除前5天的備份文件

    mysql備份腳本以及刪除前5天的備份文件

    mysql備份腳本在網(wǎng)上有很多的,在本文將為大家詳細(xì)介紹下如何刪除前5天的備份文件,感興趣的朋友不要錯(cuò)過(guò)
    2013-10-10
  • MYSQL 無(wú)法識(shí)別中文的永久解決方法

    MYSQL 無(wú)法識(shí)別中文的永久解決方法

    多數(shù)情況下,mysql在剛剛安裝時(shí)是不支持中文的,這是由于編碼的問(wèn)題,那么如何解決這個(gè)方法,本文我們就來(lái)詳細(xì)的了解一下
    2021-06-06
  • MySQL百萬(wàn)數(shù)據(jù)深度分頁(yè)優(yōu)化思路解析

    MySQL百萬(wàn)數(shù)據(jù)深度分頁(yè)優(yōu)化思路解析

    這篇文章主要為大家介紹了MySQL百萬(wàn)數(shù)據(jù)深度分頁(yè)優(yōu)化思路分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • mysql 獲取今天、昨天0點(diǎn)時(shí)間戳的實(shí)例

    mysql 獲取今天、昨天0點(diǎn)時(shí)間戳的實(shí)例

    今天小編就為大家分享一篇mysql 獲取今天、昨天0點(diǎn)時(shí)間戳的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • MySQL覆蓋索引的使用示例

    MySQL覆蓋索引的使用示例

    如果一個(gè)索引包含(或覆蓋)所有需要查詢的字段的值,稱為‘覆蓋索引’。這篇文章主要給大家介紹了關(guān)于MySQL覆蓋索引的相關(guān)資料,需要的朋友可以參考下
    2021-01-01
  • Navicat操作MYSQL的詳細(xì)過(guò)程

    Navicat操作MYSQL的詳細(xì)過(guò)程

    這篇文章主要介紹了Navicat操作MYSQL的詳細(xì)過(guò)程,包括數(shù)據(jù)表的操作修改刪除操作,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03
  • 最新評(píng)論