Class: SidekiqMonitoring::Global

Inherits:
Object
  • Object
show all
Includes:
StatusMixin
Defined in:
lib/sidekiq-monitoring.rb

Instance Attribute Summary collapse

Attributes included from StatusMixin

#status

Instance Method Summary collapse

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_thresholdsObject

Returns the value of attribute elapsed_thresholds.



139
140
141
# File 'lib/sidekiq-monitoring.rb', line 139

def elapsed_thresholds
  @elapsed_thresholds
end

#latency_thresholdsObject

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_thresholdsObject

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(options = {})
  {
    '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_statusObject



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

#queuesObject



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

#workersObject



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