Class: SidekiqMonitoring::Queue

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

Constant Summary collapse

DEFAULT_THRESHOLD =
[ 1_000, 2_000 ]
DEFAULT_LATENCY_THRESHOLD =
[ 300, 900 ]

Instance Attribute Summary collapse

Attributes included from StatusMixin

#status

Instance Method Summary collapse

Methods included from StatusMixin

#<=>, #criticality

Constructor Details

#initialize(name, size, latency, queue_size_thresholds = nil, latency_thresholds = nil) ⇒ Queue

Returns a new instance of Queue.



107
108
109
110
111
112
113
114
# File 'lib/sidekiq-monitoring.rb', line 107

def initialize(name, size, latency, queue_size_thresholds = nil, latency_thresholds = nil)
  @name = name
  @size = size
  @latency = latency
  @queue_size_warning_threshold, @queue_size_critical_threshold = (queue_size_thresholds ? queue_size_thresholds : DEFAULT_THRESHOLD)
  @latency_warning_threshold, @latency_critical_threshold = (latency_thresholds ? latency_thresholds : DEFAULT_LATENCY_THRESHOLD)
  @status = monitoring_status
end

Instance Attribute Details

#latencyObject

Returns the value of attribute latency.



105
106
107
# File 'lib/sidekiq-monitoring.rb', line 105

def latency
  @latency
end

#latency_critical_thresholdObject

Returns the value of attribute latency_critical_threshold.



105
106
107
# File 'lib/sidekiq-monitoring.rb', line 105

def latency_critical_threshold
  @latency_critical_threshold
end

#latency_warning_thresholdObject

Returns the value of attribute latency_warning_threshold.



105
106
107
# File 'lib/sidekiq-monitoring.rb', line 105

def latency_warning_threshold
  @latency_warning_threshold
end

#nameObject (readonly)

Returns the value of attribute name.



104
105
106
# File 'lib/sidekiq-monitoring.rb', line 104

def name
  @name
end

#queue_size_critical_thresholdObject

Returns the value of attribute queue_size_critical_threshold.



105
106
107
# File 'lib/sidekiq-monitoring.rb', line 105

def queue_size_critical_threshold
  @queue_size_critical_threshold
end

#queue_size_warning_thresholdObject

Returns the value of attribute queue_size_warning_threshold.



105
106
107
# File 'lib/sidekiq-monitoring.rb', line 105

def queue_size_warning_threshold
  @queue_size_warning_threshold
end

#sizeObject (readonly)

Returns the value of attribute size.



104
105
106
# File 'lib/sidekiq-monitoring.rb', line 104

def size
  @size
end

Instance Method Details

#as_jsonObject



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/sidekiq-monitoring.rb', line 116

def as_json
  {
    'name' => name,
    'status' => status,
    'size' => size,
    'queue_size_warning_threshold' => queue_size_warning_threshold,
    'queue_size_critical_threshold' => queue_size_critical_threshold,
    'latency' => latency,
    'latency_warning_threshold' => latency_warning_threshold,
    'latency_critical_threshold' => latency_critical_threshold
  }
end

#monitoring_statusObject



129
130
131
132
133
# File 'lib/sidekiq-monitoring.rb', line 129

def monitoring_status
  return 'CRITICAL' if size >= queue_size_critical_threshold || latency >= latency_critical_threshold
  return 'WARNING' if size >= queue_size_warning_threshold || latency >= latency_warning_threshold
  'OK'
end