Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add mariadb_dialect to address the MariaDB differences in INNODB_METRICS #10486

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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