- MaxOpenConnections: The max allowed open connections to the DB, as set by DB.SetMaxOpenConns.
- InUse: The number of connections actively in-use.
- Idle: The number of open connections that are currently idle.
- WaitCount: The total number of times a goroutine has had to wait for a connection.
- WaitDuration: The cumulative amount of time goroutines have spent waiting for a connection.
- MaxIdleClosed: The number of connections closed according to the limit specified by DB.SetMaxIdleConns.
- MaxLifetimeClosed: The number of connections closed because they exceeded the duration specified by DB.SetConnMaxLifetime.
New Stats Exposed in Go's database/SQL Package
May 22, 2018
Database
If you keep up with the Go development cycle, then you’ll know Go recently entered its feature-freeze for the Go 1.11 release. One of the changes for this upcoming release that caught my eye was to the database/sql package. Daniel Theophanes contributed a change that introduces several new counters available via the DB.Stats() method.
If you’re not familiar with it, DB.Stats() returns a DBStat structure containing information about the underlying sql.DB that the method is called on. Up to this point, the struct has had a single field, tracking the current number of open connections to the database. Daniel’s patch introduces a number of additional fields though: