Class: SidekiqMonitoring::Global
- Inherits:
-
Object
- Object
- SidekiqMonitoring::Global
- Includes:
- StatusMixin
- Defined in:
- lib/sidekiq-monitoring.rb
Instance Attribute Summary collapse
-
#elapsed_thresholds ⇒ Object
Returns the value of attribute elapsed_thresholds.
-
#latency_thresholds ⇒ Object
Returns the value of attribute latency_thresholds.
-
#queue_size_thresholds ⇒ Object
Returns the value of attribute queue_size_thresholds.
Attributes included from StatusMixin
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #global_status ⇒ Object
-
#initialize(queue_size_thresholds = nil, latency_thresholds = nil, elapsed_thresholds = nil) ⇒ Global
constructor
A new instance of Global.
- #queues ⇒ Object
- #workers ⇒ Object
Methods included from StatusMixin
#<=>, #criticality, #monitoring_status
Constructor Details
#initialize(queue_size_thresholds = nil, latency_thresholds = nil, elapsed_thresholds = nil) ⇒ Global
Returns a new instance of Global.
155 156 157 158 159 |
# File 'lib/sidekiq-monitoring.rb', line 155 def initialize(queue_size_thresholds = nil, latency_thresholds = nil, elapsed_thresholds = nil) @queue_size_thresholds = queue_size_thresholds || {} @latency_thresholds = latency_thresholds || {} @elapsed_thresholds = elapsed_thresholds || {} end |
Instance Attribute Details
#elapsed_thresholds ⇒ Object
Returns the value of attribute elapsed_thresholds.
139 140 141 |
# File 'lib/sidekiq-monitoring.rb', line 139 def elapsed_thresholds @elapsed_thresholds end |
#latency_thresholds ⇒ Object
Returns the value of attribute latency_thresholds.
139 140 141 |
# File 'lib/sidekiq-monitoring.rb', line 139 def latency_thresholds @latency_thresholds end |
#queue_size_thresholds ⇒ Object
Returns the value of attribute queue_size_thresholds.
139 140 141 |
# File 'lib/sidekiq-monitoring.rb', line 139 def queue_size_thresholds @queue_size_thresholds end |
Instance Method Details
#as_json(options = {}) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/sidekiq-monitoring.rb', line 141 def as_json( = {}) { 'global_status' => global_status, 'queues' => queues.select { |q| q.size > 0 }.sort_by(&:criticality).reverse!.map!(&:as_json), 'workers' => workers.sort_by(&:criticality).reverse!.map!(&:as_json), } end |
#global_status ⇒ Object
149 150 151 152 153 |
# File 'lib/sidekiq-monitoring.rb', line 149 def global_status queue_status = (queues.sort.last && queues.sort.last.status) || 'UNKNOWN' worker_status = (workers.sort.last && workers.sort.last.status) || 'UNKNOWN' @global_status ||= (worker_status != 'UNKNOWN' && criticality(worker_status) > criticality(queue_status)) ? worker_status : queue_status end |
#queues ⇒ Object
161 162 163 164 165 |
# File 'lib/sidekiq-monitoring.rb', line 161 def queues @queues ||= Sidekiq::Queue.all.map do |queue| Queue.new(queue.name, queue.size, queue.latency, queue_size_thresholds[queue.name], latency_thresholds[queue.name]) end end |
#workers ⇒ Object
167 168 169 170 171 172 |
# File 'lib/sidekiq-monitoring.rb', line 167 def workers @workers ||= Sidekiq::Workers.new.map do |process_id, thread_id, work| payload = work['payload'] Worker.new(process_id, payload['jid'], work['run_at'], work['queue'], payload['class'], elapsed_thresholds[work['queue']]) end end |