sidekiq_queue_status 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq_queue_status/failure_rate.rb +21 -0
- data/lib/sidekiq_queue_status/metric.rb +24 -0
- data/lib/sidekiq_queue_status/middleware.rb +4 -24
- data/lib/sidekiq_queue_status/queue_latency.rb +18 -0
- data/lib/sidekiq_queue_status/railtie.rb +4 -1
- data/lib/sidekiq_queue_status/version.rb +1 -1
- data/lib/sidekiq_queue_status.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 983038f3f4671d60805223bdb2490356060e61a5
|
4
|
+
data.tar.gz: 3db19c930aa5afa3c5dea0001c876ce81aa8f02d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d4563c2520de2c560e1691004bea63985b5fedce16f5d42ab76d63cf629d1b0b4fa425ca7179580a568a1d3a8fe6fd71ce6540e6b123802ed410bc638ae81d
|
7
|
+
data.tar.gz: 1407ab64ea2393f3630275a37befe7d5a41e16b15f8c3fe88c0b0e9b672b73d0ffd642db9b04986b4654f81b77c18601740c022a1980f4ce9c7dcda6c78184d5
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SidekiqQueueStatus
|
2
|
+
class FailureRate < Metric
|
3
|
+
DEFAULT_FAILURE_RATE_PERC = 10
|
4
|
+
def monitor
|
5
|
+
calculate_failure_rate.tap do |failure_rate|
|
6
|
+
error("Failure rate above #{max_failure_rate}%") if failure_rate > max_failure_rate
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def calculate_failure_rate
|
11
|
+
stats = Sidekiq::Stats::History.new(1)
|
12
|
+
processed, failed = [stats.processed, stats.failed].map { |h| h.values.last }
|
13
|
+
val = (failed.to_f / processed.to_f) * 100.0
|
14
|
+
val > 0 ? val.to_i : 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def max_failure_rate
|
18
|
+
Metric.config['queue_failure_rate'] || DEFAULT_FAILURE_RATE_PERC
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SidekiqQueueStatus
|
2
|
+
class Metric
|
3
|
+
Result = Struct.new :latencies, :failure_rate, :errors
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :config
|
7
|
+
def all
|
8
|
+
metrics = QueueLatency.new, FailureRate.new
|
9
|
+
errors = metrics.map(&:errors).flatten
|
10
|
+
Result.new(*metrics.map(&:result), errors)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :errors, :result
|
15
|
+
def initialize
|
16
|
+
@errors = []
|
17
|
+
@result = monitor
|
18
|
+
end
|
19
|
+
|
20
|
+
def error(message)
|
21
|
+
@errors << message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,45 +2,25 @@ require 'sidekiq/api'
|
|
2
2
|
|
3
3
|
module SidekiqQueueStatus
|
4
4
|
class Middleware
|
5
|
-
DEFAULT_TRESHOLD = 30
|
6
|
-
DEFAULT_FAILURE_RATE_PERC = 10
|
7
5
|
HEADERS = {
|
8
6
|
'Content-Type' => 'application/json',
|
9
7
|
'Cache-Control' => 'no-cache'
|
10
8
|
}
|
11
9
|
|
12
|
-
def initialize(app
|
10
|
+
def initialize(app)
|
13
11
|
@app = app
|
14
|
-
@latency_treshold = Hash.new(DEFAULT_TRESHOLD).merge(configured_tresholds)
|
15
|
-
@max_failure_rate = failure_rate || DEFAULT_FAILURE_RATE_PERC
|
16
12
|
end
|
17
13
|
|
18
14
|
def call(env)
|
19
15
|
if env["PATH_INFO"] =~ %r{\A/queue-status\Z}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
errors << "Queue #{name} above threshold of #{max_latency}s" if latency > max_latency
|
24
|
-
end
|
25
|
-
failure_rate = calculate_failure_rate
|
26
|
-
errors << "Failure rate above #{@max_failure_rate}%" if failure_rate > @max_failure_rate
|
27
|
-
body = { latencies: queues, failure_percentage: failure_rate, errors: errors }.to_json
|
28
|
-
status = errors.any? ? 503 : 200
|
16
|
+
metrics = Metric.all
|
17
|
+
body = { latencies: metrics.latencies, failure_percentage: metrics.failure_rate, errors: metrics.errors }.to_json
|
18
|
+
status = metrics.errors.any? ? 503 : 200
|
29
19
|
[status, HEADERS, [body]]
|
30
20
|
else
|
31
21
|
@app.call(env)
|
32
22
|
end
|
33
23
|
end
|
34
24
|
|
35
|
-
def queues
|
36
|
-
Sidekiq::Queue.all.map { |q| [q.name, q.latency.to_i] }.to_h
|
37
|
-
end
|
38
|
-
|
39
|
-
def calculate_failure_rate
|
40
|
-
stats = Sidekiq::Stats::History.new(1)
|
41
|
-
processed, failed = [stats.processed, stats.failed].map { |h| h.values.last }
|
42
|
-
val = (failed.to_f / processed.to_f) * 100.0
|
43
|
-
val > 0 ? val.to_i : 0
|
44
|
-
end
|
45
25
|
end
|
46
26
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SidekiqQueueStatus
|
2
|
+
class QueueLatency < Metric
|
3
|
+
DEFAULT_TRESHOLD = 30
|
4
|
+
def monitor
|
5
|
+
queues_with_latency.each do |name, latency|
|
6
|
+
error("Queue #{name} above threshold of #{max_latency(name)}s") if latency > max_latency(name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def queues_with_latency
|
11
|
+
Sidekiq::Queue.all.map { |q| [q.name, q.latency.to_i] }.to_h
|
12
|
+
end
|
13
|
+
|
14
|
+
def max_latency(name)
|
15
|
+
Hash.new(DEFAULT_TRESHOLD).merge(Metric.config['queue_tresholds'])[name]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -5,7 +5,10 @@ module SidekiqQueueStatus
|
|
5
5
|
config.queue_tresholds = {}
|
6
6
|
config.queue_failure_rate = nil
|
7
7
|
initializer "sidekiq_queue_status.configure_rails_initialization" do |app|
|
8
|
-
|
8
|
+
Metric.config = {}
|
9
|
+
Metric.config['queue_tresholds'] = app.config.queue_tresholds
|
10
|
+
Metric.config['queue_failure_rate'] = app.config.queue_failure_rate
|
11
|
+
app.middleware.use SidekiqQueueStatus::Middleware
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/sidekiq_queue_status.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_queue_status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthijs Langenberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -83,7 +83,10 @@ files:
|
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
85
|
- lib/sidekiq_queue_status.rb
|
86
|
+
- lib/sidekiq_queue_status/failure_rate.rb
|
87
|
+
- lib/sidekiq_queue_status/metric.rb
|
86
88
|
- lib/sidekiq_queue_status/middleware.rb
|
89
|
+
- lib/sidekiq_queue_status/queue_latency.rb
|
87
90
|
- lib/sidekiq_queue_status/railtie.rb
|
88
91
|
- lib/sidekiq_queue_status/version.rb
|
89
92
|
- sidekiq_queue_status.gemspec
|