From d65c5e6f5935d99da4c7b8bc6c807340ca986388 Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Wed, 28 Aug 2024 11:07:39 +0200 Subject: [PATCH] Fetch lock time and cpu time from performance schema (#862) 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 --- collector/perf_schema_events_statements.go | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/collector/perf_schema_events_statements.go b/collector/perf_schema_events_statements.go index f359d594..fe125601 100644 --- a/collector/perf_schema_events_statements.go +++ b/collector/perf_schema_events_statements.go @@ -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, @@ -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, @@ -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.", @@ -184,7 +198,8 @@ 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 @@ -192,7 +207,7 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance ) 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 } @@ -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,