Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Added more InnoDB metric to MySQL plugin (influxdata#2179)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreF authored and mlinde201 committed Feb 6, 2017
1 parent 15c9438 commit b05244d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/inputs/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This plugin gathers the statistic data from MySQL server
* Process list
* User Statistics
* Info schema auto increment columns
* InnoDB metrics
* Table I/O waits
* Index I/O waits
* Perf Schema table lock waits
Expand Down Expand Up @@ -51,6 +52,9 @@ This plugin gathers the statistic data from MySQL server
## gather auto_increment columns and max values from information schema
gather_info_schema_auto_inc = true
#
## gather metrics from INFORMATION_SCHEMA.INNODB_METRICS
gather_innodb_metrics = true
#
## gather metrics from SHOW SLAVE STATUS command output
gather_slave_status = true
#
Expand Down Expand Up @@ -141,6 +145,7 @@ 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"
* 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
55 changes: 55 additions & 0 deletions plugins/inputs/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Mysql struct {
GatherProcessList bool `toml:"gather_process_list"`
GatherUserStatistics bool `toml:"gather_user_statistics"`
GatherInfoSchemaAutoInc bool `toml:"gather_info_schema_auto_inc"`
GatherInnoDBMetrics bool `toml:"gather_innodb_metrics"`
GatherSlaveStatus bool `toml:"gather_slave_status"`
GatherBinaryLogs bool `toml:"gather_binary_logs"`
GatherTableIOWaits bool `toml:"gather_table_io_waits"`
Expand Down Expand Up @@ -67,6 +68,9 @@ var sampleConfig = `
## gather auto_increment columns and max values from information schema
gather_info_schema_auto_inc = true
#
## gather metrics from INFORMATION_SCHEMA.INNODB_METRICS
gather_innodb_metrics = true
#
## gather metrics from SHOW SLAVE STATUS command output
gather_slave_status = true
#
Expand Down Expand Up @@ -435,6 +439,11 @@ const (
FROM information_schema.tables t
JOIN information_schema.columns c USING (table_schema,table_name)
WHERE c.extra = 'auto_increment' AND t.auto_increment IS NOT NULL
`
innoDBMetricsQuery = `
SELECT NAME, COUNT
FROM information_schema.INNODB_METRICS
WHERE status='enabled'
`
perfTableIOWaitsQuery = `
SELECT OBJECT_SCHEMA, OBJECT_NAME, COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE, COUNT_DELETE,
Expand Down Expand Up @@ -610,6 +619,13 @@ func (m *Mysql) gatherServer(serv string, acc telegraf.Accumulator) error {
}
}

if m.GatherInnoDBMetrics {
err = m.gatherInnoDBMetrics(db, serv, acc)
if err != nil {
return err
}
}

if m.GatherTableIOWaits {
err = m.gatherPerfTableIOWaits(db, serv, acc)
if err != nil {
Expand Down Expand Up @@ -1244,6 +1260,45 @@ func (m *Mysql) gatherInfoSchemaAutoIncStatuses(db *sql.DB, serv string, acc tel
return nil
}

// 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 {
// run query
rows, err := db.Query(innoDBMetricsQuery)
if err != nil {
return err
}
defer rows.Close()

var key string
var val sql.RawBytes

// parse DSN and save server tag
servtag := getDSNTag(serv)
tags := map[string]string{"server": servtag}
fields := make(map[string]interface{})
for rows.Next() {
if err := rows.Scan(&key, &val); err != nil {
return err
}
key = strings.ToLower(key)
// parse value, if it is numeric then save, otherwise ignore
if floatVal, ok := parseValue(val); ok {
fields[key] = floatVal
}
// Send 20 fields at a time
if len(fields) >= 20 {
acc.AddFields("mysql_innodb", fields, tags)
fields = make(map[string]interface{})
}
}
// Send any remaining fields
if len(fields) > 0 {
acc.AddFields("mysql_innodb", fields, tags)
}
return nil
}

// gatherPerfTableLockWaits can be used to get
// the total number and time for SQL and external lock wait events
// for each table and operation
Expand Down

0 comments on commit b05244d

Please sign in to comment.