You've already forked mysqld_exporter
mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-08-06 14:22:37 +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:
@@ -31,7 +31,8 @@ const (
|
|||||||
// timestamps. %s will be replaced by the database and table name.
|
// timestamps. %s will be replaced by the database and table name.
|
||||||
// The second column allows gets the server timestamp at the exact same
|
// The second column allows gets the server timestamp at the exact same
|
||||||
// time the query is run.
|
// time the query is run.
|
||||||
slaveHostsQuery = "SHOW SLAVE HOSTS"
|
slaveHostsQuery = "SHOW SLAVE HOSTS"
|
||||||
|
showReplicasQuery = "SHOW REPLICAS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Metric descriptors.
|
// Metric descriptors.
|
||||||
@@ -63,9 +64,15 @@ func (ScrapeSlaveHosts) Version() float64 {
|
|||||||
|
|
||||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
// 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 {
|
func (ScrapeSlaveHosts) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||||
slaveHostsRows, err := db.QueryContext(ctx, slaveHostsQuery)
|
var (
|
||||||
if err != nil {
|
slaveHostsRows *sql.Rows
|
||||||
return err
|
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()
|
defer slaveHostsRows.Close()
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ const (
|
|||||||
slaveStatus = "slave_status"
|
slaveStatus = "slave_status"
|
||||||
)
|
)
|
||||||
|
|
||||||
var slaveStatusQueries = [2]string{"SHOW ALL SLAVES STATUS", "SHOW SLAVE STATUS"}
|
var slaveStatusQueries = [3]string{"SHOW ALL SLAVES STATUS", "SHOW SLAVE STATUS", "SHOW REPLICA STATUS"}
|
||||||
var slaveStatusQuerySuffixes = [3]string{" NONBLOCKING", " NOLOCK", ""}
|
var slaveStatusQuerySuffixes = [3]string{" NONBLOCKING", " NOLOCK", ""}
|
||||||
|
|
||||||
func columnIndex(slaveCols []string, colName string) int {
|
func columnIndex(slaveCols []string, colName string) int {
|
||||||
@@ -113,7 +113,13 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome
|
|||||||
}
|
}
|
||||||
|
|
||||||
masterUUID := columnValue(scanArgs, slaveCols, "Master_UUID")
|
masterUUID := columnValue(scanArgs, slaveCols, "Master_UUID")
|
||||||
|
if masterUUID == "" {
|
||||||
|
masterUUID = columnValue(scanArgs, slaveCols, "Source_UUID")
|
||||||
|
}
|
||||||
masterHost := columnValue(scanArgs, slaveCols, "Master_Host")
|
masterHost := columnValue(scanArgs, slaveCols, "Master_Host")
|
||||||
|
if masterHost == "" {
|
||||||
|
masterHost = columnValue(scanArgs, slaveCols, "Source_Host")
|
||||||
|
}
|
||||||
channelName := columnValue(scanArgs, slaveCols, "Channel_Name") // MySQL & Percona
|
channelName := columnValue(scanArgs, slaveCols, "Channel_Name") // MySQL & Percona
|
||||||
connectionName := columnValue(scanArgs, slaveCols, "Connection_name") // MariaDB
|
connectionName := columnValue(scanArgs, slaveCols, "Connection_name") // MariaDB
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user