func Stats(ctx context.Context, db *sql.DB, name string, every time.Duration) {
	ticker := time.NewTicker(every)
	for {
		select {
		case <-ticker.C:
			stats := db.Stats()
			labels := prometheus.Labels{
				sqlInstance: name,
			}
			ConnInUse.With(labels).Set(float64(stats.InUse))
			ConnIdle.With(labels).Set(float64(stats.Idle))
			ConnWait.With(labels).Set(float64(stats.WaitCount))
			ConnIdleClosed.With(labels).Set(float64(stats.MaxIdleClosed))
			ConnIdleTimeClosed.With(labels).Set(float64(stats.MaxIdleTimeClosed))
			ConnLifetimeClosed.With(labels).Set(float64(stats.MaxLifetimeClosed))
			ConnWaitMS.With(labels).Set(float64(stats.WaitDuration.Milliseconds()))
		case <-ctx.Done():
			ticker.Stop()
			return
		}
	}
}
Stats, monitor db connection pool with interval every.
package metric
import (
	"context"
	"database/sql"
	"time"
	"github.com/prometheus/client_golang/prometheus"
)