newrelic-sidekiq-metrics 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +73 -0
- data/LICENSE +21 -0
- data/README.md +49 -0
- data/Rakefile +9 -0
- data/lib/newrelic-sidekiq-metrics.rb +1 -0
- data/lib/newrelic_sidekiq_metrics.rb +56 -0
- data/lib/newrelic_sidekiq_metrics/middleware.rb +8 -0
- data/lib/newrelic_sidekiq_metrics/recorder.rb +24 -0
- data/lib/newrelic_sidekiq_metrics/version.rb +3 -0
- data/newrelic-sidekiq-metrics.gemspec +36 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff56e51fac9a560c1252483b241aa4a8112a1e290184b08e80cd63cdd4f96d93
|
4
|
+
data.tar.gz: 7e00e186e2714f57619ff71ec79280079c2308a4eace5bc5be68bed1521bf469
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 760a01007bedef4642cc65a91bc38f12e0c76b88e3da003c97e24c49fcd7555d158998a582c28a01340ff772c92b7e5b7a198888e5d156ceecf0785e17a15556
|
7
|
+
data.tar.gz: 2fb59a2474621dfe067ddcfc007d329aec2f9173aa3d2a488aae03f54cae16015d4353a8711f421c21c641ad590747890352a63a06da0f5c1b2b8fd25e52f73a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.6.5
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
newrelic-sidekiq-metrics (0.2.0)
|
5
|
+
newrelic_rpm (~> 6.7.0)
|
6
|
+
sidekiq (~> 6.0.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
connection_pool (2.2.2)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
jaro_winkler (1.5.4)
|
16
|
+
method_source (0.9.2)
|
17
|
+
newrelic_rpm (6.7.0.359)
|
18
|
+
parallel (1.18.0)
|
19
|
+
parser (2.6.5.0)
|
20
|
+
ast (~> 2.4.0)
|
21
|
+
pry (0.12.2)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.9.0)
|
24
|
+
rack (2.0.7)
|
25
|
+
rack-protection (2.0.7)
|
26
|
+
rack
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (13.0.0)
|
29
|
+
redis (4.1.3)
|
30
|
+
rspec (3.9.0)
|
31
|
+
rspec-core (~> 3.9.0)
|
32
|
+
rspec-expectations (~> 3.9.0)
|
33
|
+
rspec-mocks (~> 3.9.0)
|
34
|
+
rspec-core (3.9.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-expectations (3.9.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-mocks (3.9.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-support (3.9.0)
|
43
|
+
rubocop (0.76.0)
|
44
|
+
jaro_winkler (~> 1.5.1)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 2.6)
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
50
|
+
rubocop-performance (1.5.0)
|
51
|
+
rubocop (>= 0.71.0)
|
52
|
+
ruby-progressbar (1.10.1)
|
53
|
+
sidekiq (6.0.3)
|
54
|
+
connection_pool (>= 2.2.2)
|
55
|
+
rack (>= 2.0.0)
|
56
|
+
rack-protection (>= 2.0.0)
|
57
|
+
redis (>= 4.1.0)
|
58
|
+
unicode-display_width (1.6.0)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
bundler
|
65
|
+
newrelic-sidekiq-metrics!
|
66
|
+
pry
|
67
|
+
rake
|
68
|
+
rspec
|
69
|
+
rubocop
|
70
|
+
rubocop-performance
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 RenoFi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/newrelic-sidekiq-metrics.svg)](https://rubygems.org/gems/newrelic-sidekiq-metrics)
|
2
|
+
[![Build Status](https://travis-ci.org/RenoFi/newrelic-sidekiq-metrics.svg?branch=master)](https://travis-ci.org/RenoFi/newrelic-sidekiq-metrics)
|
3
|
+
|
4
|
+
# newrelic-sidekiq-metrics
|
5
|
+
|
6
|
+
Implements recording Sidekiq stats to New Relic metrics.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'newrelic-sidekiq-metrics'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Available metrics you can record are:
|
19
|
+
|
20
|
+
```
|
21
|
+
----------------------------------------------------
|
22
|
+
| Sidekiq stat name | NewRelic metric name |
|
23
|
+
----------------------------------------------------
|
24
|
+
| processed | Custom/Sidekiq/ProcessedSize |
|
25
|
+
| failed | Custom/Sidekiq/FailedSize |
|
26
|
+
| scheduled_size | Custom/Sidekiq/ScheduledSize |
|
27
|
+
| retry_size | Custom/Sidekiq/RetrySize |
|
28
|
+
| dead_size | Custom/Sidekiq/DeadSize |
|
29
|
+
| enqueued | Custom/Sidekiq/EnqueuedSize |
|
30
|
+
| processes_size | Custom/Sidekiq/ProcessesSize |
|
31
|
+
| workers_size | Custom/Sidekiq/WorkersSize |
|
32
|
+
----------------------------------------------------
|
33
|
+
```
|
34
|
+
|
35
|
+
By default only `enqueued` and `retry_size` are recorded.
|
36
|
+
|
37
|
+
You can enable more with:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
NewrelicSidekiqMetrics.use(:enqueued, :retry_size, :dead_size)
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RenoFi/newrelic-sidekiq-metrics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'newrelic_sidekiq_metrics'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'sidekiq/api'
|
2
|
+
require 'newrelic_rpm'
|
3
|
+
require 'newrelic_sidekiq_metrics/version'
|
4
|
+
require 'newrelic_sidekiq_metrics/recorder'
|
5
|
+
require 'newrelic_sidekiq_metrics/middleware'
|
6
|
+
|
7
|
+
module NewrelicSidekiqMetrics
|
8
|
+
METRIC_PREFIX = 'Custom/Sidekiq'.freeze
|
9
|
+
|
10
|
+
METRIC_MAP = {
|
11
|
+
processed: 'ProcessedSize',
|
12
|
+
failed: 'FailedSize',
|
13
|
+
scheduled_size: 'ScheduledSize',
|
14
|
+
retry_size: 'RetrySize',
|
15
|
+
dead_size: 'DeadSize',
|
16
|
+
enqueued: 'EnqueuedSize',
|
17
|
+
processes_size: 'ProcessesSize',
|
18
|
+
workers_size: 'WorkersSize',
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
DEFAULT_ENABLED_METRICS = %i[enqueued retry_size].freeze
|
22
|
+
|
23
|
+
def self.available_metrics
|
24
|
+
METRIC_MAP.keys
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.used_metrics
|
28
|
+
@used_metrics ||= DEFAULT_ENABLED_METRICS
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.use(*values)
|
32
|
+
@used_metrics = values.flatten & available_metrics
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.add_client_middleware
|
36
|
+
Sidekiq.configure_client do |config|
|
37
|
+
config.client_middleware do |chain|
|
38
|
+
chain.add NewrelicSidekiqMetrics::Middleware
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.add_server_middleware
|
44
|
+
Sidekiq.configure_server do |config|
|
45
|
+
config.client_middleware do |chain|
|
46
|
+
chain.add NewrelicSidekiqMetrics::Middleware
|
47
|
+
end
|
48
|
+
config.server_middleware do |chain|
|
49
|
+
chain.add NewrelicSidekiqMetrics::Middleware
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
NewrelicSidekiqMetrics.add_client_middleware
|
56
|
+
NewrelicSidekiqMetrics.add_server_middleware
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module NewrelicSidekiqMetrics
|
2
|
+
class Recorder
|
3
|
+
attr_reader :stats, :metrics
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@stats = Sidekiq::Stats.new
|
7
|
+
@metrics = NewrelicSidekiqMetrics.used_metrics
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
metrics.each { |m| record_metric(m) }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def record_metric(name)
|
17
|
+
NewRelic::Agent.record_metric(metric_full_name(name), stats.public_send(name))
|
18
|
+
end
|
19
|
+
|
20
|
+
def metric_full_name(name)
|
21
|
+
File.join(METRIC_PREFIX, METRIC_MAP.fetch(name))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'newrelic_sidekiq_metrics/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'newrelic-sidekiq-metrics'
|
7
|
+
spec.version = NewrelicSidekiqMetrics::VERSION
|
8
|
+
spec.authors = ['Krzysztof Knapik', 'RenoFi Engineering Team']
|
9
|
+
spec.email = ['knapo@knapo.net', 'engineering@renofi.com']
|
10
|
+
|
11
|
+
spec.summary = 'Implements recording Sidekiq stats to New Relic metrics.'
|
12
|
+
spec.homepage = 'https://github.com/RenoFi/newrelic-sidekiq-metrics'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = 'https://github.com/RenoFi/newrelic-sidekiq-metrics'
|
16
|
+
spec.metadata['source_code_uri'] = 'https://github.com/RenoFi/newrelic-sidekiq-metrics'
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(__dir__) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.required_ruby_version = '>= 2.5'
|
26
|
+
|
27
|
+
spec.add_dependency 'newrelic_rpm', '~> 6.7.0'
|
28
|
+
spec.add_dependency 'sidekiq', '~> 6.0.3'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler'
|
31
|
+
spec.add_development_dependency 'pry'
|
32
|
+
spec.add_development_dependency 'rake'
|
33
|
+
spec.add_development_dependency 'rspec'
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
spec.add_development_dependency 'rubocop-performance'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic-sidekiq-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztof Knapik
|
8
|
+
- RenoFi Engineering Team
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: newrelic_rpm
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 6.7.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 6.7.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sidekiq
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 6.0.3
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 6.0.3
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pry
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop-performance
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description:
|
127
|
+
email:
|
128
|
+
- knapo@knapo.net
|
129
|
+
- engineering@renofi.com
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rspec"
|
136
|
+
- ".rubocop.yml"
|
137
|
+
- ".ruby-version"
|
138
|
+
- ".travis.yml"
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- LICENSE
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- lib/newrelic-sidekiq-metrics.rb
|
145
|
+
- lib/newrelic_sidekiq_metrics.rb
|
146
|
+
- lib/newrelic_sidekiq_metrics/middleware.rb
|
147
|
+
- lib/newrelic_sidekiq_metrics/recorder.rb
|
148
|
+
- lib/newrelic_sidekiq_metrics/version.rb
|
149
|
+
- newrelic-sidekiq-metrics.gemspec
|
150
|
+
homepage: https://github.com/RenoFi/newrelic-sidekiq-metrics
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata:
|
154
|
+
homepage_uri: https://github.com/RenoFi/newrelic-sidekiq-metrics
|
155
|
+
source_code_uri: https://github.com/RenoFi/newrelic-sidekiq-metrics
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '2.5'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubygems_version: 3.0.6
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Implements recording Sidekiq stats to New Relic metrics.
|
175
|
+
test_files: []
|