Exporters | 安装mysqld_exporter

文章目录

一、下载linux版本的mysqld_exporter

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

Shell 复制代码
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz

二、解压安装包

Shell 复制代码
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

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

Shell 复制代码
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;

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

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

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

Shell 复制代码
/etc/mysqld_exporter/mysqld_exporter --config.my-cnf="/etc/mysqld_exporter/my.cnf"

六、新建启动服务

Shell 复制代码
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

七、启动服务

Shell 复制代码
systemctl daemon-reload
systemctl enable --now mysqld_exporter
systemctl status mysqld_exporter
ss -nlt|grep 9104

八、prometheus 收集数据并监控

Shell 复制代码
vi /prometheus/prometheus.yml
- job_name: mysql_exporter
    static_configs:
    - targets: ['192.168.168.172:9104']

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

Shell 复制代码
启动参数                                 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+            从何处收集心跳数据的表。(默认值:心跳)

通用启动参数

Shell 复制代码
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                      打印版本信息
相关推荐
weisian1511 天前
Prometheus-3--Prometheus是怎么抓取Java应用,Redis中间件,服务器环境的指标的?
java·redis·prometheus
louqle2 天前
【AI问答】PromQL中interval和rate_interval的区别以及Grafana面板的配置建议
grafana·prometheus
bing_1584 天前
如何将 Redis 监控集成到微服务整体的监控体系中( 如 Prometheus + Grafana)
redis·微服务·prometheus
cui_win6 天前
Prometheus实战教程 01 - Prometheus 简介和架构
架构·prometheus
Fireworkitte7 天前
Prometheus + Grafana + Micrometer 监控方案详解
grafana·prometheus
软件测试-阿涛10 天前
【性能测试】Jmeter+Grafana+InfluxDB+Prometheus Windows安装部署教程
测试工具·jmeter·性能优化·压力测试·grafana·prometheus
lpt11111111112 天前
prometheus + grafana 搭建
java·grafana·prometheus
广目软件13 天前
GM DC Monitor v2.1平台部署手册分享
运维·服务器·zabbix·运维开发·prometheus
技术栈壳13 天前
Prometheus+altermanager搭配钉钉报警
prometheus