Skip to content

Commit

Permalink
[receiver/mysql] feat: add table metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
s-v-a-n committed May 20, 2024
1 parent bbcb16c commit 5437618
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 319 deletions.
2 changes: 1 addition & 1 deletion .chloggen/feat_table_stats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ issues: [32693]
# 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` and `TABLE_LENGTH` as the sum of `DATA_LENGTH` and `INDEX_LENGTH`.
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,
Expand Down
6 changes: 2 additions & 4 deletions receiver/mysqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ type TableStats struct {
name string
rows int64
averageRowLength int64
totalLength int64
dataLength int64
indexLength int64
}
Expand Down Expand Up @@ -245,8 +244,7 @@ func (c *mySQLClient) getInnodbStats() (map[string]string, error) {
// 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 `TOTAL_LENGTH`, " +
"DATA_LENGTH, INDEX_LENGTH " +
"AVG_ROW_LENGTH, DATA_LENGTH, INDEX_LENGTH " +
"FROM information_schema.TABLES " +
"WHERE TABLE_SCHEMA NOT in ('information_schema', 'sys') " +
"ORDER BY TABLE_LENGTH DESC;"
Expand All @@ -260,7 +258,7 @@ func (c *mySQLClient) getTableStats() ([]TableStats, error) {
var s TableStats
err := rows.Scan(&s.schema, &s.name,
&s.rows, &s.averageRowLength,
&s.totalLength, &s.dataLength, &s.indexLength)
&s.dataLength, &s.indexLength)
if err != nil {
return nil, err
}
Expand Down
35 changes: 3 additions & 32 deletions receiver/mysqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,36 +534,6 @@ The average row length in bytes for a given table.
| table | Table name for event or process. | Any Str |
| schema | The schema of the object. | Any Str |
### mysql.table.data_length
The data 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.index_length
The index 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 @@ -643,9 +613,9 @@ The number of rows for a given table.
| table | Table name for event or process. | Any Str |
| schema | The schema of the object. | Any Str |
### mysql.table.total_length
### mysql.table.size
The total length (sum of data_length and index_length) in bytes for a given table.
The table size in bytes for a given table.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
Expand All @@ -657,6 +627,7 @@ The total length (sum of data_length and index_length) in bytes for a given tabl
| ---- | ----------- | ------ |
| 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
Expand Down
12 changes: 2 additions & 10 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

0 comments on commit 5437618

Please sign in to comment.