Created
July 21, 2022 05:59
-
-
Save byrnedo/1659018dc36177325a42bbf6378bf268 to your computer and use it in GitHub Desktop.
Go routine to periodically log sqlx connection pool stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go func(dbx *sqlx.DB) { | |
ticker := time.NewTicker(5 * time.Second) | |
defer ticker.Stop() | |
for { | |
select { | |
case <-ticker.C: | |
stats := dbx.Stats() | |
b, _ := json.Marshal(stats) | |
log.Printf("db stats: %d open, %d idle, %d in-use", stats.OpenConnections, stats.Idle, stats.InUse) | |
} | |
} | |
}(db) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment