如何进行Prometheus-MySQL监控
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,如何进行Prometheus-MySQL监控,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。简介mysqld_exporter是用于获
千家信息网最后更新 2026年10月31日如何进行Prometheus-MySQL监控
如何进行Prometheus-MySQL监控,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
简介
mysqld_exporter是用于获取mysql实例的指标服务。
安装
mysql授权
CREATE USER exporter@localhost identified by "mima"; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost' WITH MAX_USER_CONNECTIONS 3; flush privileges;
直接通过命令下载就可以了。
wget -t 1000 -c https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz tar zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /opt/ cd /opt/mysqld_exporter-0.12.1.linux-amd64 export DATA_SOURCE_NAME='exporter:mima@(localhost:3306)/' ./mysqld_exporter
这里设置用户名密码是通过环境变量的形式,也可以用配置文件,默认找的配置文件是~/.my.cnf,也可以使用参数--config.my-cnf="/opt/mysqld_exporter/.my.cnf" 进行设置。
./mysqld_exporter --config.my-cnf="/opt/mysqld_exporter/.my.cnf"
其他参数
usage: mysqld_exporter [] Flags: -h, --help Show context-sensitive help (also try --help-long and --help-man). --exporter.lock_wait_timeout=2 Set a lock_wait_timeout on the connection to avoid long metadata locking. --exporter.log_slow_filter Add a log_slow_filter to avoid slow query logging of scrapes. NOTE: Not supported by Oracle MySQL. --collect.heartbeat.database="heartbeat" Database from where to collect heartbeat data --collect.heartbeat.table="heartbeat" Table from where to collect heartbeat data --collect.info_schema.processlist.min_time=0 Minimum time a thread must be in each state to be counted --collect.info_schema.processlist.processes_by_user Enable collecting the number of processes by user --collect.info_schema.processlist.processes_by_host Enable collecting the number of processes by host --collect.info_schema.tables.databases="*" The list of databases to collect table stats for, or '*' for all --collect.mysql.user.privileges Enable collecting user privileges from mysql.user --collect.perf_schema.eventsstatements.limit=250 Limit the number of events statements digests by response time --collect.perf_schema.eventsstatements.timelimit=86400 Limit how old the 'last_seen' events statements can be, in seconds --collect.perf_schema.eventsstatements.digest_text_limit=120 Maximum length of the normalized statement text --collect.perf_schema.file_instances.filter=".*" RegEx file_name filter for performance_schema.file_summary_by_instance --collect.perf_schema.file_instances.remove_prefix="/var/lib/mysql/" Remove path prefix in performance_schema.file_summary_by_instance --web.listen-address=":9104" Address to listen on for web interface and telemetry. --web.telemetry-path="/metrics" Path under which to expose metrics. --timeout-offset=0.25 Offset to subtract from timeout in seconds. --config.my-cnf="/home/jalright/.my.cnf" Path to .my.cnf file to read MySQL credentials from. --collect.mysql.user Collect data from mysql.user --collect.info_schema.tables Collect metrics from information_schema.tables --collect.info_schema.innodb_tablespaces Collect metrics from information_schema.innodb_sys_tablespaces --collect.info_schema.innodb_metrics Collect metrics from information_schema.innodb_metrics --collect.global_status Collect from SHOW GLOBAL STATUS --collect.global_variables Collect from SHOW GLOBAL VARIABLES --collect.slave_status Collect from SHOW SLAVE STATUS --collect.info_schema.processlist Collect current thread state counts from the information_schema.processlist --collect.perf_schema.tablelocks Collect metrics from performance_schema.table_lock_waits_summary_by_table --collect.perf_schema.eventsstatements Collect metrics from performance_schema.events_statements_summary_by_digest --collect.perf_schema.eventsstatementssum Collect metrics of grand sums from performance_schema.events_statements_summary_by_digest --collect.perf_schema.eventswaits Collect metrics from performance_schema.events_waits_summary_global_by_event_name --collect.auto_increment.columns Collect auto_increment columns and max values from information_schema --collect.binlog_size Collect the current size of all registered binlog files --collect.perf_schema.tableiowaits Collect metrics from performance_schema.table_io_waits_summary_by_table --collect.perf_schema.indexiowaits Collect metrics from performance_schema.table_io_waits_summary_by_index_usage --collect.info_schema.userstats If running with userstat=1, set to true to collect user statistics --collect.info_schema.clientstats If running with userstat=1, set to true to collect client statistics --collect.info_schema.tablestats If running with userstat=1, set to true to collect table statistics --collect.info_schema.schemastats If running with userstat=1, set to true to collect schema statistics --collect.perf_schema.file_events Collect metrics from performance_schema.file_summary_by_event_name --collect.perf_schema.file_instances Collect metrics from performance_schema.file_summary_by_instance --collect.perf_schema.replication_group_member_stats Collect metrics from performance_schema.replication_group_member_stats --collect.perf_schema.replication_applier_status_by_worker Collect metrics from performance_schema.replication_applier_status_by_worker --collect.engine_innodb_status Collect from SHOW ENGINE INNODB STATUS --collect.heartbeat Collect from heartbeat --collect.slave_hosts Scrape information from 'SHOW SLAVE HOSTS' --collect.info_schema.innodb_cmp Collect metrics from information_schema.innodb_cmp --collect.info_schema.innodb_cmpmem Collect metrics from information_schema.innodb_cmpmem --collect.info_schema.query_response_time Collect query response time distribution if query_response_time_stats is ON. --collect.engine_tokudb_status Collect from SHOW ENGINE TOKUDB STATUS --log.level="info" Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal] --log.format="logger:stderr" Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true" --version Show application version.
部署服务
直接注册成systemd服务。
```bash #!/bin/bash VERSION="0.12.1" wget -t 100 -c https://github.com/prometheus/mysqld_exporter/releases/download/v${VERSION}/mysqld_exporter-${VERSION}.linux-amd64.tar.gz if [ ! -e mysqld_exporter-${VERSION}.linux-amd64.tar.gz ] then echo "安装包下载失败" exit 1 fi tar xvfz mysqld_exporter-${VERSION}.linux-amd64.tar.gz -C /opt/ cd /opt ln -s mysqld_exporter-${VERSION}.linux-amd64 mysqld_exporter cat > /etc/systemd/system/mysqld_exporter.service <配置prometheus Job
默认端口是9104
- job_name: 'mysqld_exporter' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9104']
指标展示
指标可以通过prometheus的WebUI进行查看
http://[promethe server ip]:9090
如果需要画图,可以直接使用grafana,有人已经配置好了图形可以通过grafana官方下的dashboard找到mysqld_exporter相关的dashboard就可以直接使用了,配置好prometheus数据源,直接导入grafana就可以直接展示了。
关于如何进行Prometheus-MySQL监控问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。
配置
指标
问题
服务
监控
参数
可以通过
文件
更多
帮助
解答
易行
简单易行
内容
变量
命令
图形
官方
实例
密码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
天津市摩尔互联网科技
互联网科技公司起名
新华互联网科技学院
紫鲸互联网科技
百单互联网科技有限公司
顺网科技2021年互联网排名
成都仁贤领冠互联网科技有限公司
青海省互联网新科技
开启互联网科技时代小说
济南华为互联网科技产业总部基地
阿里巴巴算科技企业还是互联网
移动互联网科技股
工业互联网山东科技大学
美国互联网科技公司
唯美互联网科技
互联网金融运营模式中的金融科技
美国五大互联网科技公司市值多少
山东蛋芒互联网科技有限公司
山东亿川互联网科技有限责任公司
互联网 科技节活动 微视频大赛
互联网的科技创新
安徽鑫晟辉互联网科技
互联网科技logo设计
米客互联网科技
互联网科技有限公司 翻译
移动互联网科技公司
深圳育鹏互联网科技有限公司招聘
国大互联网教育科技有限公司薪资
互联网第三次科技革命特征
科技互联网企业在行动