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

prometheus監(jiān)控MySQL并實(shí)現(xiàn)可視化的操作詳解

 更新時(shí)間:2024年04月26日 08:51:38   作者:阿龍先生啊  
mysqld_exporter?是一個(gè)用于監(jiān)控?MySQL?服務(wù)器的開源工具,它是由?Prometheus?社區(qū)維護(hù)的一個(gè)官方?Exporter,本文給大家介紹了prometheus監(jiān)控MySQL并實(shí)現(xiàn)可視化的操作,文中通過代碼和圖文講解的非常詳細(xì),需要的朋友可以參考下

 一、概述

mysqld_exporter 是一個(gè)用于監(jiān)控 MySQL 服務(wù)器的開源工具,它是由 Prometheus 社區(qū)維護(hù)的一個(gè)官方 Exporter。該工具通過連接到 MySQL 服務(wù)器并執(zhí)行各種查詢來收集關(guān)于 MySQL 服務(wù)器性能和狀態(tài)的指標(biāo),并將這些指標(biāo)暴露給 Prometheus 監(jiān)控系統(tǒng)。

以下是 mysqld_exporter 的一些主要特點(diǎn)和功能:

  • 指標(biāo)收集: mysqld_exporter 通過執(zhí)行 SQL 查詢來收集關(guān)于 MySQL 服務(wù)器的各種指標(biāo),包括查詢性能、連接狀態(tài)、InnoDB 狀態(tài)、復(fù)制狀態(tài)等。
  • Prometheus 兼容: mysqld_exporter 輸出的指標(biāo)符合 Prometheus 的指標(biāo)格式,并且可以直接由 Prometheus 進(jìn)行收集和存儲(chǔ)。
  • 靈活的配置: 用戶可以通過配置文件或命令行參數(shù)來配置 mysqld_exporter 的行為,包括指定要監(jiān)控的 MySQL 實(shí)例、連接參數(shù)、指標(biāo)的收集頻率等。
  • 安全性: mysqld_exporter 支持通過 TLS/SSL 進(jìn)行安全連接,以確保監(jiān)控?cái)?shù)據(jù)的機(jī)密性和完整性。
  • 多版本支持: mysqld_exporter 可以與多個(gè) MySQL 版本兼容,并且可以通過配置選擇性地啟用或禁用特定版本的指標(biāo)收集。
  • 自定義查詢: 用戶可以通過配置文件自定義要執(zhí)行的 SQL 查詢,以收集特定于其環(huán)境的自定義指標(biāo)。
  • 易于部署: mysqld_exporter 可以作為一個(gè)獨(dú)立的二進(jìn)制文件部署,并且支持多種部署方式,包括 Docker 容器、系統(tǒng)服務(wù)等。

總的來說,mysqld_exporter 是一個(gè)功能強(qiáng)大且易于使用的工具,可以幫助用戶監(jiān)控和診斷其 MySQL 服務(wù)器的性能和健康狀態(tài),從而及時(shí)發(fā)現(xiàn)和解決潛在的問題。

1.1下載解壓mysqld_exporter

wget --no-check-certificate   https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
 
 
cd mysqld_exporter-0.15.1.linux-amd64
cp -ar mysqld_exporter /usr/local/bin/
chmod +x /usr/local/bin/mysqld_exporter

1.2創(chuàng)建MySQL授權(quán)用戶

# 創(chuàng)建數(shù)據(jù)庫(kù)用戶。
CREATE USER 'mysql_exporter'@'192.168.2.139' IDENTIFIED BY 'Abcdef123!.';
 
# 對(duì)mysql_exporter用戶授權(quán)
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'192.168.2.139';

1.3配置my.cnf

創(chuàng)建mysql配置文件、運(yùn)行時(shí)可免密碼連接數(shù)據(jù)庫(kù)

cd mysqld_exporter-0.15.1.linux-amd64
 
cat > my.cnf << EOF
[client]
host=192.168.2.211
port=3306
user=mysql_exporter
password=Abcdef123!.
 
[client.servers]
host=192.168.2.211
port=3306
user=mysql_exporter
password=Abcdef123!.
 
EOF

1.4啟動(dòng)mysqld_exporter

直接命令行啟動(dòng)mysql_exporter客戶端

nohup ./mysqld_exporter --config.my-cnf=./my.cnf &

也可以注冊(cè)為服務(wù)

cat <<EOF>>  /usr/lib/systemd/system/mysqld-exporter.service 
[Unit]
Description=mysqld_exporter
 
 
[Service]
User=root
ExecStart=/root/prome/mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter --config.my-cnf /root/prome/mysqld_exporter-0.15.1.linux-amd64/my.cnf --web.listen-address=0.0.0.0:9104 \
--collect.slave_status \
--collect.binlog_size \
--collect.info_schema.processlist \
--collect.info_schema.innodb_metrics \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.perf_schema.replication_group_member_stats
Restart=on-failure
 
[Install]
WantedBy=multi-user.targe
EOF

1.5prometheus配置修改

修改prometheus-cfg.yaml文件,添加如下

  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.124.16:9104']
 
kubectl apply  -f prometheus-alertmanager-cfg.yaml
kubectl delete -f prometheus-deploy.yaml
kubectl apply  -f prometheus-deploy.yaml
 
 
curl -XPOST localhost:9090/-/reload

登錄 promethetus 可以看到采集到了

二、Grafana展示

官網(wǎng)模板地址Dashboards | Grafana Labs

mysql-overview_rev5.json

導(dǎo)入模板

選擇“Import Json File”

導(dǎo)入模板后,選擇import

展示成功

以上就是prometheus監(jiān)控MySQL并實(shí)現(xiàn)可視化的操作詳解的詳細(xì)內(nèi)容,更多關(guān)于prometheus監(jiān)控MySQL的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論