Skip to content

Commit

Permalink
Add more metrics for *sql.DB (#3230)
Browse files Browse the repository at this point in the history
Closes #2909.
  • Loading branch information
slavabobik authored Aug 23, 2023
1 parent 7049116 commit a78b98a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/backends/sqlite/metadata/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (r *Registry) Collect(ch chan<- prometheus.Metric) {
r.p.Collect(ch)

r.rw.RLock()
defer r.rw.RLock()
defer r.rw.RUnlock()

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
Expand Down
61 changes: 59 additions & 2 deletions internal/util/fsql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,65 @@ func (c *metricsCollector) Collect(ch chan<- prometheus.Metric) {
float64(stats.OpenConnections),
)

// Add other metrics from stats here.
// TODO https://github.com/FerretDB/FerretDB/issues/2909
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "in_use"),
"The number of connections currently in use.",
nil, c.labels,
),
prometheus.GaugeValue,
float64(stats.InUse),
)

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "idle"),
"The number of idle connections.",
nil, c.labels,
),
prometheus.GaugeValue,
float64(stats.Idle),
)

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "wait_count_total"),
"The total number of connections waited for.",
nil, c.labels,
),
prometheus.CounterValue,
float64(stats.WaitCount),
)

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "wait_duration_seconds_total"),
"The total time blocked waiting for a new connection.",
nil, c.labels,
),
prometheus.CounterValue,
float64(stats.WaitDuration.Seconds()),
)

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "max_idle_closed_total"),
"The total number of connections closed due to SetMaxIdleConns.",
nil, c.labels,
),
prometheus.CounterValue,
float64(stats.MaxIdleClosed),
)

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "max_idle_time_closed_total"),
"The total number of connections closed due to SetConnMaxIdleTime.",
nil, c.labels,
),
prometheus.CounterValue,
float64(stats.MaxIdleTimeClosed),
)

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
Expand Down

0 comments on commit a78b98a

Please sign in to comment.