Skip to content

Commit

Permalink
Mysql metrics/query perf (#56)
Browse files Browse the repository at this point in the history
* normalised statement counts, cumulative time per statement

* changed to event time limit to be maxInt64

* removed print statements

* nit

* Update go.mod

* enabled statement event time

* small fix

* Added count-star datapoint
  • Loading branch information
naman47vyas authored and bhogayatakb committed Dec 4, 2024
1 parent 46875ea commit 4352aa2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
7 changes: 4 additions & 3 deletions receiver/mysqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type StatementEventStats struct {
countSortMergePasses int64
countSortRows int64
countNoIndexUsed int64
countStar int64
}

type tableLockWaitEventStats struct {
Expand Down Expand Up @@ -348,7 +349,7 @@ func (c *mySQLClient) getStatementEventsStats() ([]StatementEventStats, error) {
"LEFT(DIGEST_TEXT, %d) as DIGEST_TEXT, SUM_TIMER_WAIT, SUM_ERRORS,"+
"SUM_WARNINGS, SUM_ROWS_AFFECTED, SUM_ROWS_SENT, SUM_ROWS_EXAMINED,"+
"SUM_CREATED_TMP_DISK_TABLES, SUM_CREATED_TMP_TABLES, SUM_SORT_MERGE_PASSES,"+
"SUM_SORT_ROWS, SUM_NO_INDEX_USED "+
"SUM_SORT_ROWS, SUM_NO_INDEX_USED , COUNT_STAR "+
"FROM performance_schema.events_statements_summary_by_digest "+
"WHERE SCHEMA_NAME NOT IN ('mysql', 'performance_schema', 'information_schema') "+
"AND last_seen > DATE_SUB(NOW(), INTERVAL %d SECOND) "+
Expand All @@ -360,6 +361,7 @@ func (c *mySQLClient) getStatementEventsStats() ([]StatementEventStats, error) {

rows, err := c.client.Query(query)
if err != nil {
fmt.Println(err.Error())
return nil, err
}
defer rows.Close()
Expand All @@ -370,13 +372,12 @@ func (c *mySQLClient) getStatementEventsStats() ([]StatementEventStats, error) {
err := rows.Scan(&s.schema, &s.digest, &s.digestText,
&s.sumTimerWait, &s.countErrors, &s.countWarnings,
&s.countRowsAffected, &s.countRowsSent, &s.countRowsExamined, &s.countCreatedTmpDiskTables,
&s.countCreatedTmpTables, &s.countSortMergePasses, &s.countSortRows, &s.countNoIndexUsed)
&s.countCreatedTmpTables, &s.countSortMergePasses, &s.countSortRows, &s.countNoIndexUsed, &s.countStar)
if err != nil {
return nil, err
}
stats = append(stats, s)
}

return stats, nil
}

Expand Down
3 changes: 2 additions & 1 deletion receiver/mysqlreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package mysqlreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver"

import (
"math"
"time"

"go.opentelemetry.io/collector/config/confignet"
Expand All @@ -18,7 +19,7 @@ import (
const (
defaultStatementEventsDigestTextLimit = 120
defaultStatementEventsLimit = 250
defaultStatementEventsTimeLimit = 24 * time.Hour
defaultStatementEventsTimeLimit = time.Duration(math.MaxInt64)
)

type Config struct {
Expand Down
4 changes: 2 additions & 2 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.

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

4 changes: 2 additions & 2 deletions receiver/mysqlreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ metrics:
aggregation_temporality: cumulative
attributes: []
mysql.statement_event.count:
enabled: false
enabled: true
description: Summary of current and recent statement events.
unit: "1"
sum:
Expand All @@ -555,7 +555,7 @@ metrics:
aggregation_temporality: cumulative
attributes: [schema, digest, digest_text, event_state]
mysql.statement_event.wait.time:
enabled: false
enabled: true
description: The total wait time of the summarized timed events.
unit: ns
sum:
Expand Down

0 comments on commit 4352aa2

Please sign in to comment.