stat.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package pgxpool
  2. import (
  3. "time"
  4. "github.com/jackc/puddle/v2"
  5. )
  6. // Stat is a snapshot of Pool statistics.
  7. type Stat struct {
  8. s *puddle.Stat
  9. newConnsCount int64
  10. lifetimeDestroyCount int64
  11. idleDestroyCount int64
  12. }
  13. // AcquireCount returns the cumulative count of successful acquires from the pool.
  14. func (s *Stat) AcquireCount() int64 {
  15. return s.s.AcquireCount()
  16. }
  17. // AcquireDuration returns the total duration of all successful acquires from
  18. // the pool.
  19. func (s *Stat) AcquireDuration() time.Duration {
  20. return s.s.AcquireDuration()
  21. }
  22. // AcquiredConns returns the number of currently acquired connections in the pool.
  23. func (s *Stat) AcquiredConns() int32 {
  24. return s.s.AcquiredResources()
  25. }
  26. // CanceledAcquireCount returns the cumulative count of acquires from the pool
  27. // that were canceled by a context.
  28. func (s *Stat) CanceledAcquireCount() int64 {
  29. return s.s.CanceledAcquireCount()
  30. }
  31. // ConstructingConns returns the number of conns with construction in progress in
  32. // the pool.
  33. func (s *Stat) ConstructingConns() int32 {
  34. return s.s.ConstructingResources()
  35. }
  36. // EmptyAcquireCount returns the cumulative count of successful acquires from the pool
  37. // that waited for a resource to be released or constructed because the pool was
  38. // empty.
  39. func (s *Stat) EmptyAcquireCount() int64 {
  40. return s.s.EmptyAcquireCount()
  41. }
  42. // IdleConns returns the number of currently idle conns in the pool.
  43. func (s *Stat) IdleConns() int32 {
  44. return s.s.IdleResources()
  45. }
  46. // MaxConns returns the maximum size of the pool.
  47. func (s *Stat) MaxConns() int32 {
  48. return s.s.MaxResources()
  49. }
  50. // TotalConns returns the total number of resources currently in the pool.
  51. // The value is the sum of ConstructingConns, AcquiredConns, and
  52. // IdleConns.
  53. func (s *Stat) TotalConns() int32 {
  54. return s.s.TotalResources()
  55. }
  56. // NewConnsCount returns the cumulative count of new connections opened.
  57. func (s *Stat) NewConnsCount() int64 {
  58. return s.newConnsCount
  59. }
  60. // MaxLifetimeDestroyCount returns the cumulative count of connections destroyed
  61. // because they exceeded MaxConnLifetime.
  62. func (s *Stat) MaxLifetimeDestroyCount() int64 {
  63. return s.lifetimeDestroyCount
  64. }
  65. // MaxIdleDestroyCount returns the cumulative count of connections destroyed because
  66. // they exceeded MaxConnIdleTime.
  67. func (s *Stat) MaxIdleDestroyCount() int64 {
  68. return s.idleDestroyCount
  69. }
  70. // EmptyAcquireWaitTime returns the cumulative time waited for successful acquires
  71. // from the pool for a resource to be released or constructed because the pool was
  72. // empty.
  73. func (s *Stat) EmptyAcquireWaitTime() time.Duration {
  74. return s.s.EmptyAcquireWaitTime()
  75. }