sidekiq-statsd 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -6
- data/lib/sidekiq/statsd/server_middleware.rb +15 -2
- data/lib/sidekiq/statsd/version.rb +1 -1
- data/spec/sidekiq/statsd/server_middleware_spec.rb +5 -10
- data/spec/support/shared_examples_for_a_resilient_gauge_reporter.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d8e3354a5bc87cb290fa801fe88fd84af3c6903cc0177f80a95769b29dee43
|
4
|
+
data.tar.gz: d4be3f1f2e8d80c43ace8e07fa86daabb53b8060cccc0a0ba6f27dc992f98019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b73d03dd5d3a6cc0f3a41e06f0b5be7b065fe30f2d45198a5acba85f34caee0e1542b2ee607701df9f63cd49dd0e78289f803ec71b04f76c17ad2603349faf3b
|
7
|
+
data.tar.gz: 406fde1d9d0a9686704e31c50a66b191d81a5f5a7c6cc5986467e223c2cf6507d92979a1e4f5b5dc0b26e95853943508b024bc6c78c7891f73e754bdc52de4c0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,12 @@
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/phstc/sidekiq-statsd.png)](http://travis-ci.org/phstc/sidekiq-statsd)
|
4
4
|
[![Dependency Status](https://gemnasium.com/phstc/sidekiq-statsd.png)](https://gemnasium.com/phstc/sidekiq-statsd)
|
5
5
|
|
6
|
-
Sidekiq StatsD is a [Sidekiq server middleware](https://github.com/mperham/sidekiq/wiki/Middleware) to send
|
6
|
+
Sidekiq StatsD is a [Sidekiq server middleware](https://github.com/mperham/sidekiq/wiki/Middleware) to send Sidekiq metrics through [statsd](https://github.com/reinh/statsd):
|
7
|
+
|
8
|
+
- [global metrics](https://github.com/mperham/sidekiq/wiki/API#wiki-stats)
|
9
|
+
- [queue metrics](https://github.com/mperham/sidekiq/wiki/API#queue)
|
10
|
+
- [worker metrics](https://github.com/mperham/sidekiq/wiki/API#workers) (`processing`, `runtime`)
|
11
|
+
- job metrics (`processing_time` and `success` / `failure`)
|
7
12
|
|
8
13
|
## Compatibility
|
9
14
|
|
@@ -50,16 +55,12 @@ end
|
|
50
55
|
|
51
56
|
```ruby
|
52
57
|
# @param [Hash] options The options to initialize the StatsD client.
|
53
|
-
# @option options [Statsd] :statsd Existing statsd client to use.
|
58
|
+
# @option options [Statsd] :statsd Existing [statsd client](https://github.com/github/statsd-ruby) to use.
|
54
59
|
# @option options [String] :env ("production") The env to segment the metric key (e.g. env.prefix.worker_name.success|failure).
|
55
60
|
# @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
|
56
|
-
# @option options [String] :host ("localhost") The StatsD host.
|
57
|
-
# @option options [String] :port ("8125") The StatsD port.
|
58
61
|
# @option options [String] :sidekiq_stats ("true") Send Sidekiq global stats e.g. total enqueued, processed and failed.
|
59
62
|
```
|
60
63
|
|
61
|
-
If you have a [statsd instance](https://github.com/github/statsd-ruby) you can pass it through the `:statsd` option. If not you can pass the `:host` and `:port` to connect to statsd.
|
62
|
-
|
63
64
|
## Contributing
|
64
65
|
|
65
66
|
1. Fork it
|
@@ -41,6 +41,7 @@ module Sidekiq::Statsd
|
|
41
41
|
raise e
|
42
42
|
ensure
|
43
43
|
report_global_stats(b) if @options[:sidekiq_stats]
|
44
|
+
report_worker_stats(b) if @options[:sidekiq_stats]
|
44
45
|
report_queue_stats(b, msg['queue'])
|
45
46
|
end
|
46
47
|
end
|
@@ -63,9 +64,20 @@ module Sidekiq::Statsd
|
|
63
64
|
def report_queue_stats(statsd, queue_name)
|
64
65
|
sidekiq_queue = Sidekiq::Queue.new(queue_name)
|
65
66
|
statsd.gauge prefix('queues', queue_name, 'enqueued'), sidekiq_queue.size
|
67
|
+
statsd.gauge prefix('queues', queue_name, 'latency'), sidekiq_queue.latency
|
68
|
+
end
|
69
|
+
|
70
|
+
def report_worker_stats(statsd)
|
71
|
+
workers = Sidekiq::Workers.new.to_a.map { |_pid, _tid, work| work }
|
72
|
+
worker_groups = workers.group_by { |worker| worker['queue'] }
|
66
73
|
|
67
|
-
|
68
|
-
|
74
|
+
workers.each do |worker|
|
75
|
+
runtime = Time.now.to_i - worker['run_at']
|
76
|
+
statsd.gauge prefix('queues', worker['queue'], 'runtime'), runtime
|
77
|
+
end
|
78
|
+
|
79
|
+
worker_groups.each do |queue_name, workers|
|
80
|
+
statsd.gauge prefix('queues', queue_name, 'processing'), workers.size
|
69
81
|
end
|
70
82
|
end
|
71
83
|
|
@@ -78,3 +90,4 @@ module Sidekiq::Statsd
|
|
78
90
|
end
|
79
91
|
end # ServerMiddleware
|
80
92
|
end # Sidekiq
|
93
|
+
|
@@ -39,20 +39,15 @@ describe Sidekiq::Statsd::ServerMiddleware do
|
|
39
39
|
|
40
40
|
context 'without global sidekiq stats' do
|
41
41
|
it "doesn't initialize a Sidekiq::Stats instance" do
|
42
|
-
# Sidekiq::Stats.new
|
42
|
+
# Sidekiq::Stats.new makes redis calls
|
43
43
|
expect(Sidekiq::Stats).not_to receive(:new)
|
44
44
|
described_class.new(statsd: client, sidekiq_stats: false)
|
45
45
|
end
|
46
46
|
|
47
|
-
it "doesn't
|
48
|
-
|
49
|
-
expect(
|
50
|
-
|
51
|
-
expect(client).not_to receive(:failed)
|
52
|
-
|
53
|
-
described_class
|
54
|
-
.new(statsd: client, sidekiq_stats: false)
|
55
|
-
.call(worker, msg, queue, &clean_job)
|
47
|
+
it "doesn't initialize a Sidekiq::Workers instance" do
|
48
|
+
# Sidekiq::Workers.new makes redis calls
|
49
|
+
expect(Sidekiq::Workers).not_to receive(:new)
|
50
|
+
described_class.new(statsd: client, sidekiq_stats: false)
|
56
51
|
end
|
57
52
|
end
|
58
53
|
|
@@ -1,10 +1,16 @@
|
|
1
|
+
require 'active_support/testing/time_helpers'
|
2
|
+
|
1
3
|
shared_examples "a resilient gauge reporter" do
|
4
|
+
include ActiveSupport::Testing::TimeHelpers
|
5
|
+
|
2
6
|
let(:sidekiq_stats) { double(enqueued: 1, processed: 2, failed: 3, retry_size: 4) }
|
7
|
+
let!(:sidekiq_workers) { [["pid", "tid", { "queue" => "my_queue", "run_at" => Time.now.to_i }]] }
|
3
8
|
let(:queue_stats) { double(size: 3, latency: 4.2) }
|
4
9
|
|
5
10
|
before do
|
6
11
|
allow(Sidekiq::Stats).to receive(:new) { sidekiq_stats }
|
7
12
|
allow(Sidekiq::Queue).to receive(:new).with('mailer') { queue_stats }
|
13
|
+
allow(Sidekiq::Workers).to receive(:new) { sidekiq_workers }
|
8
14
|
end
|
9
15
|
|
10
16
|
it "gauges enqueued jobs" do
|
@@ -60,4 +66,24 @@ shared_examples "a resilient gauge reporter" do
|
|
60
66
|
|
61
67
|
middleware.call(worker, msg, queue, &job)
|
62
68
|
end
|
69
|
+
|
70
|
+
it "gauges precessing jobs" do
|
71
|
+
expect(client)
|
72
|
+
.to receive(:gauge)
|
73
|
+
.with("production.worker.queues.my_queue.processing", 1)
|
74
|
+
.once
|
75
|
+
|
76
|
+
middleware.call(worker, msg, queue, &job)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "gauges job runtime" do
|
80
|
+
travel_to 5.minutes.from_now
|
81
|
+
|
82
|
+
expect(client)
|
83
|
+
.to receive(:gauge)
|
84
|
+
.with("production.worker.queues.my_queue.runtime", 300)
|
85
|
+
.once
|
86
|
+
|
87
|
+
middleware.call(worker, msg, queue, &job)
|
88
|
+
end
|
63
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Cantero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|