delayed_job_metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/delayed_job_metrics.gemspec +35 -0
- data/lib/delayed_job_metrics.rb +11 -0
- data/lib/delayed_job_metrics/exporter.rb +276 -0
- data/lib/delayed_job_metrics/http_basic_auth.rb +16 -0
- data/lib/delayed_job_metrics/railtie.rb +20 -0
- data/lib/delayed_job_metrics/version.rb +5 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 332d11af2805bb1c0d9524fbc61321c9ca6dfbca7c521d38d34f5dfd213738dd
|
4
|
+
data.tar.gz: f734c1d1a872c5ae2bc7bef9880b226e15a273a5ed8371adb82abd0358f672c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdcc72220bd58135519a8f2ab32621b0889d5c01e85847ae09dc49c040c051bf086557b64bcb70e5c3ea81714477a058fbfaf89eab34f501247637f658fb6d24
|
7
|
+
data.tar.gz: d04ba889dfc73b739d96bf71166a0dc8bdfd26706dd7b115edba225a07c629c4d2bdfe7199ab317e3bfc0fe32eb2758deb5728532318eacf05556563ba011725
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rabbitmq_client
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.4
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
delayed_job_metrics (0.0.1)
|
5
|
+
prometheus-client (~> 2.0.0)
|
6
|
+
rack (~> 2.2.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
jaro_winkler (1.5.4)
|
14
|
+
parallel (1.19.1)
|
15
|
+
parser (2.7.1.0)
|
16
|
+
ast (~> 2.4.0)
|
17
|
+
prometheus-client (2.0.0)
|
18
|
+
rack (2.2.2)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (12.3.3)
|
21
|
+
rexml (3.2.4)
|
22
|
+
rspec (3.9.0)
|
23
|
+
rspec-core (~> 3.9.0)
|
24
|
+
rspec-expectations (~> 3.9.0)
|
25
|
+
rspec-mocks (~> 3.9.0)
|
26
|
+
rspec-core (3.9.1)
|
27
|
+
rspec-support (~> 3.9.1)
|
28
|
+
rspec-expectations (3.9.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.9.0)
|
31
|
+
rspec-mocks (3.9.1)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-support (3.9.2)
|
35
|
+
rubocop (0.81.0)
|
36
|
+
jaro_winkler (~> 1.5.1)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 2.7.0.1)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
rexml
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
43
|
+
ruby-progressbar (1.10.1)
|
44
|
+
unicode-display_width (1.7.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
delayed_job_metrics!
|
51
|
+
rake (~> 12.0)
|
52
|
+
rspec (~> 3.0)
|
53
|
+
rubocop
|
54
|
+
|
55
|
+
BUNDLED WITH
|
56
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Al-waleed Shihadeh
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# DelayedJobMetrics
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/delayed_job_metrics`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'delayed_job_metrics'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install delayed_job_metrics
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Start Rails server and start scraping metrics
|
26
|
+
|
27
|
+
```
|
28
|
+
curl -fs http://127.0.0.1:3000/metrics
|
29
|
+
```
|
30
|
+
|
31
|
+
### Enable metrics middelware
|
32
|
+
|
33
|
+
```
|
34
|
+
DELAYED_JOB_METRICS_ENABLED=true
|
35
|
+
```
|
36
|
+
|
37
|
+
### Set metrics endpoint
|
38
|
+
Add the below envrinment variable to overwrite the default endpoint
|
39
|
+
|
40
|
+
```
|
41
|
+
DELAYED_JOB_METRICS_ENNDPOINT=/my_endpoint
|
42
|
+
```
|
43
|
+
|
44
|
+
### Setup basic auth
|
45
|
+
|
46
|
+
```
|
47
|
+
HTAUTH_METRICS_USER=user
|
48
|
+
HTAUTH_METRICS_PASSWORD=secret
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/delayed_job_metrics. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/delayed_job_metrics/blob/master/CODE_OF_CONDUCT.md).
|
60
|
+
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
65
|
+
|
66
|
+
## Code of Conduct
|
67
|
+
|
68
|
+
Everyone interacting in the DelayedJobMetrics project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/delayed_job_metrics/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'delayed_job_metrics'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/delayed_job_metrics/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'delayed_job_metrics'
|
7
|
+
spec.version = DelayedJobMetrics::VERSION
|
8
|
+
spec.authors = ['Al-waleed Shihadeh']
|
9
|
+
spec.email = ['wshihadeh dot dev at gmail dot com']
|
10
|
+
|
11
|
+
spec.summary = 'Delayed Job Promtheues Metrcis'
|
12
|
+
spec.description = 'Delayed Job Promtheues Metrcis'
|
13
|
+
spec.homepage = 'https://github.com/wshihadeh/delayed_job_metrics'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'prometheus-client', '~> 2.0.0'
|
30
|
+
spec.add_dependency 'rack', '~> 2.2.2'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'delayed_job_metrics/version'
|
4
|
+
require 'prometheus/middleware/exporter'
|
5
|
+
require 'delayed_job_metrics/http_basic_auth'
|
6
|
+
require 'delayed_job_metrics/exporter'
|
7
|
+
require 'delayed_job_metrics/railtie' if defined?(Rails)
|
8
|
+
|
9
|
+
module DelayedJobMetrics
|
10
|
+
class Error < StandardError; end
|
11
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize
|
4
|
+
module DelayedJobMetrics
|
5
|
+
# :nodoc:
|
6
|
+
class Exporter < Prometheus::Middleware::Exporter
|
7
|
+
def initialize(app, options = {})
|
8
|
+
@app = app
|
9
|
+
@registry = options[:registry] || Prometheus::Client.registry
|
10
|
+
@path = options[:path] || '/metrics'
|
11
|
+
@acceptable = build_dictionary(FORMATS, FALLBACK)
|
12
|
+
|
13
|
+
init_delayed_jobs_metrics
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
if env['PATH_INFO'] == @path
|
18
|
+
if ENV['HTAUTH_METRICS_USER'] && ENV['HTAUTH_METRICS_PASSWORD']
|
19
|
+
http_auth_call(env, :expose_metrics)
|
20
|
+
else
|
21
|
+
expose_metrics(env)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def http_auth_call(env, callback)
|
29
|
+
auth = BasicAuth.new(env) do |u, p|
|
30
|
+
u == ENV['HTAUTH_METRICS_USER'] && p == ENV['HTAUTH_METRICS_PASSWORD']
|
31
|
+
end
|
32
|
+
|
33
|
+
auth.call(env, method(callback))
|
34
|
+
end
|
35
|
+
|
36
|
+
def expose_metrics(env)
|
37
|
+
format = negotiate(env, @acceptable)
|
38
|
+
format ? process_mertics_request(format) : not_acceptable(FORMATS)
|
39
|
+
end
|
40
|
+
|
41
|
+
def process_mertics_request(format)
|
42
|
+
reset_metrics
|
43
|
+
collect_metrics
|
44
|
+
respond_with(format)
|
45
|
+
end
|
46
|
+
|
47
|
+
def reset_metrics
|
48
|
+
Prometheus::Client.registry.metrics.each do |metric|
|
49
|
+
metric.values.keys.each { |key| metric.set(0, labels: key) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def collect_metrics
|
54
|
+
@dj_total_count.set(Delayed::Job.count)
|
55
|
+
@dj_total_pending_count.set(
|
56
|
+
Delayed::Job.where(attempts: 0, locked_at: nil).count
|
57
|
+
)
|
58
|
+
|
59
|
+
Delayed::Job.group(:queue, :priority, :attempts)
|
60
|
+
.count.each do |data, count|
|
61
|
+
@dj_count.set(count, labels: {
|
62
|
+
queue: data[0],
|
63
|
+
priority: data[1],
|
64
|
+
attempts: data[2]
|
65
|
+
})
|
66
|
+
next unless (data[2]).zero?
|
67
|
+
|
68
|
+
@dj_pending_count.set(count, labels: {
|
69
|
+
queue: data[0],
|
70
|
+
priority: data[1]
|
71
|
+
})
|
72
|
+
end
|
73
|
+
|
74
|
+
Delayed::Job.where.not(last_error: nil)
|
75
|
+
.where(failed_at: nil).group(
|
76
|
+
:queue,
|
77
|
+
:priority,
|
78
|
+
:attempts
|
79
|
+
).count.each do |data, count|
|
80
|
+
@dj_error_count.set(count, labels: {
|
81
|
+
queue: data[0],
|
82
|
+
priority: data[1],
|
83
|
+
attempts: data[2]
|
84
|
+
})
|
85
|
+
end
|
86
|
+
|
87
|
+
Delayed::Job.where.not(failed_at: nil)
|
88
|
+
.group(:queue,
|
89
|
+
:priority).count.each do |data, count|
|
90
|
+
@dj_failed_count.set(count, labels: {
|
91
|
+
queue: data.first,
|
92
|
+
priority: data.last
|
93
|
+
})
|
94
|
+
end
|
95
|
+
|
96
|
+
Delayed::Job.where(failed_at: nil)
|
97
|
+
.where('DATE(run_at) = DATE(?)', Time.now)
|
98
|
+
.group(:queue, :priority, :attempts).count
|
99
|
+
.each do |data, count|
|
100
|
+
@dj_to_be_executed_today_count.set(count, labels: {
|
101
|
+
queue: data[0],
|
102
|
+
priority: data[1],
|
103
|
+
attempts: data[2]
|
104
|
+
})
|
105
|
+
end
|
106
|
+
|
107
|
+
Delayed::Job.where.not(failed_at: nil)
|
108
|
+
.where('DATE(run_at) = DATE(?)', Time.now)
|
109
|
+
.group(:queue, :priority).count
|
110
|
+
.each do |data, count|
|
111
|
+
@dj_failed_today_count.set(count, labels: {
|
112
|
+
queue: data[0],
|
113
|
+
priority: data[1]
|
114
|
+
})
|
115
|
+
end
|
116
|
+
|
117
|
+
jobs_handler('failed_at is NULL').each do |data, count|
|
118
|
+
@dj_handler_count.set(count, labels: {
|
119
|
+
queue: data[0],
|
120
|
+
priority: data[1],
|
121
|
+
attempts: data[2],
|
122
|
+
handler: data[3]
|
123
|
+
})
|
124
|
+
end
|
125
|
+
|
126
|
+
jobs_handler('last_error is not NULL').each do |data, count|
|
127
|
+
@dj_handler_error_count.set(count, labels: {
|
128
|
+
queue: data[0],
|
129
|
+
priority: data[1],
|
130
|
+
attempts: data[2],
|
131
|
+
handler: data[3]
|
132
|
+
})
|
133
|
+
end
|
134
|
+
|
135
|
+
jobs_methods(false).each do |data, count|
|
136
|
+
@dj_performable_count.set(count, labels: {
|
137
|
+
queue: data[0],
|
138
|
+
priority: data[1],
|
139
|
+
attempts: data[2],
|
140
|
+
handler: data[3],
|
141
|
+
object: data[4],
|
142
|
+
method_name: data[5]
|
143
|
+
})
|
144
|
+
end
|
145
|
+
|
146
|
+
jobs_methods(true).each do |data, count|
|
147
|
+
@dj_performable_failed_count.set(count, labels: {
|
148
|
+
queue: data[0],
|
149
|
+
priority: data[1],
|
150
|
+
attempts: data[2],
|
151
|
+
handler: data[3],
|
152
|
+
object: data[4],
|
153
|
+
method_name: data[5]
|
154
|
+
})
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def jobs_handler(condition)
|
159
|
+
Delayed::Job.where(condition.to_s)
|
160
|
+
.each_with_object(Hash.new(0)) do |dj, counts|
|
161
|
+
handler = dj.handler.to_s.match(
|
162
|
+
%r{!ruby/object:([^\n]+)}
|
163
|
+
).to_a[1].to_s.gsub(/ {}/, '')
|
164
|
+
key = [dj.queue, dj.priority, dj.attempts, handler]
|
165
|
+
counts[key] += 1
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def jobs_methods(failed = false)
|
170
|
+
not_val = 'not ' if failed
|
171
|
+
Delayed::Job.where("failed_at is #{not_val}NULL")
|
172
|
+
.where("handler like '%Delayed::Performable%'")
|
173
|
+
.reduce(Hash.new(0)) do |counts, dj|
|
174
|
+
process(dj, counts)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def process(job, counts)
|
179
|
+
handler_str = job.handler.to_s
|
180
|
+
handler = handler_str.match(
|
181
|
+
%r{!ruby/object:([^\n]+)}
|
182
|
+
).to_a[1].to_s.gsub(/ {}/, '')
|
183
|
+
object = handler_str.match(
|
184
|
+
%r{(serialized_)?object: !ruby/(class '|object:)([^(\n|')]+)}
|
185
|
+
).to_a[3]
|
186
|
+
method_name = handler_str.match(/method_name: ([^\n]+)/).to_a[1]
|
187
|
+
|
188
|
+
key = [job.queue, job.priority, job.attempts,
|
189
|
+
handler, object, method_name]
|
190
|
+
|
191
|
+
counts[key] += 1
|
192
|
+
counts
|
193
|
+
end
|
194
|
+
|
195
|
+
def init_delayed_jobs_metrics
|
196
|
+
@dj_total_count = @registry.gauge(
|
197
|
+
:delayed_jobs_total_count,
|
198
|
+
docstring: 'The Delayed Jobs total count.'
|
199
|
+
)
|
200
|
+
|
201
|
+
@dj_total_pending_count = @registry.gauge(
|
202
|
+
:delayed_jobs_pending_total_count,
|
203
|
+
docstring: 'The Pending Delayed Jobs total '\
|
204
|
+
'count (Jobs with 0 attempts).'
|
205
|
+
)
|
206
|
+
|
207
|
+
@dj_count = @registry.gauge(
|
208
|
+
:delayed_jobs_queue_total_count,
|
209
|
+
docstring: 'The Delayed Jobs total count Per Queue.',
|
210
|
+
labels: %i[queue priority attempts]
|
211
|
+
)
|
212
|
+
|
213
|
+
@dj_pending_count = @registry.gauge(
|
214
|
+
:delayed_jobs_queue_pending_total_count,
|
215
|
+
docstring: 'The Pending Delayed Jobs total count Per Queue.',
|
216
|
+
labels: %i[queue priority]
|
217
|
+
)
|
218
|
+
|
219
|
+
@dj_error_count = @registry.gauge(
|
220
|
+
:delayed_jobs_queue_error_total_count,
|
221
|
+
docstring: 'The total count of delayed jobs with '\
|
222
|
+
'errors (Terminated Jobs do not count).',
|
223
|
+
labels: %i[queue priority attempts]
|
224
|
+
)
|
225
|
+
|
226
|
+
@dj_failed_count = @registry.gauge(
|
227
|
+
:delayed_jobs_queue_failed_total_count,
|
228
|
+
docstring: 'The total count of the failed delayed '\
|
229
|
+
'jobs with errors (Jobs will not be retried anymore).',
|
230
|
+
labels: %i[queue priority]
|
231
|
+
)
|
232
|
+
|
233
|
+
@dj_to_be_executed_today_count = @registry.gauge(
|
234
|
+
:delayed_jobs_to_be_executed_today_count,
|
235
|
+
docstring: 'The total count of the delayed jobs '\
|
236
|
+
'that should be executed today).',
|
237
|
+
labels: %i[queue priority attempts]
|
238
|
+
)
|
239
|
+
|
240
|
+
@dj_failed_today_count = @registry.gauge(
|
241
|
+
:delayed_jobs_failed_today_count,
|
242
|
+
docstring: 'The total count of the delayed jobs that failed today).',
|
243
|
+
labels: %i[queue priority]
|
244
|
+
)
|
245
|
+
|
246
|
+
@dj_handler_count = @registry.gauge(
|
247
|
+
:delayed_jobs_handler_count,
|
248
|
+
docstring: 'The total count of the active delayed '\
|
249
|
+
'jobs per handler class).',
|
250
|
+
labels: %i[queue priority attempts handler]
|
251
|
+
)
|
252
|
+
|
253
|
+
@dj_handler_error_count = @registry.gauge(
|
254
|
+
:delayed_jobs_handler_error_count,
|
255
|
+
docstring: 'The total count of the delayed jobs '\
|
256
|
+
'with errors per handler class).',
|
257
|
+
labels: %i[queue priority attempts handler]
|
258
|
+
)
|
259
|
+
|
260
|
+
@dj_performable_count = @registry.gauge(
|
261
|
+
:delayed_jobs_performable_count,
|
262
|
+
docstring: 'The total count of the delayed jobs '\
|
263
|
+
'for the performable actions).',
|
264
|
+
labels: %i[queue priority attempts handler object method_name]
|
265
|
+
)
|
266
|
+
|
267
|
+
@dj_performable_failed_count = @registry.gauge(
|
268
|
+
:delayed_jobs_performable_failed_count,
|
269
|
+
docstring: 'The total count of the delayed jobs '\
|
270
|
+
'for the performable actions).',
|
271
|
+
labels: %i[queue priority attempts handler object method_name]
|
272
|
+
)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
# rubocop:enable Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DelayedJobMetrics
|
4
|
+
#:nodoc:
|
5
|
+
class BasicAuth < ::Rack::Auth::Basic
|
6
|
+
def call(env, callback)
|
7
|
+
auth = ::Rack::Auth::Basic::Request.new(env)
|
8
|
+
|
9
|
+
return unauthorized unless auth.provided?
|
10
|
+
return bad_request unless auth.basic?
|
11
|
+
return callback.call(env) if valid?(auth)
|
12
|
+
|
13
|
+
unauthorized
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DelayedJobMetrics
|
4
|
+
# The Railtie triggering a setup from RAILs to make it configurable
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
if ENV.fetch('DELAYED_JOB_METRICS_ENABLED', 'false') == 'true'
|
7
|
+
initializer 'delayed_jobs_metrics.insert_middleware' do
|
8
|
+
config.delayed_jobs_metrics = ::ActiveSupport::OrderedOptions.new
|
9
|
+
config.delayed_jobs_metrics.path =
|
10
|
+
ENV.fetch('DELAYED_JOB_METRICS_ENNDPOINT', '/metrics')
|
11
|
+
|
12
|
+
config.app_middleware.insert_after(
|
13
|
+
ActionDispatch::RequestId,
|
14
|
+
DelayedJobMetrics::Exporter,
|
15
|
+
config.delayed_jobs_metrics
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: delayed_job_metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Al-waleed Shihadeh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: prometheus-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Delayed Job Promtheues Metrcis
|
84
|
+
email:
|
85
|
+
- wshihadeh dot dev at gmail dot com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".ruby-gemset"
|
93
|
+
- ".ruby-version"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- delayed_job_metrics.gemspec
|
103
|
+
- lib/delayed_job_metrics.rb
|
104
|
+
- lib/delayed_job_metrics/exporter.rb
|
105
|
+
- lib/delayed_job_metrics/http_basic_auth.rb
|
106
|
+
- lib/delayed_job_metrics/railtie.rb
|
107
|
+
- lib/delayed_job_metrics/version.rb
|
108
|
+
homepage: https://github.com/wshihadeh/delayed_job_metrics
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/wshihadeh/delayed_job_metrics
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 2.3.0
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubygems_version: 3.0.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Delayed Job Promtheues Metrcis
|
132
|
+
test_files: []
|