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

[receiver/mysql] feat: add table size metrics #32680

Merged
merged 2 commits into from
May 20, 2024
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
30 changes: 30 additions & 0 deletions .chloggen/feat_table_stats.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: receiver/mysql

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adds INFORMATION_SCHEMA TABLES metrics"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32693]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This adds table size metrics using the INFORMATION_SCHEMA TABLES table: https://dev.mysql.com/doc/refman/8.3/en/information-schema-tables-table.html.
Specifically, we are adding the columns: `TABLE_ROWS`, `AVG_ROW_LENGTH`, `DATA_LENGTH`, `INDEX_LENGTH`.


# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
37 changes: 37 additions & 0 deletions receiver/mysqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type client interface {
getVersion() (string, error)
getGlobalStats() (map[string]string, error)
getInnodbStats() (map[string]string, error)
getTableStats() ([]TableStats, error)
getTableIoWaitsStats() ([]TableIoWaitsStats, error)
getIndexIoWaitsStats() ([]IndexIoWaitsStats, error)
getStatementEventsStats() ([]StatementEventStats, error)
Expand Down Expand Up @@ -57,6 +58,15 @@ type IndexIoWaitsStats struct {
index string
}

type TableStats struct {
schema string
name string
rows int64
averageRowLength int64
dataLength int64
indexLength int64
}

type StatementEventStats struct {
schema string
digest string
Expand Down Expand Up @@ -231,6 +241,33 @@ func (c *mySQLClient) getInnodbStats() (map[string]string, error) {
return query(*c, q)
}

// getTableStats queries the db for information_schema table size metrics.
func (c *mySQLClient) getTableStats() ([]TableStats, error) {
query := "SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_ROWS, " +
"AVG_ROW_LENGTH, DATA_LENGTH, INDEX_LENGTH " +
"FROM information_schema.TABLES " +
"WHERE TABLE_SCHEMA NOT in ('information_schema', 'sys') " +
"ORDER BY TABLE_LENGTH DESC;"
rows, err := c.client.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
var stats []TableStats
for rows.Next() {
var s TableStats
err := rows.Scan(&s.schema, &s.name,
&s.rows, &s.averageRowLength,
&s.dataLength, &s.indexLength)
if err != nil {
return nil, err
}
stats = append(stats, s)
}

return stats, nil
}

// getTableIoWaitsStats queries the db for table_io_waits metrics.
func (c *mySQLClient) getTableIoWaitsStats() ([]TableIoWaitsStats, error) {
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, " +
Expand Down
46 changes: 46 additions & 0 deletions receiver/mysqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,21 @@ The total wait time of the summarized timed events.
| digest | Digest. | Any Str |
| digest_text | Text before digestion. | Any Str |

### mysql.table.average_row_length

The average row length in bytes for a given table.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | false |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| table | Table name for event or process. | Any Str |
| schema | The schema of the object. | Any Str |

### mysql.table.lock_wait.read.count

The total table lock wait read events.
Expand Down Expand Up @@ -583,6 +598,37 @@ The total table lock wait write events times.
| table | Table name for event or process. | Any Str |
| kind | Write operation types. | Str: ``allow_write``, ``concurrent_insert``, ``low_priority``, ``normal``, ``external`` |

### mysql.table.rows

The number of rows for a given table.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| 1 | Sum | Int | Cumulative | false |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| table | Table name for event or process. | Any Str |
| schema | The schema of the object. | Any Str |

### mysql.table.size

The table size in bytes for a given table.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | false |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| table | Table name for event or process. | Any Str |
| schema | The schema of the object. | Any Str |
| kind | The table size types. | Str: ``data``, ``index`` |

### mysql.table_open_cache

The number of hits, misses or overflows for open tables cache lookups.
Expand Down
12 changes: 12 additions & 0 deletions receiver/mysqlreceiver/internal/metadata/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading