Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch lock time and cpu time from performance schema #862

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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