mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 00:50:20 +08:00
feat/sqlx_metric (#4587)
Co-authored-by: aiden.ma <Aiden.ma@yijinin.com>
This commit is contained in:
parent
e6d1b47a43
commit
030c859171
@ -1,10 +1,14 @@
|
|||||||
package sqlx
|
package sqlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/syncx"
|
"github.com/zeromicro/go-zero/core/syncx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +27,21 @@ func getCachedSqlConn(driverName, server string) (*sql.DB, error) {
|
|||||||
return nil, err
|
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
|
return conn, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user