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 26, 2024
1 parent dd8afce commit 4212787
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 @@ -32,6 +32,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 @@ -55,6 +57,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 @@ -97,6 +101,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, db *sql.DB, ch cha

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, &tmpTables, &tmpDiskTables, &sortMergePasses, &sortRows, &noIndexUsed,
&schemaName, &digest, &digestText, &count, &queryTime, &lockTime, &cpuTime, &errors, &warnings, &rowsAffected, &rowsSent, &rowsExamined, &tmpTables, &tmpDiskTables, &sortMergePasses, &sortRows, &noIndexUsed,
); err != nil {
return err
}
Expand All @@ -204,6 +219,14 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, db *sql.DB, ch cha
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 4212787

Please sign in to comment.