Class: Stats::Worker
- Inherits:
-
Object
- Object
- Stats::Worker
- Defined in:
- lib/stats.rb
Instance Method Summary collapse
- #backlog ⇒ Object
- #booting? ⇒ Boolean
-
#initialize(wstats) ⇒ Worker
constructor
A new instance of Worker.
- #killed=(killed) ⇒ Object
- #killed? ⇒ Boolean
- #last_checkin ⇒ Object
- #load ⇒ Object
- #max_threads ⇒ Object (also: #total_threads)
- #mem ⇒ Object
- #mem=(mem) ⇒ Object
- #pcpu ⇒ Object
- #pcpu=(pcpu) ⇒ Object
- #phase ⇒ Object
- #pid ⇒ Object
- #pool_capacity ⇒ Object
- #requests_count ⇒ Object
- #running ⇒ Object (also: #spawned_threads)
- #running_threads ⇒ Object
- #uptime ⇒ Object
Constructor Details
#initialize(wstats) ⇒ Worker
Returns a new instance of Worker.
4 5 6 |
# File 'lib/stats.rb', line 4 def initialize(wstats) @wstats = wstats end |
Instance Method Details
#backlog ⇒ Object
76 77 78 |
# File 'lib/stats.rb', line 76 def backlog @wstats.dig('last_status', 'backlog') || 0 end |
#booting? ⇒ Boolean
36 37 38 |
# File 'lib/stats.rb', line 36 def booting? @wstats.key?('last_status') && @wstats['last_status'].empty? end |
#killed=(killed) ⇒ Object
12 13 14 |
# File 'lib/stats.rb', line 12 def killed=(killed) @wstats['killed'] = killed end |
#killed? ⇒ Boolean
16 17 18 |
# File 'lib/stats.rb', line 16 def killed? !!@wstats['killed'] end |
#last_checkin ⇒ Object
80 81 82 83 84 |
# File 'lib/stats.rb', line 80 def last_checkin (Time.now - Time.parse(@wstats['last_checkin'])).round rescue 0 end |
#load ⇒ Object
63 64 65 |
# File 'lib/stats.rb', line 63 def load running_threads/total_threads.to_f*100 end |
#max_threads ⇒ Object Also known as: total_threads
46 47 48 |
# File 'lib/stats.rb', line 46 def max_threads @wstats.dig('last_status', 'max_threads') || @wstats['max_threads'] || 0 end |
#mem ⇒ Object
24 25 26 |
# File 'lib/stats.rb', line 24 def mem @wstats['mem'] end |
#mem=(mem) ⇒ Object
20 21 22 |
# File 'lib/stats.rb', line 20 def mem=(mem) @wstats['mem'] = mem end |
#pcpu ⇒ Object
32 33 34 |
# File 'lib/stats.rb', line 32 def pcpu @wstats['pcpu'] end |
#pcpu=(pcpu) ⇒ Object
28 29 30 |
# File 'lib/stats.rb', line 28 def pcpu=(pcpu) @wstats['pcpu'] = pcpu end |
#phase ⇒ Object
59 60 61 |
# File 'lib/stats.rb', line 59 def phase @wstats['phase'] end |
#pid ⇒ Object
8 9 10 |
# File 'lib/stats.rb', line 8 def pid @wstats['pid'] end |
#pool_capacity ⇒ Object
51 52 53 |
# File 'lib/stats.rb', line 51 def pool_capacity @wstats.dig('last_status', 'pool_capacity') || @wstats['pool_capacity'] || 0 end |
#requests_count ⇒ Object
72 73 74 |
# File 'lib/stats.rb', line 72 def requests_count @wstats.dig('last_status', 'requests_count') || @wstats['requests_count'] end |
#running ⇒ Object Also known as: spawned_threads
40 41 42 |
# File 'lib/stats.rb', line 40 def running @wstats.dig('last_status', 'running') || @wstats['running'] || 0 end |
#running_threads ⇒ Object
55 56 57 |
# File 'lib/stats.rb', line 55 def running_threads max_threads - pool_capacity end |
#uptime ⇒ Object
67 68 69 70 |
# File 'lib/stats.rb', line 67 def uptime return 0 unless @wstats.key?('started_at') (Time.now - Time.parse(@wstats['started_at'])).to_i end |