mysqld_exporter

在Prometheus架构中,exporter是负责收集数据并将信息汇报给Prometheus Server的组件,mysqld_exporter是常用的数据库监控工具。

一、mysqld_exporter的安装

1、mysql库创建相应用户并赋权:
create user 'exporter'@'%' identified by 'MONty_00';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%'  WITH MAX_USER_CONNECTIONS 3;
flush privileges;
2、配置.my.cnf

.my.cnf默认放置在启动用户的家目录,启动时无需指定;也可以随意放置在任意目录,在启动时通过 --config.my-cnf={conf_dir}/.my.cnf指定配置文件。
.my.cnf内容

[client]
host=127.0.0.1
port=3306
user=exporter
password=123456
3、启动mysqld_exporter

mysqld_exporter默认监听9104端口,启动命令如下:

./mysqld_exporter --config.my-cnf=/opt/mysqld_exporter-0.10.0.linux-amd64/.my.cnf 
4、使用环境变量运行(不推荐)

使用环境变量运行时无需指定配置文件。

export DATA_SOURCE_NAME='user:password@(hostname:3306)/'
./mysqld_exporter <flags>

二、mysqld_exporter常用启动参数

1、如何指定启动参数

1) exporter版本>0.10.0时:

--collect.auto_increment.columns
--no-collect.auto_increment.columns

2)exporter版本<=0.10.0时:

-collect.auto_increment.columns
-collect.auto_increment.columns=[true|false]
2、通过以下参数控制收集数据
启动参数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+ 从何处收集心跳数据的表。(默认值:心跳)
3、通用启动参数
NameDescription
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 打印版本信息

三、SSL配置

如果MySQL服务器支持SSL,则需要指定一个CA信任库来验证服务器的信任链,并为SSL连接的客户端指定SSL密钥对。
要将mysqld_exporter配置为使用自定义CA证书,请将以下内容添加到.my.cnf的配置文件中:

ssl-ca=/path/to/ca/file

要指定客户端SSL密钥对,请将以下内容添加到cnf中。

ssl-key=/path/to/ssl/client/key
ssl-cert=/path/to/ssl/client/cert

仅在mysql cnf文件中支持自定义SSL配置,如果在环境变量DATA_SOURCE_NAME中设置mysql服务器的数据源名称,则不支持自定义SSL配置。

 

 

转自:https://www.ab62.cn/article/5703.html

posted @ 2022-08-09 21:30  郭大侠1  阅读(4112)  评论(0编辑  收藏  举报