Skip to content

Commit 2ef168b

Browse files
authored
Add perf_schema quantile columns to collector (#897)
* Use summary to represent query latency quantiles. This change replaces the individual quantile (95,99,999) metrics with a summary that captures those respective quantiles. Enables a more prometheus native representation of the data. --------- Signed-off-by: Matt Nolf <[email protected]>
1 parent 8c897e0 commit 2ef168b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Diff for: collector/perf_schema_events_statements.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ const perfEventsStatementsQuery = `
4242
SUM_CREATED_TMP_TABLES,
4343
SUM_SORT_MERGE_PASSES,
4444
SUM_SORT_ROWS,
45-
SUM_NO_INDEX_USED
45+
SUM_NO_INDEX_USED,
46+
QUANTILE_95,
47+
QUANTILE_99,
48+
QUANTILE_999
4649
FROM (
4750
SELECT *
4851
FROM performance_schema.events_statements_summary_by_digest
@@ -67,7 +70,10 @@ const perfEventsStatementsQuery = `
6770
Q.SUM_CREATED_TMP_TABLES,
6871
Q.SUM_SORT_MERGE_PASSES,
6972
Q.SUM_SORT_ROWS,
70-
Q.SUM_NO_INDEX_USED
73+
Q.SUM_NO_INDEX_USED,
74+
Q.QUANTILE_95,
75+
Q.QUANTILE_99,
76+
Q.QUANTILE_999
7177
ORDER BY SUM_TIMER_WAIT DESC
7278
LIMIT %d
7379
`
@@ -160,6 +166,11 @@ var (
160166
"The total number of statements that used full table scans by digest.",
161167
[]string{"schema", "digest", "digest_text"}, nil,
162168
)
169+
performanceSchemaEventsStatementsLatency = prometheus.NewDesc(
170+
prometheus.BuildFQName(namespace, performanceSchema, "events_statements_latency"),
171+
"A summary of statement latency by digest",
172+
[]string{"schema", "digest", "digest_text"}, nil,
173+
)
163174
)
164175

165176
// ScrapePerfEventsStatements collects from `performance_schema.events_statements_summary_by_digest`.
@@ -204,10 +215,11 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance
204215
tmpTables, tmpDiskTables uint64
205216
sortMergePasses, sortRows uint64
206217
noIndexUsed uint64
218+
quantile95, quantile99, quantile999 uint64
207219
)
208220
for perfSchemaEventsStatementsRows.Next() {
209221
if err := perfSchemaEventsStatementsRows.Scan(
210-
&schemaName, &digest, &digestText, &count, &queryTime, &lockTime, &cpuTime, &errors, &warnings, &rowsAffected, &rowsSent, &rowsExamined, &tmpDiskTables, &tmpTables, &sortMergePasses, &sortRows, &noIndexUsed,
222+
&schemaName, &digest, &digestText, &count, &queryTime, &lockTime, &cpuTime, &errors, &warnings, &rowsAffected, &rowsSent, &rowsExamined, &tmpDiskTables, &tmpTables, &sortMergePasses, &sortRows, &noIndexUsed, &quantile95, &quantile99, &quantile999,
211223
); err != nil {
212224
return err
213225
}
@@ -267,6 +279,11 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance
267279
performanceSchemaEventsStatementsNoIndexUsedDesc, prometheus.CounterValue, float64(noIndexUsed),
268280
schemaName, digest, digestText,
269281
)
282+
ch <- prometheus.MustNewConstSummary(performanceSchemaEventsStatementsLatency, count, float64(queryTime)/picoSeconds, map[float64]float64{
283+
95: float64(quantile95) / picoSeconds,
284+
99: float64(quantile99) / picoSeconds,
285+
999: float64(quantile999) / picoSeconds,
286+
}, schemaName, digest, digestText)
270287
}
271288
return nil
272289
}

0 commit comments

Comments
 (0)