主頁(yè) > 知識(shí)庫(kù) > Prometheus 監(jiān)控MySQL使用grafana展示

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

熱門(mén)標(biāo)簽:大眾點(diǎn)評(píng)星級(jí)酒店地圖標(biāo)注 話務(wù)外呼系統(tǒng)怎么樣 智能外呼系統(tǒng)復(fù)位 外東北地圖標(biāo)注 云南電商智能外呼系統(tǒng)價(jià)格 400電話可以辦理嗎 拉卡拉外呼系統(tǒng) 高清地圖標(biāo)注道路 臨清電話機(jī)器人

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

概述:

prometheus是由SoundCloud開(kāi)發(fā)的開(kāi)源監(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的一類(lèi)數(shù)據(jù)采集組件的總稱(chēng)。它負(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ā)送。常見(jiàn)的接收方式有:電子郵件,webhook 等。Alertmanager三種處理告警信息的方式:分組,抑制,靜默。

接下來(lái)開(kā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ò)查詢(xún)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

輸出信息類(lèi)似如下:

# 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é)果類(lèi)似如下:

# 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)題,主要就兩類(lèi):

   1)grafana 5.x和6.x組件的名稱(chēng)發(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è)工具

開(kāi)啟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)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 使用Grafana+Prometheus監(jiān)控mysql服務(wù)性能
  • 利用Prometheus與Grafana對(duì)Mysql服務(wù)器的性能監(jiān)控詳解
  • 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)用教程詳解

標(biāo)簽:定西 溫州 山西 無(wú)錫 揚(yáng)州 阿里 三明 福州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Prometheus 監(jiān)控MySQL使用grafana展示》,本文關(guān)鍵詞  Prometheus,監(jiān)控,MySQL,使用,;如發(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 監(jiān)控MySQL使用grafana展示》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Prometheus 監(jiān)控MySQL使用grafana展示的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章