百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 热门文章 > 正文

使用mysqld_exporter监控MySQL并展示数据

bigegpt 2025-05-21 12:10 4 浏览

mysqld_exporter是Prometheus用于监控MySQL指标的一个导出器,支持对MySQL 5.5以上进行监控。用来抓取mysql的相关信息,下面是mysqld_exporter 安装的相关信息


环境: 192.168.31.40 MariaDB-5.5.68 mysqld_exporter_0.12.1


一、下载mysqld_exporter 并安装


官方网址:
https://prometheus.io/download/



选择对应的版本下载

[root@node-1 ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz


#解压 ,移动到/usr/local 路径下 并从命名为 mysqld_exporter

[root@node-1 ~]# tar -xf mysqld_exporter-0.12.1.linux-amd64.tar.gz

[root@node-1 ~]# mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysqld_exporter


二、登陆数据库,创建授权账户

[root@node-1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 278
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant PROCESS, REPLICATION CLIENT, SELECT on *.* to 'exporter'@'localhost' identified by 'fxkjnj';
MariaDB [(none)]> flush privileges;


#注意: 这里我只授权了本机登陆,因为 mysqld_exporter 也安装在数据库这台主机上


#退出验证,使用exporter 用户登陆数据库

 [root@node-1 ~]# mysql -uroot -p'fxkjnj'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 286
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*A88C2B91E04CF458B1EFF3228824DEA7CE4ABA22' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> 


三、创建mysqld_exporter 的配置文件 my.cnf


[root@node-1 mysqld_exporter]# vim /usr/local/mysqld_exporter/my.cnf

[client]

host=192.168.31.40

port=3306

user=exporter

password=fxkjnj


四、创建mysql_exporter 启动文件,使用systemd 管理

[root@node-1 mysqld_exporter]# vim /etc/systemd/system/mysqld_exporter.service 
[Unit]
Description=mysqld_exporter
Documentation=mysqld_exporter-doc
 
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf
 
[Install]
WantedBy=multi-user.target


#初始化并启动mysqld_exporter


[root@node-1 mysqld_exporter]# systemctl daemon-reload

[root@node-1 mysqld_exporter]# systemctl start mysqld_exporter.service


#查看进程及端口

[root@node-1 ~]# ps -ef | grep mysqld_exporter | grep -v grep

root 60884 1 0 16:55 ? 00:00:02 /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf


[root@node-1 ~]# netstat -ntlup | grep mysqld_export

tcp6 0 0 :::9104 :::* LISTEN 60884/mysqld_export


五、修改prometheus 配置文件 指定 mysqld_exporter 采集器地址


[root@prometheus ~]#vim /etc/prometheus/prometheus.yml

[root@prometheus ~]#vim /etc/prometheus/prometheus.yml
..............

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['192.168.31.250:9090']


  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.31.40:9104']

..............


#热加载prometheus

[root@prometheus ~]# ps -ef | grep prometheus | grep -v grep | awk '{print $2}' | xargs kill -HUP


#登陆到prometheus 控制台,可以在status/targets 里看到 mysqld_exporter 采集器相关信息


点击
http://192.168.31.40:9104/metrics 可以看到相关数据



六、使用grafana 展示 mysqld_exporter 采集器采集的数据


PS: grafana 添加 prometheus 数据源 过程 省略。。。。。。。。。。


为了最终的效果,我们使用 Grafana 官网小伙伴提供的dashboard 来展示数据

模板地址:
https://grafana.com/grafana/dashboards/7362 ID: 7362



点击 Download JSON , 下载完后 登陆Grafana ,默认地址 http://IP:3000

找到左侧 + 号,import 导入刚刚下载的json 文件





选择好数据源

稍等片刻,就可以看到 最终的效果



本篇只涉及到 使用mysqld_exporter 收集mysql 数据并展示 ,并没有写到 触发器的配置告警,这个等后面再更新

相关推荐

【机器学习】数据挖掘神器LightGBM详解(附代码)

来源:机器学习初学者本文约11000字,建议阅读20分钟本文为你介绍数据挖掘神器LightGBM。LightGBM是微软开发的boosting集成模型,和XGBoost一样是对GBDT...

3分钟,用DeepSeek全自动生成语音计算器,还带括号表达式!

最近,大家慢慢了解到了DeepSeek的强大功能,特别是它在编程领域也同样强大。编程零基础小白,一行代码不用写,也能全自动生成一个完整的、可运行的软件来!很多程序员一直不相信小白不写代码也能编软件!下...

python学习笔记 3.表达式

在Python中,表达式是由值、变量和运算符组成的组合。以下是一些常见的Python表达式:算术表达式:由数值和算术运算符组成的表达式,如加减乘除等。例如:5+3、7*2、10/3等。字符...

5.7 VS 8.x,为什么用户不升级MySql

一般来说为了更好的功能和性能,都需要将软件升级到最新的版本,然而在开源软件中,由于一些开发商变化或其他的问题(开源授权变化),致使人们不愿使用最新的版本,一个最典型的问题就是CentOS操作系统。还有...

大厂高频:讲一下MySQL主从复制

大家经常听说主从复制,那么主从复制的意义?能解决的问题有哪些?主从复制能解决的问题就是在我们平时开发的程序中操作数据库的时候,大多数的情况查询的操作大大超过了写的操作,也就说对数据库读取数据的压力比较...

MYSQL数据库的五大安全防护措施

以技术为基础的企业里最有价值的资产莫过于是客户或者其数据库中的产品信息了。因此,在这样的企业中,保证数据库免受外界攻击是数据库管理的重要环节。很多数据库管理员并没有实施什么数据库保护措施,只是因为觉得...

docker安装mysql

准备工作已安装Docker环境(官方安装文档)终端/命令行工具(Linux/macOS/WSL)步骤1:拉取MySQL镜像打开终端执行以下命令,拉取官方MySQL镜像(默认最新版本):d...

Zabbix监控系统系列之六:监控 mysql

zabbix监控mysql1、监控规划在创建监控项之前要尽量考虑清楚要监控什么,怎么监控,监控数据如何存储,监控数据如何展现,如何处理报警等。要进行监控的系统规划需要对Zabbix很了解,这里只是...

详解MySQL的配置文件及优化

#头条创作挑战赛#在Windows系统中,MySQL服务器启动时最先读取的是my.ini这个配置文件。在Linux系统中,配置文件为my.cnf,其路径一般为/etc/my.cnf或/etc/mysq...

Mysql 几个批处理执行脚本

学习mysql过程中,需要创建测试数据,并让多人每人一个数据库连接并进行作业检查。整合部分批处理创建数据批量创建数据库DELIMITER$CREATEPROCEDURECreateDatab...

MySQL学到什么程度?才有可以在简历上写精通

前言如今互联网行业用的最多就是MySQL,然而对于高级Web面试者,尤其对于寻找30k下工作的求职者,很多MySQL相关知识点基本都会涉及,如果面试中,你的相关知识答的模糊和不切要点,基...

mysql 主、从服务器配置“Slave_IO_Running: Connecting” 问题分析

#在进行mysql主、从服务器配置时,”SHOWSLAVESTATUS;“查看从库状态Slave_IO_Runing,出现错误:“Slave_IO_Running:Connectin...

MYSQL数据同步

java开发工程师在实际的开发经常会需要实现两台不同机器上的MySQL数据库的数据同步,要解决这个问题不难,无非就是mysql数据库的数据同步问题。但要看你是一次性的数据同步需求,还是定时数据同步,亦...

「MySQL 8」MySQL 5.7都即将停只维护了,是时候学习一波MySQL 8了

MySQL8新特性选择MySQL8的背景:MySQL5.6已经停止版本更新了,对于MySQL5.7版本,其将于2023年10月31日停止支持。后续官方将不再进行后续的代码维护。另外,...

Prometheus监控mysql

通过Prometheus监控Mysql,我们需要在Mysql端安装一个mysql-exporter,然后Prometheus通过mysql-exporter暴露的端口抓取数据。1.安装一个MYSQL配...