Class: PumaStats
- Inherits:
-
Object
- Object
- PumaStats
- Defined in:
- lib/puma/plugin/statsd.rb
Overview
Wrap puma’s stats in a safe API
Instance Method Summary collapse
- #backlog ⇒ Object
- #booted_workers ⇒ Object
- #clustered? ⇒ Boolean
-
#initialize(stats, previous_requests_count = 0) ⇒ PumaStats
constructor
A new instance of PumaStats.
- #max_threads ⇒ Object
- #old_workers ⇒ Object
- #percent_busy ⇒ Object
- #pool_capacity ⇒ Object
- #requests_count ⇒ Object
- #requests_delta ⇒ Object
- #running ⇒ Object
- #workers ⇒ Object
Constructor Details
#initialize(stats, previous_requests_count = 0) ⇒ PumaStats
Returns a new instance of PumaStats.
39 40 41 42 |
# File 'lib/puma/plugin/statsd.rb', line 39 def initialize(stats, previous_requests_count = 0) @stats = stats @previous_requests_count = previous_requests_count end |
Instance Method Details
#backlog ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/puma/plugin/statsd.rb', line 68 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
52 53 54 |
# File 'lib/puma/plugin/statsd.rb', line 52 def booted_workers @stats.fetch(:booted_workers, 1) end |
#clustered? ⇒ Boolean
44 45 46 |
# File 'lib/puma/plugin/statsd.rb', line 44 def clustered? @stats.has_key?(:workers) end |
#max_threads ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/puma/plugin/statsd.rb', line 84 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
56 57 58 |
# File 'lib/puma/plugin/statsd.rb', line 56 def old_workers @stats.fetch(:old_workers, 0) end |
#percent_busy ⇒ Object
100 101 102 |
# File 'lib/puma/plugin/statsd.rb', line 100 def percent_busy (1 - (pool_capacity / max_threads.to_f)) * 100 end |
#pool_capacity ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/puma/plugin/statsd.rb', line 76 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
92 93 94 95 96 97 98 |
# File 'lib/puma/plugin/statsd.rb', line 92 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 |
#requests_delta ⇒ Object
104 105 106 |
# File 'lib/puma/plugin/statsd.rb', line 104 def requests_delta requests_count - @previous_requests_count end |
#running ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/puma/plugin/statsd.rb', line 60 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
48 49 50 |
# File 'lib/puma/plugin/statsd.rb', line 48 def workers @stats.fetch(:workers, 1) end |