Some checks failed
CI / test (push) Failing after 13s
- slog.go: SlogLogger adapts *slog.Logger to dbx.Logger interface - scan.go: Collect[T] and CollectOne[T] generic helpers using pgx.RowToStructByName - cluster.go: slow query logging via Config.SlowQueryThreshold (Warn level in queryEnd) - stats.go: PoolStats with Cluster.Stats() aggregating pool stats across all nodes - config.go/node.go: NodeConfig.Tracer passthrough for pgx.QueryTracer (OpenTelemetry) - options.go: WithSlowQueryThreshold and WithTracer functional options - dbxtest/tx.go: RunInTx runs callback in always-rolled-back transaction for test isolation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package dbx
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// PoolStats is an aggregate of pool statistics across all nodes.
|
|
type PoolStats struct {
|
|
AcquireCount int64
|
|
AcquireDuration time.Duration
|
|
AcquiredConns int32
|
|
CanceledAcquireCount int64
|
|
ConstructingConns int32
|
|
EmptyAcquireCount int64
|
|
IdleConns int32
|
|
MaxConns int32
|
|
TotalConns int32
|
|
Nodes map[string]*pgxpool.Stat
|
|
}
|
|
|
|
// Stats returns aggregate pool statistics for all nodes in the cluster.
|
|
func (c *Cluster) Stats() PoolStats {
|
|
ps := PoolStats{
|
|
Nodes: make(map[string]*pgxpool.Stat, len(c.all)),
|
|
}
|
|
for _, n := range c.all {
|
|
s := n.pool.Stat()
|
|
ps.Nodes[n.name] = s
|
|
ps.AcquireCount += s.AcquireCount()
|
|
ps.AcquireDuration += s.AcquireDuration()
|
|
ps.AcquiredConns += s.AcquiredConns()
|
|
ps.CanceledAcquireCount += s.CanceledAcquireCount()
|
|
ps.ConstructingConns += s.ConstructingConns()
|
|
ps.EmptyAcquireCount += s.EmptyAcquireCount()
|
|
ps.IdleConns += s.IdleConns()
|
|
ps.MaxConns += s.MaxConns()
|
|
ps.TotalConns += s.TotalConns()
|
|
}
|
|
return ps
|
|
}
|