1
0
mirror of https://github.com/prometheus/mysqld_exporter.git synced 2025-07-30 06:43:05 +03:00

Support MySQL 8.4 replicas syntax (#837)

* support MySQL 8.4

Signed-off-by: Mitsuhiro Tanda <mitsuhiro.tanda@gmail.com>
---------

Signed-off-by: Mitsuhiro Tanda <mitsuhiro.tanda@gmail.com>
This commit is contained in:
Mitsuhiro Tanda
2024-05-15 17:11:39 +09:00
committed by GitHub
parent 0c89d59c06
commit f6a64d768c
2 changed files with 18 additions and 5 deletions

View File

@ -31,7 +31,8 @@ const (
// timestamps. %s will be replaced by the database and table name.
// The second column allows gets the server timestamp at the exact same
// time the query is run.
slaveHostsQuery = "SHOW SLAVE HOSTS"
slaveHostsQuery = "SHOW SLAVE HOSTS"
showReplicasQuery = "SHOW REPLICAS"
)
// Metric descriptors.
@ -63,9 +64,15 @@ func (ScrapeSlaveHosts) Version() float64 {
// Scrape collects data from database connection and sends it over channel as prometheus metric.
func (ScrapeSlaveHosts) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
slaveHostsRows, err := db.QueryContext(ctx, slaveHostsQuery)
if err != nil {
return err
var (
slaveHostsRows *sql.Rows
err error
)
// Try the both syntax for MySQL 8.0 and MySQL 8.4
if slaveHostsRows, err = db.QueryContext(ctx, slaveHostsQuery); err != nil {
if slaveHostsRows, err = db.QueryContext(ctx, showReplicasQuery); err != nil {
return err
}
}
defer slaveHostsRows.Close()