diff --git a/.my.cnf b/.my.cnf new file mode 100644 index 00000000..f71c7e5d --- /dev/null +++ b/.my.cnf @@ -0,0 +1,9 @@ +[client] +host=localhost +port=3306 +socket=/var/run/mysqld/mysqld.sock +user=foo +password=bar +[client.server1] +user = bar +password = bar123 diff --git a/collector/perf_schema_events_statements.go b/collector/perf_schema_events_statements.go index 0dc74210..d34a61c7 100644 --- a/collector/perf_schema_events_statements.go +++ b/collector/perf_schema_events_statements.go @@ -42,7 +42,10 @@ const perfEventsStatementsQuery = ` SUM_CREATED_TMP_TABLES, SUM_SORT_MERGE_PASSES, SUM_SORT_ROWS, - SUM_NO_INDEX_USED + SUM_NO_INDEX_USED, + QUANTILE_95, + QUANTILE_99, + QUANTILE_999 FROM ( SELECT * FROM performance_schema.events_statements_summary_by_digest @@ -67,7 +70,10 @@ const perfEventsStatementsQuery = ` Q.SUM_CREATED_TMP_TABLES, Q.SUM_SORT_MERGE_PASSES, Q.SUM_SORT_ROWS, - Q.SUM_NO_INDEX_USED + Q.SUM_NO_INDEX_USED, + Q.QUANTILE_95, + Q.QUANTILE_99, + Q.QUANTILE_999 ORDER BY SUM_TIMER_WAIT DESC LIMIT %d ` @@ -160,6 +166,21 @@ var ( "The total number of statements that used full table scans by digest.", []string{"schema", "digest", "digest_text"}, nil, ) + performanceSchemaEventsStatementsQuantile95 = prometheus.NewDesc( + prometheus.BuildFQName(namespace, performanceSchema, "events_statements_quantile_95"), + "The 95th percentile of the statement latency, in picoseconds.", + []string{"schema", "digest", "digest_text"}, nil, + ) + performanceSchemaEventsStatementsQuantile99 = prometheus.NewDesc( + prometheus.BuildFQName(namespace, performanceSchema, "events_statements_quantile_99"), + "The 99th percentile of the statement latency, in picoseconds.", + []string{"schema", "digest", "digest_text"}, nil, + ) + performanceSchemaEventsStatementsQuantile999 = prometheus.NewDesc( + prometheus.BuildFQName(namespace, performanceSchema, "events_statements_quantile_999"), + "The 99.9th percentile of the statement latency, in picoseconds.", + []string{"schema", "digest", "digest_text"}, nil, + ) ) // ScrapePerfEventsStatements collects from `performance_schema.events_statements_summary_by_digest`. @@ -204,10 +225,11 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance tmpTables, tmpDiskTables uint64 sortMergePasses, sortRows uint64 noIndexUsed uint64 + quantile95, quantile99, quantile999 uint64 ) for perfSchemaEventsStatementsRows.Next() { if err := perfSchemaEventsStatementsRows.Scan( - &schemaName, &digest, &digestText, &count, &queryTime, &lockTime, &cpuTime, &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, &quantile95, &quantile99, &quantile999, ); err != nil { return err } @@ -267,6 +289,18 @@ func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance performanceSchemaEventsStatementsNoIndexUsedDesc, prometheus.CounterValue, float64(noIndexUsed), schemaName, digest, digestText, ) + ch <- prometheus.MustNewConstMetric( + performanceSchemaEventsStatementsQuantile95, prometheus.CounterValue, float64(quantile95), + schemaName, digest, digestText, + ) + ch <- prometheus.MustNewConstMetric( + performanceSchemaEventsStatementsQuantile99, prometheus.CounterValue, float64(quantile99), + schemaName, digest, digestText, + ) + ch <- prometheus.MustNewConstMetric( + performanceSchemaEventsStatementsQuantile999, prometheus.CounterValue, float64(quantile999), + schemaName, digest, digestText, + ) } return nil }