Skip to content

Instantly share code, notes, and snippets.

@byrnedo
Created July 21, 2022 05:59
Show Gist options
  • Save byrnedo/1659018dc36177325a42bbf6378bf268 to your computer and use it in GitHub Desktop.
Save byrnedo/1659018dc36177325a42bbf6378bf268 to your computer and use it in GitHub Desktop.
Go routine to periodically log sqlx connection pool stats
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