diff --git a/plugins/inputs/mysql/README.md b/plugins/inputs/mysql/README.md index e14db4831b3f9..3e1ed6b47fde6 100644 --- a/plugins/inputs/mysql/README.md +++ b/plugins/inputs/mysql/README.md @@ -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. diff --git a/plugins/inputs/mysql/mysql.go b/plugins/inputs/mysql/mysql.go index 11886441eabac..79c48f7c11518 100644 --- a/plugins/inputs/mysql/mysql.go +++ b/plugins/inputs/mysql/mysql.go @@ -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 @@ -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 }