Skip to content

Commit

Permalink
[receiver/mysql]: add scraping io_waits metrics (#14328)
Browse files Browse the repository at this point in the history
  • Loading branch information
aboguszewski-sumo authored Sep 23, 2022
1 parent 48316fe commit e6083b5
Show file tree
Hide file tree
Showing 15 changed files with 2,081 additions and 7 deletions.
79 changes: 79 additions & 0 deletions receiver/mysqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type client interface {
Connect() error
getGlobalStats() (map[string]string, error)
getInnodbStats() (map[string]string, error)
getTableIoWaitsStats() ([]TableIoWaitsStats, error)
getIndexIoWaitsStats() ([]IndexIoWaitsStats, error)
Close() error
}

Expand All @@ -34,6 +36,28 @@ type mySQLClient struct {
client *sql.DB
}

type IoWaitsStats struct {
schema string
name string
countDelete int64
countFetch int64
countInsert int64
countUpdate int64
timeDelete int64
timeFetch int64
timeInsert int64
timeUpdate int64
}

type TableIoWaitsStats struct {
IoWaitsStats
}

type IndexIoWaitsStats struct {
IoWaitsStats
index string
}

var _ client = (*mySQLClient)(nil)

func newMySQLClient(conf *Config) client {
Expand Down Expand Up @@ -73,6 +97,61 @@ func (c *mySQLClient) getInnodbStats() (map[string]string, error) {
return Query(*c, query)
}

// getTableIoWaitsStats queries the db for table_io_waits metrics.
func (c *mySQLClient) getTableIoWaitsStats() ([]TableIoWaitsStats, error) {
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, " +
"COUNT_DELETE, COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE," +
"SUM_TIMER_DELETE, SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE" +
"FROM performance_schema.table_io_waits_summary_by_table" +
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema');"
rows, err := c.client.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
var stats []TableIoWaitsStats
for rows.Next() {
var s TableIoWaitsStats
err := rows.Scan(&s.schema, &s.name,
&s.countDelete, &s.countFetch, &s.countInsert, &s.countUpdate,
&s.timeDelete, &s.timeFetch, &s.timeInsert, &s.timeUpdate)
if err != nil {
return nil, err
}
stats = append(stats, s)
}

return stats, nil
}

// getIndexIoWaitsStats queries the db for index_io_waits metrics.
func (c *mySQLClient) getIndexIoWaitsStats() ([]IndexIoWaitsStats, error) {
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, ifnull(INDEX_NAME, 'NONE') as INDEX_NAME," +
"COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE, COUNT_DELETE," +
"SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE, SUM_TIMER_DELETE" +
"FROM performance_schema.table_io_waits_summary_by_index_usage" +
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema');"

rows, err := c.client.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
var stats []IndexIoWaitsStats
for rows.Next() {
var s IndexIoWaitsStats
err := rows.Scan(&s.schema, &s.name, &s.index,
&s.countDelete, &s.countFetch, &s.countInsert, &s.countUpdate,
&s.timeDelete, &s.timeFetch, &s.timeInsert, &s.timeUpdate)
if err != nil {
return nil, err
}
stats = append(stats, s)
}

return stats, nil
}

func Query(c mySQLClient, query string) (map[string]string, error) {
rows, err := c.client.Query(query)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions receiver/mysqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ These are the metrics available for this scraper.
| **mysql.commands** | The number of times each type of command has been executed. | 1 | Sum(Int) | <ul> <li>command</li> </ul> |
| **mysql.double_writes** | The number of writes to the InnoDB doublewrite buffer. | 1 | Sum(Int) | <ul> <li>double_writes</li> </ul> |
| **mysql.handlers** | The number of requests to various MySQL handlers. | 1 | Sum(Int) | <ul> <li>handler</li> </ul> |
| **mysql.index.io.wait.count** | The total count of I/O wait events for an index. | 1 | Sum(Int) | <ul> <li>io_waits_operations</li> <li>table_name</li> <li>schema</li> <li>index_name</li> </ul> |
| **mysql.index.io.wait.time** | The total time of I/O wait events for an index. | ns | Sum(Int) | <ul> <li>io_waits_operations</li> <li>table_name</li> <li>schema</li> <li>index_name</li> </ul> |
| **mysql.locks** | The number of MySQL locks. | 1 | Sum(Int) | <ul> <li>locks</li> </ul> |
| **mysql.log_operations** | The number of InnoDB log operations. | 1 | Sum(Int) | <ul> <li>log_operations</li> </ul> |
| **mysql.operations** | The number of InnoDB operations. | 1 | Sum(Int) | <ul> <li>operations</li> </ul> |
| **mysql.page_operations** | The number of InnoDB page operations. | 1 | Sum(Int) | <ul> <li>page_operations</li> </ul> |
| **mysql.row_locks** | The number of InnoDB row locks. | 1 | Sum(Int) | <ul> <li>row_locks</li> </ul> |
| **mysql.row_operations** | The number of InnoDB row operations. | 1 | Sum(Int) | <ul> <li>row_operations</li> </ul> |
| **mysql.sorts** | The number of MySQL sorts. | 1 | Sum(Int) | <ul> <li>sorts</li> </ul> |
| **mysql.table.io.wait.count** | The total count of I/O wait events for a table. | 1 | Sum(Int) | <ul> <li>io_waits_operations</li> <li>table_name</li> <li>schema</li> </ul> |
| **mysql.table.io.wait.time** | The total time of I/O wait events for a table. | ns | Sum(Int) | <ul> <li>io_waits_operations</li> <li>table_name</li> <li>schema</li> </ul> |
| **mysql.threads** | The state of MySQL threads. | 1 | Sum(Int) | <ul> <li>threads</li> </ul> |

**Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default.
Expand Down Expand Up @@ -51,11 +55,15 @@ metrics:
| command (command) | The command types. | execute, close, fetch, prepare, reset, send_long_data |
| double_writes (kind) | The doublewrite types. | pages_written, writes |
| handler (kind) | The handler types. | commit, delete, discover, external_lock, mrr_init, prepare, read_first, read_key, read_last, read_next, read_prev, read_rnd, read_rnd_next, rollback, savepoint, savepoint_rollback, update, write |
| index_name (index) | The name of the index. | |
| io_waits_operations (operation) | The io_waits operation type. | delete, fetch, insert, update |
| locks (kind) | The table locks type. | immediate, waited |
| log_operations (operation) | The log operation types. | waits, write_requests, writes |
| operations (operation) | The operation types. | fsyncs, reads, writes |
| page_operations (operation) | The page operation types. | created, read, written |
| row_locks (kind) | The row lock type. | waits, time |
| row_operations (operation) | The row operation type. | deleted, inserted, read, updated |
| schema (schema) | The schema of the object. | |
| sorts (kind) | The sort count type. | merge_passes, range, rows, scan |
| table_name (table) | Table name for event or process. | |
| threads (kind) | The thread count type. | cached, connected, created, running |
Loading

0 comments on commit e6083b5

Please sign in to comment.