Skip to content

Commit

Permalink
fix: add mariadb_dialect to address the MariaDB differences in INNODB…
Browse files Browse the repository at this point in the history
…_METRICS (#10486)
  • Loading branch information
MarcHagen authored Apr 19, 2022
1 parent bcc7c57 commit e8b08b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion plugins/inputs/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ and process. It has following fields:
for them. It has following fields:
* auto_increment_column(int, number)
* auto_increment_column_max(int, number)
* InnoDB metrics - all metrics of information_schema.INNODB_METRICS with a status "enabled"
* InnoDB metrics - all metrics of information_schema.INNODB_METRICS with a status "enabled". For MariaDB,
`mariadb_dialect = true` to use `ENABLED=1`.
* Perf table lock waits - gathers total number and time for SQL and external
lock waits events for each table and operation. It has following fields.
The unit of fields varies by the tags.
Expand Down
19 changes: 18 additions & 1 deletion plugins/inputs/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ const (
FROM information_schema.INNODB_METRICS
WHERE status='enabled'
`
innoDBMetricsQueryMariadb = `
EXECUTE IMMEDIATE CONCAT("
SELECT NAME, COUNT
FROM information_schema.INNODB_METRICS
WHERE ", IF(version() REGEXP '10\.[1-4].*',"status='enabled'", "ENABLED=1"), "
");
`
perfTableIOWaitsQuery = `
SELECT OBJECT_SCHEMA, OBJECT_NAME, COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE, COUNT_DELETE,
SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE, SUM_TIMER_DELETE
Expand Down Expand Up @@ -1245,8 +1252,18 @@ func (m *Mysql) gatherInfoSchemaAutoIncStatuses(db *sql.DB, serv string, acc tel
// gatherInnoDBMetrics can be used to fetch enabled metrics from
// information_schema.INNODB_METRICS
func (m *Mysql) gatherInnoDBMetrics(db *sql.DB, serv string, acc telegraf.Accumulator) error {
var (
query string
)

if m.MariadbDialect {
query = innoDBMetricsQueryMariadb
} else {
query = innoDBMetricsQuery
}

// run query
rows, err := db.Query(innoDBMetricsQuery)
rows, err := db.Query(query)
if err != nil {
return err
}
Expand Down

0 comments on commit e8b08b1

Please sign in to comment.