Skip to content

Commit

Permalink
[receiver/mysql]: add mysql.commands metric with support for delete, …
Browse files Browse the repository at this point in the history
…insert, select, update (#17589)

feat(mysqlreceiver): add mysql.commands metric with support for delete, insert, select, update

Signed-off-by: Dominik Rosiek <[email protected]>
  • Loading branch information
sumo-drosiek authored Jan 17, 2023
1 parent 13b8d0c commit b72951b
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/drosiek-mysql-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: add mysql.commands metric with supprot for delete, insert, select, update

# One or more tracking issues related to the change
issues: [14138]

# (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:
14 changes: 14 additions & 0 deletions receiver/mysqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,20 @@ The number of transmitted bytes between server and clients.
| ---- | ----------- | ------ |
| kind | The name of the transmission direction. | Str: ``received``, ``sent`` |
### mysql.commands
The number of times each type of command has been executed.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| 1 | Sum | Int | Cumulative | true |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| command | The command types. | Str: ``delete``, ``insert``, ``select``, ``update`` |
### mysql.connection.count
The number of connection attempts (successful or not) to the MySQL server.
Expand Down
104 changes: 104 additions & 0 deletions receiver/mysqlreceiver/internal/metadata/generated_metrics.go

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

20 changes: 20 additions & 0 deletions receiver/mysqlreceiver/internal/metadata/generated_metrics_test.go

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

4 changes: 4 additions & 0 deletions receiver/mysqlreceiver/internal/metadata/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ all_metrics:
enabled: true
mysql.client.network.io:
enabled: true
mysql.commands:
enabled: true
mysql.connection.count:
enabled: true
mysql.connection.errors:
Expand Down Expand Up @@ -99,6 +101,8 @@ no_metrics:
enabled: false
mysql.client.network.io:
enabled: false
mysql.commands:
enabled: false
mysql.connection.count:
enabled: false
mysql.connection.errors:
Expand Down
14 changes: 14 additions & 0 deletions receiver/mysqlreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ attributes:
description: The prepare statement command types.
type: string
enum: [execute, close, fetch, prepare, reset, send_long_data]
command:
description: The command types.
type: string
enum: [delete, insert, select, update]
connection_error:
name_override: error
description: The connection error type.
Expand Down Expand Up @@ -221,6 +225,16 @@ metrics:
monotonic: true
aggregation: cumulative
attributes: [prepared_statements_command]
mysql.commands:
enabled: false
description: The number of times each type of command has been executed.
unit: 1
sum:
value_type: int
input_type: string
monotonic: true
aggregation: cumulative
attributes: [command]
mysql.handlers:
enabled: true
description: The number of requests to various MySQL handlers.
Expand Down
12 changes: 11 additions & 1 deletion receiver/mysqlreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (m *mySQLScraper) scrapeGlobalStats(now pcommon.Timestamp, errs *scrapererr
case "Connections":
addPartialIfError(errs, m.mb.RecordMysqlConnectionCountDataPoint(now, v))

// commands
// prepared_statements_commands
case "Com_stmt_execute":
addPartialIfError(errs, m.mb.RecordMysqlPreparedStatementsDataPoint(now, v,
metadata.AttributePreparedStatementsCommandExecute))
Expand All @@ -221,6 +221,16 @@ func (m *mySQLScraper) scrapeGlobalStats(now pcommon.Timestamp, errs *scrapererr
addPartialIfError(errs, m.mb.RecordMysqlPreparedStatementsDataPoint(now, v,
metadata.AttributePreparedStatementsCommandSendLongData))

// commands
case "Com_delete":
addPartialIfError(errs, m.mb.RecordMysqlCommandsDataPoint(now, v, metadata.AttributeCommandDelete))
case "Com_insert":
addPartialIfError(errs, m.mb.RecordMysqlCommandsDataPoint(now, v, metadata.AttributeCommandInsert))
case "Com_select":
addPartialIfError(errs, m.mb.RecordMysqlCommandsDataPoint(now, v, metadata.AttributeCommandSelect))
case "Com_update":
addPartialIfError(errs, m.mb.RecordMysqlCommandsDataPoint(now, v, metadata.AttributeCommandUpdate))

// created tmps
case "Created_tmp_disk_tables":
addPartialIfError(errs, m.mb.RecordMysqlTmpResourcesDataPoint(now, v, metadata.AttributeTmpResourceDiskTables))
Expand Down
1 change: 1 addition & 0 deletions receiver/mysqlreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestScrape(t *testing.T) {

cfg.Metrics.MysqlClientNetworkIo.Enabled = true
cfg.Metrics.MysqlPreparedStatements.Enabled = true
cfg.Metrics.MysqlCommands.Enabled = true

cfg.Metrics.MysqlReplicaSQLDelay.Enabled = true
cfg.Metrics.MysqlReplicaTimeBehindSource.Enabled = true
Expand Down
63 changes: 63 additions & 0 deletions receiver/mysqlreceiver/testdata/scraper/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,69 @@
]
},
"unit": "s"
},
{
"description": "The number of times each type of command has been executed.",
"name": "mysql.commands",
"sum": {
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE",
"dataPoints": [
{
"asInt": "50",
"attributes": [
{
"key": "command",
"value": {
"stringValue": "delete"
}
}
],
"startTimeUnixNano": "1644862687825728000",
"timeUnixNano": "1644862687825772000"
},
{
"asInt": "78",
"attributes": [
{
"key": "command",
"value": {
"stringValue": "insert"
}
}
],
"startTimeUnixNano": "1644862687825728000",
"timeUnixNano": "1644862687825772000"
},
{
"asInt": "106",
"attributes": [
{
"key": "command",
"value": {
"stringValue": "select"
}
}
],
"startTimeUnixNano": "1644862687825728000",
"timeUnixNano": "1644862687825772000"
},
{
"asInt": "173",
"attributes": [
{
"key": "command",
"value": {
"stringValue": "update"
}
}
],
"startTimeUnixNano": "1644862687825728000",
"timeUnixNano": "1644862687825772000"
}
],
"isMonotonic": true
},
"unit": "1"
}
]
}
Expand Down

0 comments on commit b72951b

Please sign in to comment.