mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: provide stats on number of open connections to the database.
This change provides a convenient way to monitor database connection pool. Change-Id: I4b3757855b43f3b254acf9312e2a16e2f87840d0 Reviewed-on: https://go-review.googlesource.com/7950 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
9d0239771a
commit
297c1d297f
2 changed files with 36 additions and 0 deletions
|
|
@ -572,6 +572,22 @@ func (db *DB) SetMaxOpenConns(n int) {
|
|||
}
|
||||
}
|
||||
|
||||
// DBStats contains database statistics.
|
||||
type DBStats struct {
|
||||
// OpenConnections is the number of open connections to the database.
|
||||
OpenConnections int
|
||||
}
|
||||
|
||||
// Stats returns database statistics.
|
||||
func (db *DB) Stats() DBStats {
|
||||
db.mu.Lock()
|
||||
stats := DBStats{
|
||||
OpenConnections: db.numOpen,
|
||||
}
|
||||
db.mu.Unlock()
|
||||
return stats
|
||||
}
|
||||
|
||||
// Assumes db.mu is locked.
|
||||
// If there are connRequests and the connection limit hasn't been reached,
|
||||
// then tell the connectionOpener to open new connections.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue