Skip to content

Commit

Permalink
Fetch lock time and cpu time from performance schema
Browse files Browse the repository at this point in the history
Extend the query on `events_statements_summary_by_digest` to fetch
`SUM_LOCK_TIME` and `SUM_CPU_TIME` and return them as counters.

Signed-off-by: Cristian Greco <cristian@regolo.cc>
  • Loading branch information
cristiangreco committed Aug 27, 2024
1 parent afcd075 commit 3225ffa
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions collector/perf_schema_events_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const perfEventsStatementsQuery = `
LEFT(DIGEST_TEXT, %d) as DIGEST_TEXT,
COUNT_STAR,
SUM_TIMER_WAIT,
SUM_LOCK_TIME,
SUM_CPU_TIME,
SUM_ERRORS,
SUM_WARNINGS,
SUM_ROWS_AFFECTED,
Expand All @@ -54,6 +56,8 @@ const perfEventsStatementsQuery = `
Q.DIGEST_TEXT,
Q.COUNT_STAR,
Q.SUM_TIMER_WAIT,
Q.SUM_LOCK_TIME,
Q.SUM_CPU_TIME,
Q.SUM_ERRORS,
Q.SUM_WARNINGS,
Q.SUM_ROWS_AFFECTED,
Expand Down Expand Up @@ -96,6 +100,16 @@ var (
"The total time of events statements by digest.",
[]string{"schema", "digest", "digest_text"}, nil,
)
performanceSchemaEventsStatementsLockTimeDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "events_statements_lock_time_seconds_total"),
"The total lock time of events statements by digest.",
[]string{"schema", "digest", "digest_text"}, nil,
)
performanceSchemaEventsStatementsCpuTimeDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "events_statements_cpu_time_seconds_total"),
"The total cpu time of events statements by digest.",
[]string{"schema", "digest", "digest_text"}, nil,
)
performanceSchemaEventsStatementsErrorsDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "events_statements_errors_total"),
"The errors of events statements by digest.",
Expand Down Expand Up @@ -184,15 +198,16 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance

var (
schemaName, digest, digestText string
count, queryTime, errors, warnings uint64
count, queryTime, lockTime, cpuTime uint64
errors, warnings uint64
rowsAffected, rowsSent, rowsExamined uint64
tmpTables, tmpDiskTables uint64
sortMergePasses, sortRows uint64
noIndexUsed uint64
)
for perfSchemaEventsStatementsRows.Next() {
if err := perfSchemaEventsStatementsRows.Scan(
&schemaName, &digest, &digestText, &count, &queryTime, &errors, &warnings, &rowsAffected, &rowsSent, &rowsExamined, &tmpDiskTables, &tmpTables, &sortMergePasses, &sortRows, &noIndexUsed,
&schemaName, &digest, &digestText, &count, &queryTime, &lockTime, &cpuTime, &errors, &warnings, &rowsAffected, &rowsSent, &rowsExamined, &tmpDiskTables, &tmpTables, &sortMergePasses, &sortRows, &noIndexUsed,
); err != nil {
return err
}
Expand All @@ -204,6 +219,14 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance
performanceSchemaEventsStatementsTimeDesc, prometheus.CounterValue, float64(queryTime)/picoSeconds,
schemaName, digest, digestText,
)
ch <- prometheus.MustNewConstMetric(
performanceSchemaEventsStatementsLockTimeDesc, prometheus.CounterValue, float64(lockTime)/picoSeconds,
schemaName, digest, digestText,
)
ch <- prometheus.MustNewConstMetric(
performanceSchemaEventsStatementsCpuTimeDesc, prometheus.CounterValue, float64(cpuTime)/picoSeconds,
schemaName, digest, digestText,
)
ch <- prometheus.MustNewConstMetric(
performanceSchemaEventsStatementsErrorsDesc, prometheus.CounterValue, float64(errors),
schemaName, digest, digestText,
Expand Down

0 comments on commit 3225ffa

Please sign in to comment.