Class: Stats::Worker

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

Instance Method Summary collapse

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

#backlogObject



76
77
78
# File 'lib/stats.rb', line 76

def backlog
  @wstats.dig('last_status', 'backlog') || 0
end

#booting?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


16
17
18
# File 'lib/stats.rb', line 16

def killed?
  !!@wstats['killed']
end

#last_checkinObject



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

#loadObject



63
64
65
# File 'lib/stats.rb', line 63

def load
  running_threads/total_threads.to_f*100
end

#max_threadsObject 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

#memObject



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

#pcpuObject



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

#phaseObject



59
60
61
# File 'lib/stats.rb', line 59

def phase
  @wstats['phase']
end

#pidObject



8
9
10
# File 'lib/stats.rb', line 8

def pid
  @wstats['pid']
end

#pool_capacityObject



51
52
53
# File 'lib/stats.rb', line 51

def pool_capacity
  @wstats.dig('last_status', 'pool_capacity') || @wstats['pool_capacity'] || 0
end

#requests_countObject



72
73
74
# File 'lib/stats.rb', line 72

def requests_count
  @wstats.dig('last_status', 'requests_count') || @wstats['requests_count']
end

#runningObject 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_threadsObject



55
56
57
# File 'lib/stats.rb', line 55

def running_threads
  max_threads - pool_capacity
end

#uptimeObject



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