chore: Fix metric detection in acceptance tests (#1022)
readMetric calls m.Write() into a dto.Metric protobuf struct where the metric name is not stored as a label (only the metric’s own labels are). Matching on MetricNameLabel therefore always misses, and mysql_up was never found.
Switching to descriptor comparison (m.Desc() == mysqlUp) avoids the protobuf DTO entirely, operating directly on the in-memory Go object.
The test also silently passed if mysql_up was never emitted: the for loop would complete without error. Adding a seen flag with an explicit assertion ensures the metric must actually be collected.
Signed-off-by: Julien Pivotto 291750+roidelapluie@users.noreply.github.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
MySQL Server Exporter
Prometheus exporter for MySQL server metrics.
Supported versions:
NOTE: Not all collection methods are supported on MySQL/MariaDB < 5.6
Building and running
Required Grants
NOTE: It is recommended to set a max connection limit for the user to avoid overloading the server with monitoring scrapes under heavy load. This is not supported on all MySQL/MariaDB versions; for example, MariaDB 10.1 (provided with Ubuntu 18.04) does not support this feature.
Build
Running
Single exporter mode
Running using
.my.cnffrom the current directory:Multi-target support
This exporter supports the multi-target pattern. This allows running a single instance of this exporter for multiple MySQL targets.
To use the multi-target functionality, send an http request to the endpoint
/probe?target=foo:3306where target is set to the DSN of the MySQL instance to scrape metrics from.To avoid putting sensitive information like username and password in the URL, you can have multiple configurations in
config.my-cnffile and match it by adding&auth_module=<section>to the request.Sample config file for multiple configurations
On the prometheus side you can set a scrape config as follows
Flag format
Example format for flags for version > 0.10.0:
Example format for flags for version <= 0.10.0:
Collector Flags
pt-heartbeatis called with--utc). (default: false)*‘ for all.General Flags
host:port. (default:localhost:3306)~/.my.cnf)Environment Variables
Configuration precedence
If you have configured cli with both
mysqldflags and a valid configuration file, the options in the configuration file will override the flags forclientsection.TLS and basic authentication
The MySQLd Exporter supports TLS and basic authentication.
To use TLS and/or basic authentication, you need to pass a configuration file using the
--web.config.fileparameter. The format of the file is described in the exporter-toolkit repository.Customizing Configuration for a SSL Connection
If The MySQL server supports SSL, you may need to specify a CA truststore to verify the server’s chain-of-trust. You may also need to specify a SSL keypair for the client side of the SSL connection. To configure the mysqld exporter to use a custom CA certificate, add the following to the mysql cnf file:
To specify the client SSL keypair, add the following to the cnf.
Using Docker
You can deploy this exporter using the prom/mysqld-exporter Docker image.
For example:
heartbeat
With
collect.heartbeatenabled, mysqld_exporter will scrape replication delay measured by heartbeat mechanisms. Pt-heartbeat is the reference heartbeat implementation supported.Filtering enabled collectors
The
mysqld_exporterwill expose all metrics from enabled collectors by default. This is the recommended way to collect metrics to avoid errors when comparing metrics of different families.For advanced use the
mysqld_exportercan be passed an optional list of collectors to filter metrics. Thecollect[]parameter may be used multiple times. In Prometheus configuration you can use this syntax under the scrape config.This can be useful for having different Prometheus servers collect specific metrics from targets.
Example Rules
There is a set of sample rules, alerts and dashboards available in the mysqld-mixin