Skip to content

Commit

Permalink
feat/sqlx_metric (#4587)
Browse files Browse the repository at this point in the history
Co-authored-by: aiden.ma <Aiden.ma@yijinin.com>
  • Loading branch information
MarkJoyMa and aiden.ma authored Jan 22, 2025
1 parent e6d1b47 commit 030c859
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/stores/sqlx/sqlmanager.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package sqlx

import (
"crypto/sha256"
"database/sql"
"encoding/hex"
"io"
"time"

"github.com/go-sql-driver/mysql"

"github.com/zeromicro/go-zero/core/syncx"
)

Expand All @@ -23,6 +27,21 @@ func getCachedSqlConn(driverName, server string) (*sql.DB, error) {
return nil, err
}

if driverName == mysqlDriverName {
if cfg, err := mysql.ParseDSN(server); err != nil {
// do nothing here
} else {
checksum := sha256.Sum256([]byte(server))
connCollector.registerClient(&statGetter{
dbName: cfg.DBName,
hash: hex.EncodeToString(checksum[:]),
poolStats: func() sql.DBStats {
return conn.Stats()
},
})
}
}

return conn, nil
})
if err != nil {
Expand Down

0 comments on commit 030c859

Please sign in to comment.