diff --git a/docs/generated/metrics/metrics.html b/docs/generated/metrics/metrics.html
index 99c54a96d2fd..322cf53ac390 100644
--- a/docs/generated/metrics/metrics.html
+++ b/docs/generated/metrics/metrics.html
@@ -1473,6 +1473,7 @@
APPLICATION | sql.stats.flush.done_signals.ignored | Number of times the SQL Stats activity update job ignored the signal sent to it indicating a flush has completed | flush done signals ignored | COUNTER | COUNT | AVG | NON_NEGATIVE_DERIVATIVE |
APPLICATION | sql.stats.flush.duration | Time took to in nanoseconds to complete SQL Stats flush | SQL Stats Flush | HISTOGRAM | NANOSECONDS | AVG | NONE |
APPLICATION | sql.stats.flush.error | Number of errors encountered when flushing SQL Stats | SQL Stats Flush | COUNTER | COUNT | AVG | NON_NEGATIVE_DERIVATIVE |
+APPLICATION | sql.stats.flush.fingerprint.count | The number of unique statement and transaction fingerprints included in the SQL Stats flush | statement & transaction fingerprints | COUNTER | COUNT | AVG | NON_NEGATIVE_DERIVATIVE |
APPLICATION | sql.stats.mem.current | Current memory usage for fingerprint storage | Memory | GAUGE | BYTES | AVG | NONE |
APPLICATION | sql.stats.mem.max | Memory usage for fingerprint storage | Memory | HISTOGRAM | BYTES | AVG | NONE |
APPLICATION | sql.stats.reported.mem.current | Current memory usage for reported fingerprint storage | Memory | GAUGE | BYTES | AVG | NONE |
diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go
index f3128abd4872..e3ee3063d2bc 100644
--- a/pkg/sql/conn_executor.go
+++ b/pkg/sql/conn_executor.go
@@ -490,6 +490,7 @@ func NewServer(cfg *ExecutorConfig, pool *mon.BytesMonitor) *Server {
Knobs: cfg.SQLStatsTestingKnobs,
FlushCounter: serverMetrics.StatsMetrics.SQLStatsFlushStarted,
FlushDoneSignalsIgnored: serverMetrics.StatsMetrics.SQLStatsFlushDoneSignalsIgnored,
+ FlushedFingerprintCount: serverMetrics.StatsMetrics.SQLStatsFlushFingerprintCount,
FailureCounter: serverMetrics.StatsMetrics.SQLStatsFlushFailure,
FlushDuration: serverMetrics.StatsMetrics.SQLStatsFlushDuration,
}, memSQLStats)
@@ -590,6 +591,7 @@ func makeServerMetrics(cfg *ExecutorConfig) ServerMetrics {
DiscardedStatsCount: metric.NewCounter(MetaDiscardedSQLStats),
SQLStatsFlushStarted: metric.NewCounter(MetaSQLStatsFlushStarted),
SQLStatsFlushDoneSignalsIgnored: metric.NewCounter(MetaSQLStatsFlushDoneSignalsIgnored),
+ SQLStatsFlushFingerprintCount: metric.NewCounter(MetaSQLStatsFlushFingerprintCount),
SQLStatsFlushFailure: metric.NewCounter(MetaSQLStatsFlushFailure),
SQLStatsFlushDuration: metric.NewHistogram(metric.HistogramOptions{
diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go
index 84759a418956..41e6835e2f05 100644
--- a/pkg/sql/exec_util.go
+++ b/pkg/sql/exec_util.go
@@ -1094,6 +1094,12 @@ var (
Measurement: "SQL Stats Flush",
Unit: metric.Unit_COUNT,
}
+ MetaSQLStatsFlushFingerprintCount = metric.Metadata{
+ Name: "sql.stats.flush.fingerprint.count",
+ Help: "The number of unique statement and transaction fingerprints included in the SQL Stats flush",
+ Measurement: "statement & transaction fingerprints",
+ Unit: metric.Unit_COUNT,
+ }
MetaSQLStatsFlushDoneSignalsIgnored = metric.Metadata{
Name: "sql.stats.flush.done_signals.ignored",
Help: "Number of times the SQL Stats activity update job ignored the signal sent to it indicating " +
diff --git a/pkg/sql/executor_statement_metrics.go b/pkg/sql/executor_statement_metrics.go
index cb7f8314c346..7a796e5dab4a 100644
--- a/pkg/sql/executor_statement_metrics.go
+++ b/pkg/sql/executor_statement_metrics.go
@@ -77,6 +77,7 @@ type StatsMetrics struct {
SQLStatsFlushStarted *metric.Counter
SQLStatsFlushDoneSignalsIgnored *metric.Counter
+ SQLStatsFlushFingerprintCount *metric.Counter
SQLStatsFlushFailure *metric.Counter
SQLStatsFlushDuration metric.IHistogram
SQLStatsRemovedRows *metric.Counter
diff --git a/pkg/sql/sqlstats/persistedsqlstats/flush.go b/pkg/sql/sqlstats/persistedsqlstats/flush.go
index c14684f89678..81655ba4eb5a 100644
--- a/pkg/sql/sqlstats/persistedsqlstats/flush.go
+++ b/pkg/sql/sqlstats/persistedsqlstats/flush.go
@@ -62,9 +62,11 @@ func (s *PersistedSQLStats) Flush(ctx context.Context, stopper *stop.Stopper) {
return
}
+ fingerprintCount := s.SQLStats.GetTotalFingerprintCount()
+ s.cfg.FlushedFingerprintCount.Inc(fingerprintCount)
if log.V(1) {
log.Infof(ctx, "flushing %d stmt/txn fingerprints (%d bytes) after %s",
- s.SQLStats.GetTotalFingerprintCount(), s.SQLStats.GetTotalFingerprintBytes(), timeutil.Since(s.lastFlushStarted))
+ fingerprintCount, s.SQLStats.GetTotalFingerprintBytes(), timeutil.Since(s.lastFlushStarted))
}
s.lastFlushStarted = now
diff --git a/pkg/sql/sqlstats/persistedsqlstats/provider.go b/pkg/sql/sqlstats/persistedsqlstats/provider.go
index 5f038501396b..b06d467c3c96 100644
--- a/pkg/sql/sqlstats/persistedsqlstats/provider.go
+++ b/pkg/sql/sqlstats/persistedsqlstats/provider.go
@@ -50,6 +50,7 @@ type Config struct {
FlushDuration metric.IHistogram
FlushDoneSignalsIgnored *metric.Counter
FailureCounter *metric.Counter
+ FlushedFingerprintCount *metric.Counter
// Testing knobs.
Knobs *sqlstats.TestingKnobs