Class: Stats
- Inherits:
-
Object
- Object
- Stats
- Defined in:
- lib/stats.rb
Defined Under Namespace
Classes: Worker
Instance Method Summary collapse
- #booting? ⇒ Boolean
-
#initialize(stats) ⇒ Stats
constructor
A new instance of Stats.
- #load ⇒ Object
- #max_threads ⇒ Object
- #phase ⇒ Object
- #pid ⇒ Object
- #pid=(pid) ⇒ Object
- #pool_capacity ⇒ Object
- #requests_count ⇒ Object
- #running ⇒ Object
- #running_threads ⇒ Object
- #spawned_threads ⇒ Object
- #state_file_path ⇒ Object
- #state_file_path=(state_file_path) ⇒ Object
- #total_threads ⇒ Object
- #uptime ⇒ Object
- #version ⇒ Object
- #workers ⇒ Object
Constructor Details
#initialize(stats) ⇒ Stats
Returns a new instance of Stats.
87 88 89 |
# File 'lib/stats.rb', line 87 def initialize(stats) @stats = stats end |
Instance Method Details
#booting? ⇒ Boolean
116 117 118 |
# File 'lib/stats.rb', line 116 def booting? workers.all?(&:booting?) end |
#load ⇒ Object
154 155 156 |
# File 'lib/stats.rb', line 154 def load running_threads/total_threads.to_f*100 end |
#max_threads ⇒ Object
132 133 134 |
# File 'lib/stats.rb', line 132 def max_threads workers.reduce(0) { |total, wstats| total + wstats.max_threads } end |
#phase ⇒ Object
150 151 152 |
# File 'lib/stats.rb', line 150 def phase @stats['phase'] end |
#pid ⇒ Object
99 100 101 |
# File 'lib/stats.rb', line 99 def pid @stats['pid'] end |
#pid=(pid) ⇒ Object
95 96 97 |
# File 'lib/stats.rb', line 95 def pid=(pid) @stats['pid'] = pid end |
#pool_capacity ⇒ Object
146 147 148 |
# File 'lib/stats.rb', line 146 def pool_capacity @stats['pool_capacity'] || 0 end |
#requests_count ⇒ Object
136 137 138 139 140 |
# File 'lib/stats.rb', line 136 def requests_count workers_with_requests_count = workers.select(&:requests_count) return if workers_with_requests_count.none? workers_with_requests_count.reduce(0) { |total, wstats| total + wstats.requests_count } end |
#running ⇒ Object
142 143 144 |
# File 'lib/stats.rb', line 142 def running @stats['running'] || 0 end |
#running_threads ⇒ Object
124 125 126 |
# File 'lib/stats.rb', line 124 def running_threads workers.reduce(0) { |total, wstats| total + wstats.running_threads } end |
#spawned_threads ⇒ Object
128 129 130 |
# File 'lib/stats.rb', line 128 def spawned_threads workers.reduce(0) { |total, wstats| total + wstats.spawned_threads } end |
#state_file_path ⇒ Object
107 108 109 |
# File 'lib/stats.rb', line 107 def state_file_path @stats['state_file_path'] end |
#state_file_path=(state_file_path) ⇒ Object
103 104 105 |
# File 'lib/stats.rb', line 103 def state_file_path=(state_file_path) @stats['state_file_path'] = state_file_path end |
#total_threads ⇒ Object
120 121 122 |
# File 'lib/stats.rb', line 120 def total_threads workers.reduce(0) { |total, wstats| total + wstats.max_threads } end |
#uptime ⇒ Object
111 112 113 114 |
# File 'lib/stats.rb', line 111 def uptime return 0 unless @stats.key?('started_at') (Time.now - Time.parse(@stats['started_at'])).to_i end |
#version ⇒ Object
158 159 160 161 162 |
# File 'lib/stats.rb', line 158 def version return nil unless @stats.key?('versions') "#{@stats['versions']['puma']}/#{@stats['versions']['ruby']['engine']}#{@stats['versions']['ruby']['version']}p#{@stats['versions']['ruby']['patchlevel']}" end |