Exporters | 安装mysqld_exporter

发布于:2025-08-06 ⋅ 阅读:(19) ⋅ 点赞:(0)

一、下载linux版本的mysqld_exporter

下载地址:https://prometheus.io/download/

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz

二、解压安装包

tar -zxvf mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /data
mv /data/mysqld_exporter-0.14.0.linux-amd64 /data/mysqld_exporter
cp /data/mysqld_exporter /usr/sbin

三、创建数据库连接账号并授权

create user 'mysqlexporter'@'%' identified by '123456';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqlexporter'@'%' identified by '123456';
#GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqlexporter'@'%' WITH GRANT OPTIONS;
flush privileges;

四、创建连接数据库的配置文件

cd /etc/mysqld_exporter
vim my.cnf
[client]
host=127.0.0.1
port=3306
user=mysqlexporter
password=123456

五、启动服务(查询启动服务是否正常)

/etc/mysqld_exporter/mysqld_exporter --config.my-cnf="/etc/mysqld_exporter/my.cnf"

六、新建启动服务

vim /usr/lib/systemd/system/mysqld_exporter.service

[Unit]
Description=mysqld_exporter
After=network.target

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

[Install]
WantedBy=multi-user.target

七、启动服务

systemctl daemon-reload
systemctl enable --now mysqld_exporter
systemctl status mysqld_exporter
ss -nlt|grep 9104

八、prometheus 收集数据并监控

vi /prometheus/prometheus.yml
- job_name: mysql_exporter
    static_configs:
    - targets: ['192.168.168.172:9104']

通过以下参数控制收集数据

启动参数                                 MySQL版本            参数含义
collect.auto_increment.columns            5.1+            从information_schema收集auto_increment列和最大值。
collect.binlog_size                       5.1+            收集所有已注册的Binlog文件的当前大小
collect.engine_innodb_status              5.1+            通过SHOW ENGINE INNODB STATUS收集数据
collect.engine_tokudb_status              5.6+            通过SHOW ENGINE TOKUDB STATUS.收集数据
collect.global_status                     5.1+            通过SHOW GLOBAL STATUS 收集数据(默认开启)
collect.global_variables                  5.1+            通过SHOW GLOBAL VARIABLES收集数据(默认开启)
collect.info_schema.clientstats           5.5+            如果被监控的MySQL使用userstat = 1运行,则此参数需要设置为1以收集客户端统计信息
collect.info_schema.innodb_metrics        5.6+            从information_schema.innodb_metrics收集数据。
collect.info_schema.innodb_tablespaces    5.7+            从information_schema.innodb_sys_tablespaces收集数据。
collect.info_schema.innodb_cmp            5.5+            从information_schema.innodb_cmp收集InnoDB压缩表指标。
collect.info_schema.innodb_cmpmem         5.5+            从information_schema.innodb_cmpmem收集InnoDB缓冲池。
collect.info_schema.processlist           5.1+            从information_schema.processlist收集线程状态计数。
collect.info_schema.processlist.min_time  5.1+            线程状态停留多长时间会被统计。(默认值:0)
collect.info_schema.query_response_time   5.5+            如果query_response_time_stats为ON,则收集查询响应时间。
collect.info_schema.replica_host          5.6+            从information_schema.replica_host_status收集数据。
collect.info_schema.tables                5.1+            从information_schema.tables中收集数据。
collect.info_schema.tables.databases      5.1+            收集表统计信息的数据库列表,或*全部为’的数据库
collect.info_schema.tablestats            5.1+            如果被监控的MySQL使用userstat = 1运行,则设置为true以收集表统计信息。
collect.info_schema.schemastats           5.1+            如果被监控的MySQL使用userstat = 1运行,则设置为true以收集架构统计信息
collect.info_schema.userstats             5.1+            如果被监控的MySQL使用userstat = 1运行,则设置为true以收集用户统计信息。
collect.perf_schema.eventsstatements      5.6+            从performance_schema.events_statements_summary_by_digest收集数据。
collect.perf_schema.eventsstatements.digest_text_limit    5.6+    规范化语句文本的最大长度。(默认值:120)
collect.perf_schema.eventsstatements.limit                5.6+    通过响应时间限制事件语句摘要的数量。(预设值:250)
collect.perf_schema.eventsstatements.timelimit            5.6+    限制“ last_seen”事件语句的年龄(以秒为单位)。(预设值:86400)
collect.perf_schema.eventsstatementssum   5.7+            从Performance_schema.events_statements_summary_by_digest汇总中收集指标。
collect.perf_schema.eventswaits           5.5+            从Performance_schema.events_waits_summary_global_by_event_name收集指标。
collect.perf_schema.file_events           5.6+            从Performance_schema.file_summary_by_event_name收集指标。
collect.perf_schema.file_instances        5.5+            从performance_schema.file_summary_by_instance收集指标。
collect.perf_schema.indexiowaits          5.6+            从performance_schema.table_io_waits_summary_by_index_usage收集指标。
collect.perf_schema.tableiowaits          5.6+            从Performance_schema.table_io_waits_summary_by_table收集指标。
collect.perf_schema.tablelocks            5.6+            从Performance_schema.table_lock_waits_summary_by_table收集指标。
collect.perf_schema.replication_group_members             5.7+    从Performance_schema.replication_group_members收集指标。
collect.perf_schema.replication_group_member_stats        5.7+    从Performance_schema.replication_group_member_stats收集指标。
collect.perf_schema.replication_applier_status_by_worker  5.7+    从performance_schema.replication_applier_status_by_worker收集指标。
collect.slave_status                      5.1+            从SHOW SLAVE STATUS收集(默认情况下启用)
collect.slave_hosts                       5.1+            从SHOW SLAVE HOSTS收集
collect.heartbeat                         5.1+            从心跳中收集。
collect.heartbeat.database                5.1+            从中收集心跳数据的数据库。(默认值:心跳)
collect.heartbeat.table                   5.1+            从何处收集心跳数据的表。(默认值:心跳)

通用启动参数

Name                                Description
config.my-cnf                .my.cnf文件的路径。(默认值:~/.my.cnf)
log.level                    日志级别 记录详细程度(默认:信息)
exporter.lock_wait_timeout   在连接上设置lock_wait_timeout以避免长时间的元数据锁定。(默认值:2秒)
exporter.log_slow_filter     添加一个log_slow_filter以避免刮擦的慢速查询日志记录。注意:Oracle MySQL不支持。
web.listen-address           监听端口 默认9104
web.telemetry-path           公开metric的路径 默认/metrics
version                      打印版本信息

网站公告

今日签到

点亮在社区的每一天
去签到