sidekiq-statsd 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/sidekiq/statsd/server_middleware.rb +24 -13
- data/lib/sidekiq/statsd/version.rb +1 -1
- data/spec/sidekiq/statsd/server_middleware_spec.rb +23 -0
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e70c72f2d9107ff88383d3e2f8a90fdddc8ec22
|
4
|
+
data.tar.gz: bf3d374265929d5955fcffd003b30f32182134da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a07e5fd441caf1440f02926a7cef1972413ad11fb68a06574e5eca8530299a74f03acc068481fb63f28df63ebb27dc5736fc627fcac343c3d70fd9ce3732083
|
7
|
+
data.tar.gz: d8120db511be1257e6f6c7f7cce380806145d93b2f0af4729ff113df2f988dae4c7a04d6b26bfe3a6c121300b2c2346b9278d6157b991a808cee94c68fdf38a3
|
data/README.md
CHANGED
@@ -45,6 +45,7 @@ end
|
|
45
45
|
# @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
|
46
46
|
# @option options [String] :host ("localhost") The StatsD host.
|
47
47
|
# @option options [String] :port ("8125") The StatsD port.
|
48
|
+
# @option options [String] :sidekiq_stats ("true") Send Sidekiq global stats e.g. total enqueued, processed and failed.
|
48
49
|
```
|
49
50
|
|
50
51
|
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.
|
@@ -16,13 +16,16 @@ module Sidekiq::Statsd
|
|
16
16
|
# @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
|
17
17
|
# @option options [String] :host ("localhost") The StatsD host.
|
18
18
|
# @option options [String] :port ("8125") The StatsD port.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
# @option options [String] :sidekiq_stats ("true") Send Sidekiq global stats e.g. total enqueued, processed and failed.
|
20
|
+
def initialize(options = {})
|
21
|
+
@options = { env: 'production',
|
22
|
+
prefix: 'worker',
|
23
|
+
host: 'localhost',
|
24
|
+
port: 8125,
|
25
|
+
sidekiq_stats: true }.merge options
|
26
|
+
|
24
27
|
@statsd = options[:statsd] || ::Statsd.new(@options[:host], @options[:port])
|
25
|
-
@sidekiq_stats = Sidekiq::Stats.new
|
28
|
+
@sidekiq_stats = Sidekiq::Stats.new if @options[:sidekiq_stats]
|
26
29
|
end
|
27
30
|
|
28
31
|
##
|
@@ -34,22 +37,30 @@ module Sidekiq::Statsd
|
|
34
37
|
def call worker, msg, queue
|
35
38
|
@statsd.batch do |b|
|
36
39
|
begin
|
37
|
-
|
40
|
+
# colon causes invalid metric names
|
41
|
+
worker_name = worker.class.name.gsub('::', '.')
|
42
|
+
|
38
43
|
b.time prefix(worker_name, 'processing_time') do
|
39
44
|
yield
|
40
45
|
end
|
46
|
+
|
41
47
|
b.increment prefix(worker_name, 'success')
|
42
48
|
rescue => e
|
43
49
|
b.increment prefix(worker_name, 'failure')
|
44
50
|
raise e
|
45
51
|
ensure
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
if @options[:sidekiq_stats]
|
53
|
+
# Queue sizes
|
54
|
+
b.gauge prefix('enqueued'), @sidekiq_stats.enqueued
|
55
|
+
if @sidekiq_stats.respond_to?(:retry_size)
|
56
|
+
# 2.6.0 doesn't have `retry_size`
|
57
|
+
b.gauge prefix('retry_set_size'), @sidekiq_stats.retry_size
|
58
|
+
end
|
49
59
|
|
50
|
-
|
51
|
-
|
52
|
-
|
60
|
+
# All-time counts
|
61
|
+
b.gauge prefix('processed'), @sidekiq_stats.processed
|
62
|
+
b.gauge prefix('failed'), @sidekiq_stats.failed
|
63
|
+
end
|
53
64
|
|
54
65
|
# Queue metrics
|
55
66
|
queue_name = msg['queue']
|
@@ -49,6 +49,29 @@ describe Sidekiq::Statsd::ServerMiddleware do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
context 'without global sidekiq stats' do
|
53
|
+
let(:sidekiq_stats) { double }
|
54
|
+
|
55
|
+
it "doesn't initialze a Sidekiq::Stats instance" do
|
56
|
+
# Sidekiq::Stats.new calls fetch_stats!, which makes redis calls
|
57
|
+
expect(described_class.new(sidekiq_stats: false).instance_variable_get(:@sidekiq_stats))
|
58
|
+
.to be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "doesn't gauge sidekiq stats" do
|
62
|
+
Sidekiq::Stats.stub(:new).and_return(sidekiq_stats)
|
63
|
+
|
64
|
+
expect(sidekiq_stats).not_to receive(:enqueued)
|
65
|
+
expect(sidekiq_stats).not_to receive(:retry_size)
|
66
|
+
expect(sidekiq_stats).not_to receive(:processed)
|
67
|
+
expect(sidekiq_stats).not_to receive(:failed)
|
68
|
+
|
69
|
+
described_class
|
70
|
+
.new(sidekiq_stats: false)
|
71
|
+
.call(worker, msg, queue, &clean_job)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
52
75
|
context "with successful execution" do
|
53
76
|
let(:job) { clean_job }
|
54
77
|
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
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: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sidekiq
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: statsd-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.1.0
|
55
55
|
description: Sidekiq StatsD is a Sidekiq server middleware to send Sidekiq worker
|
@@ -60,10 +60,10 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
64
|
-
- .pryrc
|
65
|
-
- .travis.yml
|
66
|
-
- .yardopts
|
63
|
+
- ".gitignore"
|
64
|
+
- ".pryrc"
|
65
|
+
- ".travis.yml"
|
66
|
+
- ".yardopts"
|
67
67
|
- CHANGELOG.md
|
68
68
|
- Gemfile
|
69
69
|
- Guardfile
|
@@ -88,17 +88,17 @@ require_paths:
|
|
88
88
|
- lib
|
89
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- -
|
96
|
+
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.2.5
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Sidekiq StatsD is a Sidekiq server middleware to send Sidekiq worker metrics
|