Class: Barnes::Instruments::PumaInstrument::StatValue
- Inherits:
-
Object
- Object
- Barnes::Instruments::PumaInstrument::StatValue
- Defined in:
- lib/barnes/instruments/puma_stats_value.rb
Overview
This class is responsible for consuming a puma generated stats hash that can come in two “flavors” one is a “single process” server which will look like this:
{ "backlog": 0, "running": 0, "pool_capacity": 16 }
The other is a multiple cluster server that will look like this:
{"workers"=>2, "phase"=>0, "booted_workers"=>2, "old_workers"=>0, "worker_status"=>[{"pid"=>35020, "index"=>0, "phase"=>0, "booted"=>true, "last_checkin"=>"2018-05-21T19:53:18Z", "last_status"=>{"backlog"=>0, "running"=>5, "pool_capacity"=>5}}, {"pid"=>35021, "index"=>1, "phase"=>0, "booted"=>true, "last_checkin"=>"2018-05-21T19:53:18Z", "last_status"=>{"backlog"=>0, "running"=>5, "pool_capacity"=>5}}]}
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #cluster? ⇒ Boolean
-
#initialize(stats, key) ⇒ StatValue
constructor
A new instance of StatValue.
- #single? ⇒ Boolean
-
#value ⇒ Object
For single worker process use value directly for multiple workers use the sum.
Constructor Details
#initialize(stats, key) ⇒ StatValue
Returns a new instance of StatValue.
17 18 19 20 21 |
# File 'lib/barnes/instruments/puma_stats_value.rb', line 17 def initialize(stats, key) @stats = stats @key = key @cluster = stats.key?("worker_status") end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
15 16 17 |
# File 'lib/barnes/instruments/puma_stats_value.rb', line 15 def key @key end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
15 16 17 |
# File 'lib/barnes/instruments/puma_stats_value.rb', line 15 def stats @stats end |
Instance Method Details
#cluster? ⇒ Boolean
27 28 29 |
# File 'lib/barnes/instruments/puma_stats_value.rb', line 27 def cluster? @cluster end |
#single? ⇒ Boolean
23 24 25 |
# File 'lib/barnes/instruments/puma_stats_value.rb', line 23 def single? !cluster? end |
#value ⇒ Object
For single worker process use value directly for multiple workers use the sum.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/barnes/instruments/puma_stats_value.rb', line 35 def value return stats[key] if single? first_worker = stats["worker_status"].first return nil unless first_worker && first_worker["last_status"].key?(key) value = 0 stats["worker_status"].each do |worker_status| value += worker_status["last_status"][key] || 0 end return value end |