Gather all mysql channels (#5517)
This commit is contained in:
parent
1fa9259392
commit
e5b7a094da
|
|
@ -63,9 +63,15 @@ This plugin gathers the statistic data from MySQL server
|
||||||
## gather metrics from INFORMATION_SCHEMA.INNODB_METRICS
|
## gather metrics from INFORMATION_SCHEMA.INNODB_METRICS
|
||||||
# gather_innodb_metrics = false
|
# gather_innodb_metrics = false
|
||||||
|
|
||||||
|
## gather metrics from all channels from SHOW SLAVE STATUS command output
|
||||||
|
# gather_all_slave_channels = false
|
||||||
|
|
||||||
## gather metrics from SHOW SLAVE STATUS command output
|
## gather metrics from SHOW SLAVE STATUS command output
|
||||||
# gather_slave_status = false
|
# gather_slave_status = false
|
||||||
|
|
||||||
|
## use SHOW ALL SLAVES STATUS command output for MariaDB
|
||||||
|
# mariadb_dialect = false
|
||||||
|
|
||||||
## gather metrics from SHOW BINARY LOGS command output
|
## gather metrics from SHOW BINARY LOGS command output
|
||||||
# gather_binary_logs = false
|
# gather_binary_logs = false
|
||||||
|
|
||||||
|
|
@ -205,7 +211,9 @@ measurement name.
|
||||||
* Slave status - metrics from `SHOW SLAVE STATUS` the metrics are gathered when
|
* Slave status - metrics from `SHOW SLAVE STATUS` the metrics are gathered when
|
||||||
the single-source replication is on. If the multi-source replication is set,
|
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.
|
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.
|
||||||
* 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.
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ 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"`
|
||||||
|
GatherAllSlaveChannels bool `toml:"gather_all_slave_channels"`
|
||||||
|
MariadbDialect bool `toml:"mariadb_dialect"`
|
||||||
GatherBinaryLogs bool `toml:"gather_binary_logs"`
|
GatherBinaryLogs bool `toml:"gather_binary_logs"`
|
||||||
GatherTableIOWaits bool `toml:"gather_table_io_waits"`
|
GatherTableIOWaits bool `toml:"gather_table_io_waits"`
|
||||||
GatherTableLockWaits bool `toml:"gather_table_lock_waits"`
|
GatherTableLockWaits bool `toml:"gather_table_lock_waits"`
|
||||||
|
|
@ -47,6 +49,7 @@ type Mysql struct {
|
||||||
lastT time.Time
|
lastT time.Time
|
||||||
initDone bool
|
initDone bool
|
||||||
scanIntervalSlow uint32
|
scanIntervalSlow uint32
|
||||||
|
getStatusQuery string
|
||||||
}
|
}
|
||||||
|
|
||||||
const sampleConfig = `
|
const sampleConfig = `
|
||||||
|
|
@ -94,6 +97,12 @@ const sampleConfig = `
|
||||||
## 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 all channels from SHOW SLAVE STATUS command output
|
||||||
|
# gather_all_slave_channels = false
|
||||||
|
|
||||||
|
## use MariaDB dialect for all channels SHOW SLAVE STATUS
|
||||||
|
# mariadb_dialect = false
|
||||||
|
|
||||||
## gather metrics from SHOW BINARY LOGS command output
|
## gather metrics from SHOW BINARY LOGS command output
|
||||||
# gather_binary_logs = false
|
# gather_binary_logs = false
|
||||||
|
|
||||||
|
|
@ -166,6 +175,11 @@ func (m *Mysql) InitMysql() {
|
||||||
m.scanIntervalSlow = uint32(interval.Seconds())
|
m.scanIntervalSlow = uint32(interval.Seconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if m.MariadbDialect {
|
||||||
|
m.getStatusQuery = slaveStatusQueryMariadb
|
||||||
|
} else {
|
||||||
|
m.getStatusQuery = slaveStatusQuery
|
||||||
|
}
|
||||||
m.initDone = true
|
m.initDone = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -295,6 +309,7 @@ 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`
|
||||||
|
slaveStatusQueryMariadb = `SHOW ALL SLAVES STATUS`
|
||||||
binaryLogsQuery = `SHOW BINARY LOGS`
|
binaryLogsQuery = `SHOW BINARY LOGS`
|
||||||
infoSchemaProcessListQuery = `
|
infoSchemaProcessListQuery = `
|
||||||
SELECT COALESCE(command,''),COALESCE(state,''),count(*)
|
SELECT COALESCE(command,''),COALESCE(state,''),count(*)
|
||||||
|
|
@ -657,7 +672,10 @@ func (m *Mysql) parseGlobalVariables(key string, value sql.RawBytes) (interface{
|
||||||
// This code does not work with multi-source replication.
|
// This code does not work with multi-source replication.
|
||||||
func (m *Mysql) gatherSlaveStatuses(db *sql.DB, serv string, acc telegraf.Accumulator) error {
|
func (m *Mysql) gatherSlaveStatuses(db *sql.DB, serv string, acc telegraf.Accumulator) error {
|
||||||
// run query
|
// run query
|
||||||
rows, err := db.Query(slaveStatusQuery)
|
var rows *sql.Rows
|
||||||
|
var err error
|
||||||
|
|
||||||
|
rows, err = db.Query(m.getStatusQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -668,9 +686,11 @@ func (m *Mysql) gatherSlaveStatuses(db *sql.DB, serv string, acc telegraf.Accumu
|
||||||
tags := map[string]string{"server": servtag}
|
tags := map[string]string{"server": servtag}
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
|
|
||||||
// to save the column names as a field key
|
// for each channel record
|
||||||
// scanning keys and values separately
|
for rows.Next() {
|
||||||
if rows.Next() {
|
// to save the column names as a field key
|
||||||
|
// scanning keys and values separately
|
||||||
|
|
||||||
// get columns names, and create an array with its length
|
// get columns names, and create an array with its length
|
||||||
cols, err := rows.Columns()
|
cols, err := rows.Columns()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -689,11 +709,26 @@ func (m *Mysql) gatherSlaveStatuses(db *sql.DB, serv string, acc telegraf.Accumu
|
||||||
if m.MetricVersion >= 2 {
|
if m.MetricVersion >= 2 {
|
||||||
col = strings.ToLower(col)
|
col = strings.ToLower(col)
|
||||||
}
|
}
|
||||||
if value, ok := m.parseValue(*vals[i].(*sql.RawBytes)); ok {
|
|
||||||
|
if m.GatherAllSlaveChannels &&
|
||||||
|
(strings.ToLower(col) == "channel_name" || strings.ToLower(col) == "connection_name") {
|
||||||
|
// Since the default channel name is empty, we need this block
|
||||||
|
channelName := "default"
|
||||||
|
if len(*vals[i].(*sql.RawBytes)) > 0 {
|
||||||
|
channelName = string(*vals[i].(*sql.RawBytes))
|
||||||
|
}
|
||||||
|
tags["channel"] = channelName
|
||||||
|
} else if value, ok := m.parseValue(*vals[i].(*sql.RawBytes)); ok {
|
||||||
fields["slave_"+col] = value
|
fields["slave_"+col] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
acc.AddFields("mysql", fields, tags)
|
acc.AddFields("mysql", fields, tags)
|
||||||
|
|
||||||
|
// Only the first row is relevant if not all slave-channels should be gathered,
|
||||||
|
// so break here and skip the remaining rows
|
||||||
|
if !m.GatherAllSlaveChannels {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue