Class: PumaStats
- Inherits:
-
Object
- Object
- PumaStats
- Defined in:
- lib/puma/plugin/nexus_puma_statsd.rb
Overview
Wrap puma’s stats in a safe API
Instance Method Summary collapse
- #backlog ⇒ Object
- #booted_workers ⇒ Object
- #clustered? ⇒ Boolean
-
#initialize(stats) ⇒ PumaStats
constructor
A new instance of PumaStats.
- #max_threads ⇒ Object
- #old_workers ⇒ Object
- #pool_capacity ⇒ Object
- #requests_count ⇒ Object
- #running ⇒ Object
- #workers ⇒ Object
Constructor Details
#initialize(stats) ⇒ PumaStats
Returns a new instance of PumaStats.
14 15 16 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 14 def initialize(stats) @stats = stats end |
Instance Method Details
#backlog ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 42 def backlog if clustered? @stats[:worker_status].map { |s| s[:last_status].fetch(:backlog, 0) }.inject(0, &:+) else @stats.fetch(:backlog, 0) end end |
#booted_workers ⇒ Object
26 27 28 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 26 def booted_workers @stats.fetch(:booted_workers, 1) end |
#clustered? ⇒ Boolean
18 19 20 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 18 def clustered? @stats.key?(:workers) end |
#max_threads ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 58 def max_threads if clustered? @stats[:worker_status].map { |s| s[:last_status].fetch(:max_threads, 0) }.inject(0, &:+) else @stats.fetch(:max_threads, 0) end end |
#old_workers ⇒ Object
30 31 32 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 30 def old_workers @stats.fetch(:old_workers, 0) end |
#pool_capacity ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 50 def pool_capacity if clustered? @stats[:worker_status].map { |s| s[:last_status].fetch(:pool_capacity, 0) }.inject(0, &:+) else @stats.fetch(:pool_capacity, 0) end end |
#requests_count ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 66 def requests_count if clustered? @stats[:worker_status].map { |s| s[:last_status].fetch(:requests_count, 0) }.inject(0, &:+) else @stats.fetch(:requests_count, 0) end end |
#running ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 34 def running if clustered? @stats[:worker_status].map { |s| s[:last_status].fetch(:running, 0) }.inject(0, &:+) else @stats.fetch(:running, 0) end end |
#workers ⇒ Object
22 23 24 |
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 22 def workers @stats.fetch(:workers, 1) end |