Class: Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/stats.rb

Defined Under Namespace

Classes: Worker

Instance Method Summary collapse

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

Returns:

  • (Boolean)


116
117
118
# File 'lib/stats.rb', line 116

def booting?
  workers.all?(&:booting?)
end

#loadObject



154
155
156
# File 'lib/stats.rb', line 154

def load
  running_threads/total_threads.to_f*100
end

#max_threadsObject



132
133
134
# File 'lib/stats.rb', line 132

def max_threads
  workers.reduce(0) { |total, wstats| total + wstats.max_threads }
end

#phaseObject



150
151
152
# File 'lib/stats.rb', line 150

def phase
  @stats['phase']
end

#pidObject



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_capacityObject



146
147
148
# File 'lib/stats.rb', line 146

def pool_capacity
  @stats['pool_capacity'] || 0
end

#requests_countObject



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

#runningObject



142
143
144
# File 'lib/stats.rb', line 142

def running
  @stats['running'] || 0
end

#running_threadsObject



124
125
126
# File 'lib/stats.rb', line 124

def running_threads
  workers.reduce(0) { |total, wstats| total + wstats.running_threads }
end

#spawned_threadsObject



128
129
130
# File 'lib/stats.rb', line 128

def spawned_threads
  workers.reduce(0) { |total, wstats| total + wstats.spawned_threads }
end

#state_file_pathObject



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_threadsObject



120
121
122
# File 'lib/stats.rb', line 120

def total_threads
  workers.reduce(0) { |total, wstats| total + wstats.max_threads }
end

#uptimeObject



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

#versionObject



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

#workersObject



91
92
93
# File 'lib/stats.rb', line 91

def workers
  @workers ||= (@stats['worker_status'] || [@stats]).map { |wstats| Worker.new(wstats) }
end