CREATE USER 'exporter'@'ip' IDENTIFIED BY 'XXXXXXXX' 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)/" # Corresponding MySQL connection string information
apiVersion: apps/v1kind: Deploymentmetadata:labels:k8s-app: mysql-exporter # Rename the exporter based on the business needs. We recommend you add the MySQL instance informationname: mysql-exporter # Rename the exporter based on the business needs. We recommend you add the MySQL instance informationnamespace: mysql-demospec:replicas: 1selector:matchLabels:k8s-app: mysql-exporter # Rename the exporter based on the business needs. We recommend you add the MySQL instance informationtemplate:metadata:labels:k8s-app: mysql-exporter # Rename the exporter based on the business needs. We recommend you add the MySQL instance informationspec:containers:- env:- name: DATA_SOURCE_NAMEvalueFrom:secretKeyRef:name: mysql-secret-testkey: datasourceimage: ccr.ccs.tencentyun.com/k8s-comm/mysqld-exporter:0.12.1imagePullPolicy: IfNotPresentname: mysql-exporterports:- containerPort: 9104name: metric-portterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilednsPolicy: ClusterFirstimagePullSecrets:- name: qcloudregistrykeyrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30
curl
command with the address exposed by the exporter in the command line window, and you can get the corresponding MySQL metrics normally. If no corresponding data is returned, please check whether the connection string is correct as shown below:curl localhost:9104/metrics
Pod Monitor
to define a Prometheus scrape task. Below is a sample YAML configuration:apiVersion: monitoring.coreos.com/v1kind: PodMonitormetadata:name: mysql-exporter # Enter a unique namenamespace: cm-prometheus # The namespace is fixed. Do not change itspec:podMetricsEndpoints:- interval: 30sport: metric-port # Enter the name of the corresponding port of the Prometheus exporter in the Pod YAML configuration filepath: /metrics # Enter the value of the corresponding path of the Prometheus exporter. If it is not specified, it will be `/metrics` by defaultrelabelings:- action: replacesourceLabels:- instanceregex: (.*)targetLabel: instancereplacement: 'crs-xxxxxx' # Change it to the corresponding MySQL instance ID- action: replacesourceLabels:- instanceregex: (.*)targetLabel: ipreplacement: '1.x.x.x' # Change it to the corresponding MySQL instance IPnamespaceSelector: # Select the namespace where the Pod to be monitored residesmatchNames:- mysql-demoselector: # Enter the label value of the Pod to be monitored to locate the target PodmatchLabels:k8s-app: mysql-exporter
collectors
to enable/disable data collection. The specific parameters are as listed below:Parameter | MySQL Version | Description |
collect.auto_increment.columns | 5.1 | Collects auto_increment columns and max values from information_schema. |
collect.binlog_size | 5.1 | Collects the current size of all registered binlog files. |
collect.engine_innodb_status | 5.1 | Collects the status data from SHOW ENGINE INNODB STATUS . |
collect.engine_tokudb_status | 5.6 | Collects the status data from SHOW ENGINE TOKUDB STATUS . |
collect.global_status | 5.1 | Collects the status data from SHOW GLOBAL STATUS (enabled by default). |
collect.global_variables | 5.1 | Collects the status data from SHOW GLOBAL VARIABLES (enabled by default). |
collect.info_schema.clientstats | 5.5 | If userstat=1 is set, this parameter can be set to true to enable client data collection. |
collect.info_schema.innodb_metrics | 5.6 | Collects the monitoring data from information_schema.innodb_metrics . |
collect.info_schema.innodb_tablespaces | 5.7 | Collects the monitoring data from information_schema.innodb_sys_tablespaces . |
collect.info_schema.innodb_cmp | 5.5 | Collects the monitoring data of compressed InnoDB tables from information_schema.innodb_cmp . |
collect.info_schema.innodb_cmpmem | 5.5 | Collects the monitoring data of InnoDB buffer pool compression from information_schema.innodb_cmpmem . |
collect.info_schema.processlist | 5.1 | Collects the monitoring data of the thread status count from information_schema.processlist . |
collect.info_schema.processlist.min_time | 5.1 | Minimum time a thread must be in each status to be counted. Default value: 0 |
collect.info_schema.query_response_time | 5.5 | Collects query response time distribution if query_response_time_stats is set to ON . |
collect.info_schema.replica_host | 5.6 | Collects the status data from information_schema.replica_host_status . |
collect.info_schema.tables | 5.1 | Collects the status data from information_schema.tables . |
collect.info_schema.tables.databases | 5.1 | Sets the list of databases to collect table statistics for, or ' * ' for all. |
collect.info_schema.tablestats | 5.1 | If userstat=1 is set, this parameter can be set to true to collect table statistics. |
collect.info_schema.schemastats | 5.1 | If userstat=1 is set, this parameter can be set to true to collect schema statistics. |
collect.info_schema.userstats | 5.1 | If userstat=1 is set, this parameter can be set to true to collect user statistics. |
collect.perf_schema.eventsstatements | 5.6 | Collects the monitoring data from performance_schema.events_statements_summary_by_digest . |
collect.perf_schema.eventsstatements.digest_text_limit | 5.6 | Sets the maximum length of the normalized statement text. Default value: 120. |
collect.perf_schema.eventsstatements.limit | 5.6 | Limits the number of event statements. Default value: 250. |
collect.perf_schema.eventsstatements.timelimit | 5.6 | Limits how old the 'last_seen' events statements can be, in seconds. Default value: 86400. |
collect.perf_schema.eventsstatementssum | 5.7 | Collects the monitoring data from performance_schema.events_statements_summary_by_digest summed . |
collect.perf_schema.eventswaits | 5.5 | Collects the monitoring data from performance_schema.events_waits_summary_global_by_event_name . |
collect.perf_schema.file_events | 5.6 | Collects the monitoring data from performance_schema.file_summary_by_event_name . |
collect.perf_schema.file_instances | 5.5 | Collects the monitoring data from performance_schema.file_summary_by_instance . |
collect.perf_schema.indexiowaits | 5.6 | Collects the monitoring data from performance_schema.table_io_waits_summary_by_index_usage . |
collect.perf_schema.tableiowaits | 5.6 | Collects the monitoring data from performance_schema.table_io_waits_summary_by_table . |
collect.perf_schema.tablelocks | 5.6 | Collects the monitoring data from performance_schema.table_lock_waits_summary_by_table . |
collect.perf_schema.replication_group_members | 5.7 | Collects the monitoring data from performance_schema.replication_group_members . |
collect.perf_schema.replication_group_member_stats | 5.7 | Collects the monitoring data from performance_schema.replication_group_member_stats . |
collect.perf_schema.replication_applier_status_by_worker | 5.7 | Collects the monitoring data from performance_schema.replication_applier_status_by_worker . |
collect.slave_status | 5.1 | Collects the monitoring data from SHOW SLAVE STATUS (enabled by default). |
collect.slave_hosts | 5.1 | Collects the monitoring data from SHOW SLAVE HOSTS . |
collect.heartbeat | 5.1 | |
collect.heartbeat.database | 5.1 | Database from where to collect heartbeat data. Default value: heartbeat. |
collect.heartbeat.table | 5.1 | Table from where to collect heartbeat data. Default value: heartbeat. |
collect.heartbeat.utc | 5.1 | Uses UTC for timestamps of the current server ( pt-heartbeat is called with --utc ). Default value: false. |
Item | Description |
config.my-cnf | Path of .my.cnf file to read MySQL credentials from. Default value: ~/.my.cnf . |
log.level | Log level. Default value: info. |
exporter.lock_wait_timeout | Sets a lock_wait_timeout (in seconds) on the connection to avoid long metadata locking. Default value: 2. |
exporter.log_slow_filter | Adds a log_slow_filter to avoid slow query logging of scrapes. Note: not supported by Oracle MySQL. |
web.listen-address | Web port listening address. |
web.telemetry-path | Metric API path. |
version | Prints the version information. |
collect.heartbeat
is enabled, mysqld_exporter will scrape replication delay measured by heartbeat mechanisms.
Was this page helpful?