feat(inputs.mysql): Add support for replica status (#15749)
This commit is contained in:
parent
ee9dde8082
commit
1852d75c6c
|
|
@ -85,7 +85,11 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## gather metrics from SHOW SLAVE STATUS command output
|
## gather metrics from SHOW SLAVE STATUS command output
|
||||||
# gather_slave_status = false
|
# 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 SLAVES STATUS command output for MariaDB
|
||||||
|
## use SHOW ALL REPLICAS STATUS command if enable gather replica status
|
||||||
# mariadb_dialect = false
|
# mariadb_dialect = false
|
||||||
|
|
||||||
## gather metrics from SHOW BINARY LOGS command output
|
## 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
|
then everything works differently, this metric does not work with multi-source
|
||||||
replication, unless you set `gather_all_slave_channels = true`. For MariaDB,
|
replication, unless you set `gather_all_slave_channels = true`. For MariaDB,
|
||||||
`mariadb_dialect = true` should be set to address the field names and commands
|
`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]
|
* slave_[column name]
|
||||||
* Binary logs - all metrics including size and count of all binary files.
|
* Binary logs - all metrics including size and count of all binary files.
|
||||||
Requires to be turned on in configuration.
|
Requires to be turned on in configuration.
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ type Mysql struct {
|
||||||
GatherInfoSchemaAutoInc bool `toml:"gather_info_schema_auto_inc"`
|
GatherInfoSchemaAutoInc bool `toml:"gather_info_schema_auto_inc"`
|
||||||
GatherInnoDBMetrics bool `toml:"gather_innodb_metrics"`
|
GatherInnoDBMetrics bool `toml:"gather_innodb_metrics"`
|
||||||
GatherSlaveStatus bool `toml:"gather_slave_status"`
|
GatherSlaveStatus bool `toml:"gather_slave_status"`
|
||||||
|
GatherReplicaStatus bool `toml:"gather_replica_status"`
|
||||||
GatherAllSlaveChannels bool `toml:"gather_all_slave_channels"`
|
GatherAllSlaveChannels bool `toml:"gather_all_slave_channels"`
|
||||||
MariadbDialect bool `toml:"mariadb_dialect"`
|
MariadbDialect bool `toml:"mariadb_dialect"`
|
||||||
GatherBinaryLogs bool `toml:"gather_binary_logs"`
|
GatherBinaryLogs bool `toml:"gather_binary_logs"`
|
||||||
|
|
@ -77,12 +78,16 @@ func (*Mysql) SampleConfig() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mysql) Init() error {
|
func (m *Mysql) Init() error {
|
||||||
if m.MariadbDialect {
|
switch {
|
||||||
|
case m.MariadbDialect && m.GatherReplicaStatus:
|
||||||
|
m.getStatusQuery = replicaStatusQueryMariadb
|
||||||
|
case m.MariadbDialect:
|
||||||
m.getStatusQuery = slaveStatusQueryMariadb
|
m.getStatusQuery = slaveStatusQueryMariadb
|
||||||
} else {
|
case m.GatherReplicaStatus:
|
||||||
|
m.getStatusQuery = replicaStatusQuery
|
||||||
|
default:
|
||||||
m.getStatusQuery = slaveStatusQuery
|
m.getStatusQuery = slaveStatusQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to localhost if nothing specified.
|
// Default to localhost if nothing specified.
|
||||||
if len(m.Servers) == 0 {
|
if len(m.Servers) == 0 {
|
||||||
s := config.NewSecret([]byte(localhost))
|
s := config.NewSecret([]byte(localhost))
|
||||||
|
|
@ -250,7 +255,9 @@ const (
|
||||||
globalStatusQuery = `SHOW GLOBAL STATUS`
|
globalStatusQuery = `SHOW GLOBAL STATUS`
|
||||||
globalVariablesQuery = `SHOW GLOBAL VARIABLES`
|
globalVariablesQuery = `SHOW GLOBAL VARIABLES`
|
||||||
slaveStatusQuery = `SHOW SLAVE STATUS`
|
slaveStatusQuery = `SHOW SLAVE STATUS`
|
||||||
|
replicaStatusQuery = `SHOW REPLICA STATUS`
|
||||||
slaveStatusQueryMariadb = `SHOW ALL SLAVES STATUS`
|
slaveStatusQueryMariadb = `SHOW ALL SLAVES STATUS`
|
||||||
|
replicaStatusQueryMariadb = `SHOW ALL REPLICAS STATUS`
|
||||||
binaryLogsQuery = `SHOW BINARY LOGS`
|
binaryLogsQuery = `SHOW BINARY LOGS`
|
||||||
infoSchemaProcessListQuery = `
|
infoSchemaProcessListQuery = `
|
||||||
SELECT COALESCE(command,''),COALESCE(state,''),count(*)
|
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)
|
err = m.gatherSlaveStatuses(db, servtag, acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,11 @@
|
||||||
## gather metrics from SHOW SLAVE STATUS command output
|
## gather metrics from SHOW SLAVE STATUS command output
|
||||||
# gather_slave_status = false
|
# 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 SLAVES STATUS command output for MariaDB
|
||||||
|
## use SHOW ALL REPLICAS STATUS command if enable gather replica status
|
||||||
# mariadb_dialect = false
|
# mariadb_dialect = false
|
||||||
|
|
||||||
## gather metrics from SHOW BINARY LOGS command output
|
## gather metrics from SHOW BINARY LOGS command output
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue