feat(inputs.mysql): Add support for replica status (#15749)

This commit is contained in:
HungNT 2024-08-20 19:24:54 +07:00 committed by GitHub
parent ee9dde8082
commit 1852d75c6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View File

@ -85,7 +85,11 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
## gather metrics from SHOW SLAVE STATUS command output
# gather_slave_status = false
## gather metrics from SHOW REPLICA STATUS command output
# gather_replica_status = false
## use SHOW ALL SLAVES STATUS command output for MariaDB
## use SHOW ALL REPLICAS STATUS command if enable gather replica status
# mariadb_dialect = false
## gather metrics from SHOW BINARY LOGS command output
@ -260,7 +264,8 @@ the single-source replication is on. If the multi-source replication is set,
then everything works differently, this metric does not work with multi-source
replication, unless you set `gather_all_slave_channels = true`. For MariaDB,
`mariadb_dialect = true` should be set to address the field names and commands
differences.
differences. If enable `gather_replica_status` metrics gather from command
`SHOW REPLICA STATUS`, for MariaDB will be `SHOW ALL REPLICAS STATUS`
* slave_[column name]
* Binary logs - all metrics including size and count of all binary files.
Requires to be turned on in configuration.

View File

@ -40,6 +40,7 @@ type Mysql struct {
GatherInfoSchemaAutoInc bool `toml:"gather_info_schema_auto_inc"`
GatherInnoDBMetrics bool `toml:"gather_innodb_metrics"`
GatherSlaveStatus bool `toml:"gather_slave_status"`
GatherReplicaStatus bool `toml:"gather_replica_status"`
GatherAllSlaveChannels bool `toml:"gather_all_slave_channels"`
MariadbDialect bool `toml:"mariadb_dialect"`
GatherBinaryLogs bool `toml:"gather_binary_logs"`
@ -77,12 +78,16 @@ func (*Mysql) SampleConfig() string {
}
func (m *Mysql) Init() error {
if m.MariadbDialect {
switch {
case m.MariadbDialect && m.GatherReplicaStatus:
m.getStatusQuery = replicaStatusQueryMariadb
case m.MariadbDialect:
m.getStatusQuery = slaveStatusQueryMariadb
} else {
case m.GatherReplicaStatus:
m.getStatusQuery = replicaStatusQuery
default:
m.getStatusQuery = slaveStatusQuery
}
// Default to localhost if nothing specified.
if len(m.Servers) == 0 {
s := config.NewSecret([]byte(localhost))
@ -250,7 +255,9 @@ const (
globalStatusQuery = `SHOW GLOBAL STATUS`
globalVariablesQuery = `SHOW GLOBAL VARIABLES`
slaveStatusQuery = `SHOW SLAVE STATUS`
replicaStatusQuery = `SHOW REPLICA STATUS`
slaveStatusQueryMariadb = `SHOW ALL SLAVES STATUS`
replicaStatusQueryMariadb = `SHOW ALL REPLICAS STATUS`
binaryLogsQuery = `SHOW BINARY LOGS`
infoSchemaProcessListQuery = `
SELECT COALESCE(command,''),COALESCE(state,''),count(*)
@ -475,7 +482,7 @@ func (m *Mysql) gatherServer(server *config.Secret, acc telegraf.Accumulator) er
}
}
if m.GatherSlaveStatus {
if m.GatherSlaveStatus || m.GatherReplicaStatus {
err = m.gatherSlaveStatuses(db, servtag, acc)
if err != nil {
return err

View File

@ -48,7 +48,11 @@
## gather metrics from SHOW SLAVE STATUS command output
# gather_slave_status = false
## gather metrics from SHOW REPLICA STATUS command output
# gather_replica_status = false
## use SHOW ALL SLAVES STATUS command output for MariaDB
## use SHOW ALL REPLICAS STATUS command if enable gather replica status
# mariadb_dialect = false
## gather metrics from SHOW BINARY LOGS command output