
参数 | 说明 |
名称 | 集成名称,命名规范如下: 名称具有唯一性。 名称需要符合下面的正则:'^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'。 |
用户名 | MySQL 的用户名称。 |
密码 | MySQL 的密码。 |
地址 | MySQL 的连接地址。 |
标签 | 给指标添加自定义 Label。 |
Exporter 配置 | auto_increment.columns:从 information_schema 采集 auto_increment 列和最大值。 binlog_size:采集所有已注册的 binlog 文件的当前大小。 engine_innodb_status:从 SHOW ENGINE INNODB STATUS 采集。 engine_tokudb_status:从 SHOW ENGINE TOKUDB STATUS 采集。 global_status:从 SHOW GLOBAL STATUS 采集,默认为 true。 global_variables:从 SHOW GLOBAL VARIABLES 采集,默认为 true。 info_schema.clientstats:如果使用 userstat=1 运行,则设置为 true 以采集客户端统计信息。 info_schema.innodb_metrics:从 information_schema.innodb_metrics 采集指标。 info_schema.innodb_tablespaces:从 information_schema.innodb_sys_tablespaces 采集指标。 info_schema.innodb_cmp:从 information_schema.innodb_cmp 采集 InnoDB 压缩表指标,默认为 true。 info_schema.innodb_cmpmem:从 information_schema.innodb_cmpmem 采集 InnoDB 缓冲池压缩指标(默认为 true)。 info_schema.processlist:从 information_schema.processlist 采集线程状态计数。 info_schema.query_response_time:如果 query_response_time_stats 为 ON,则采集查询响应时间分布(默认为 true)。 info_schema.tables:从 information_schema.tables 采集指标。 info_schema.tables.databases:用于收集表统计信息的数据库列表,逗号分隔,默认是 '*' 表示所有数据库。 info_schema.tablestats:如果使用 userstat=1 运行,则设置为 true 以采集表统计信息。 info_schema.schemastats:如果使用 userstat=1 运行,则设置为 true 以采集架构统计信息。 info_schema.userstats:如果使用 userstat=1 运行,则设置为 true 以采集用户统计信息。 perf_schema.eventsstatements:从 performance_schema.events_statements_summary_by_digest 采集指标。 perf_schema.eventsstatements.digest_text_limit:标准化语句文本的最大长度,默认值为120。 perf_schema.eventsstatements.limit:按响应时间限制事件语句摘要的数量,默认值为250。 perf_schema.eventsstatements.timelimit:限制 'last_seen' 事件语句的最大时间,单位为秒,默认值为86400。 perf_schema.eventsstatementssum:从 performance_schema.events_statements_summary_by_digest 汇总采集指标。 perf_schema.eventswaits:从 performance_schema.events_waits_summary_global_by_event_name 采集指标。 perf_schema.file_events:从 performance_schema.file_summary_by_event_name 采集指标。 perf_schema.file_instances:从 performance_schema.file_summary_by_instance采集指标。 perf_schema.indexiowaits:从 performance_schema.table_io_waits_summary_by_index_usage 采集指标。 perf_schema.tableiowaits:从 performance_schema.table_io_waits_summary_by_table 采集指标。 perf_schema.tablelocks:从 performance_schema.table_lock_waits_summary_by_table 采集指标。 perf_schema.replication_group_member_stats:从 performance_schema.replication_group_member_stats 采集指标。 perf_schema.replication_applier_status_by_worker:从 performance_schema.replication_applier_status_by_worker 采集指标。 slave_status:从 SHOW SLAVE STATUS 采集,默认为 true。 slave_hosts:从 SHOW SLAVE HOSTS 采集。 heartbeat:从 heartbeat 采集。 heartbeat.database:收集 heartbeat 数据的数据库,默认值为 heartbeat。 heartbeat.table:收集 heartbeat 数据的表,默认值为 heartbeat。 |

CREATE USER 'exporter'@'ip' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3;GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'ip';
apiVersion: v1kind: Secretmetadata:name: mysql-secret-testnamespace: mysql-demotype: OpaquestringData:datasource: "user:password@tcp(ip:port)/" #对应 MySQL 连接串信息
apiVersion: apps/v1kind: Deploymentmetadata:labels:k8s-app: mysql-exporter # 根据业务需要调整成对应的名称,建议加上 MySQL 实例的信息name: mysql-exporter # 根据业务需要调整成对应的名称,建议加上 MySQL 实例的信息namespace: mysql-demospec:replicas: 1selector:matchLabels:k8s-app: mysql-exporter # 根据业务需要调整成对应的名称,建议加上 MySQL 实例的信息template:metadata:labels:k8s-app: mysql-exporter # 根据业务需要调整成对应的名称,建议加上 MySQL 实例的信息spec:containers:- env:- name: DATA_SOURCE_NAMEvalueFrom:secretKeyRef:name: mysql-secret-test # 对应上一步中的 Secret 的名称key: datasource # 对应上一步中的 Secret Keyimage: ccr.ccs.tencentyun.com/rig-agent/mysqld-exporter:v0.12.1imagePullPolicy: IfNotPresentname: mysql-exporterports:- containerPort: 9104name: metric-portterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilednsPolicy: ClusterFirstimagePullSecrets:- name: qcloudregistrykeyrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30

wget -O- localhost:9104/metrics

apiVersion: monitoring.coreos.com/v1kind: PodMonitormetadata:name: mysql-exporter # 填写一个唯一名称namespace: cm-prometheus # 按量实例: 集群的 namespace; 包年包月实例(已停止售卖): namespace 固定,不要修改spec:podMetricsEndpoints:- interval: 30sport: metric-port # 填写pod yaml中Prometheus Exporter对应的Port的Namepath: /metrics # 填写Prometheus Exporter对应的Path的值,不填默认/metricsrelabelings:- action: replacesourceLabels:- instanceregex: (.*)targetLabel: instancereplacement: 'cdb-xxxxxx' # 调整成对应的 MySQL 实例 ID- action: replacesourceLabels:- instanceregex: (.*)targetLabel: ipreplacement: '1.x.x.x' # 调整成对应的 MySQL 实例 IPnamespaceSelector: # 选择要监控pod所在的namespacematchNames:- mysql-demoselector: # 填写要监控pod的Label值,以定位目标podmatchLabels:k8s-app: mysql-exporter


Collector 来控制采集数据的启停,具体参数如下:名称 | 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 | 如果设置了 userstat=1,设置成 true 来开启用户端数据采集。 |
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 buffer pool compression 的监控数据。 |
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 | 如果设置了 userstat=1,设置成 true 来采集表统计数据。 |
collect.info_schema.schemastats | 5.1 | 如果设置了 userstat=1,设置成 true 来采集 schema 统计数据。 |
collect.info_schema.userstats | 5.1 | 如果设置了 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 summed 中采集监控数据。 |
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 | 从 from 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 | 数据库心跳检测的数据源。(默认:heartbeat) |
collect.heartbeat.table | 5.1 | 表心跳检测的数据源。(默认:heartbeat) |
collect.heartbeat.utc | 5.1 | 对当前的数据库服务器使用 UTC 时间戳 ( pt-heartbeat is called with --utc)。(默认:false) |
名称 | 描述 |
config.my-cnf | 用来读取数据库认证信息的配置文件 .my.cnf 位置。 (默认:~/.my.cnf) |
log.level | 日志级别。(默认:info) |
exporter.lock_wait_timeout | 为链接设置 lock_wait_timeout(单位:秒)以避免对元数据的锁时间太长。(默认:2) |
exporter.log_slow_filter | 添加 log_slow_filter 以避免抓取的慢查询被记录。 说明: 不支持 Oracle MySQL。 |
web.listen-address | web 端口监听地址。 |
web.telemetry-path | metrics 接口路径。 |
version | 打印版本信息。 |
collect.heartbeat,mysqld_exporter 会通过心跳检测机制抓取复制延迟数据。文档反馈