sidekiq-prometheus-exporter 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b702801b2e941ccc0d6df89caa452b5cacba0d8
4
- data.tar.gz: 7cfe65f905c85d73162aedd8d0efcb94968ac56f
3
+ metadata.gz: 706d6acff0ad51c9b9ef02fe334dd52d0dd07b1c
4
+ data.tar.gz: abaaa090c2f50dd8f7be85d42c3281f9613a23de
5
5
  SHA512:
6
- metadata.gz: a41177fe1ff1fd8d051518a8e6786c6f0d581ee2d452625e90e1a3ea408c481d98528d31c1611eb76953c003c5fed044aca6d00ee323e064ec9338f8229cd983
7
- data.tar.gz: 11187a29bf07f7f63e6f3d794d9bf44fbfeeeee6cb23151ee920e4ba4c231121ec33a7567d2f9cb4d820726339f7fdd8937804013d8ef0b396a5266f582407a5
6
+ metadata.gz: '09667bd3b4668aee6453110e5bc3275302294bea3cca1e604afa23aaf3f607d9e96a4122b06809a79bdee7011e74abb070341b4072c07fba8cfe5dcc8ddd6b74'
7
+ data.tar.gz: d91010ae4fd338f8f0e2649e1533ca998f2778bf7e3a4a7506cd698e2ce4cf10a7e5d3941c6fbb76482dd3f7cf1da8fe9e5b1bbcc53e142bcac62522f09566b7
@@ -2,9 +2,10 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.2.10
5
- - 2.3.7
6
- - 2.4.4
7
- - 2.5.1
5
+ - 2.3.8
6
+ - 2.4.6
7
+ - 2.5.5
8
+ - 2.6.2
8
9
  gemfile:
9
10
  - gemfiles/sidekiq_3.3.1.gemfile
10
11
  - gemfiles/sidekiq_3.x.gemfile
@@ -13,6 +14,8 @@ gemfile:
13
14
  addons:
14
15
  code_climate:
15
16
  repo_token: $CODECLIMATE_REPO_TOKEN
17
+ notifications:
18
+ email: false
16
19
 
17
20
  cache: bundler
18
21
  before_install: gem install bundler -v 1.16.5
data/README.md CHANGED
@@ -14,22 +14,28 @@ Open [dashboard example file](/examples/sidekiq.json), then open `https://<your
14
14
 
15
15
  # Available metrics
16
16
 
17
- (starting Sidekiq `v3.3.1`)
18
-
19
- ```text
20
- sidekiq_processed_jobs_total counter The total number of processed jobs.
21
- sidekiq_failed_jobs_total counter The total number of failed jobs.
22
- sidekiq_busy_workers gauge The number of workers performing the job.
23
- sidekiq_enqueued_jobs gauge The number of enqueued jobs.
24
- sidekiq_scheduled_jobs gauge The number of jobs scheduled for a future execution.
25
- sidekiq_retry_jobs gauge The number of jobs scheduled for the next try.
26
- sidekiq_dead_jobs gauge The number of jobs being dead.
27
- sidekiq_queue_latency_seconds gauge The amount of seconds between oldest job being pushed
28
- to the queue and current time (labels: name).
29
- sidekiq_queue_max_processing_time_seconds gauge The amount of seconds between oldest job of the queue
30
- being executed and current time (labels: name).
31
- sidekiq_queue_enqueued_jobs gauge The number of enqueued jobs in the queue (labels: name).
32
- ```
17
+ *(starting Sidekiq `v3.3.1`)*
18
+
19
+ ### Standard
20
+
21
+ | Name | Type | Description |
22
+ |-------------------------------------------|---------|-------------------------|
23
+ | sidekiq_processed_jobs_total | counter | The total number of processed jobs
24
+ | sidekiq_failed_jobs_total | counter | The total number of failed jobs
25
+ | sidekiq_busy_workers | gauge | The number of workers performing the job
26
+ | sidekiq_enqueued_jobs | gauge | The number of enqueued jobs
27
+ | sidekiq_scheduled_jobs | gauge | The number of jobs scheduled for a future execution
28
+ | sidekiq_retry_jobs | gauge | The number of jobs scheduled for the next try
29
+ | sidekiq_dead_jobs | gauge | The number of jobs being dead
30
+ | sidekiq_queue_latency_seconds | gauge | The amount of seconds between oldest job being pushed to the queue and current time (labels: `name`)
31
+ | sidekiq_queue_max_processing_time_seconds | gauge | The amount of seconds between oldest job of the queue being executed and current time (labels: `name`)
32
+ | sidekiq_queue_enqueued_jobs | gauge | The number of enqueued jobs in the queue (labels: `name`)
33
+
34
+ ### [Cron](https://github.com/ondrejbartas/sidekiq-cron)
35
+
36
+ | Name | Type | Description |
37
+ |-------------------------------------------|---------|-------------------------|
38
+ | sidekiq_cron_jobs | gauge | The number of cron jobs
33
39
 
34
40
  # Installation
35
41
 
@@ -67,9 +73,9 @@ end
67
73
  run Sidekiq::Prometheus::Exporter.to_app
68
74
  ```
69
75
 
70
- use your favorite server to start it up, like this
76
+ Use your favorite server to start it up, like this
71
77
 
72
- ```
78
+ ```bash
73
79
  $ bundle exec rackup -p9292 -o0.0.0.0
74
80
  ```
75
81
 
@@ -77,9 +83,9 @@ and then `curl https://0.0.0.0:9292/metrics`
77
83
 
78
84
  # Sidekiq Web (extream)
79
85
 
80
- If you are fine, that metrics will be exposed via Sidekiq web dashboard because
81
- you have it inside your private network or only Prometheus scraper will have an
82
- access to a machine/port/etc, then add a few lines into your web `config.ru`
86
+ If you are ok with metrics being exposed via Sidekiq web dashboard because
87
+ you have it inside your private network or only Prometheus scraper will have access
88
+ to a machine/port/etc, then add a few lines into your web `config.ru`
83
89
 
84
90
  ```ruby
85
91
  require 'sidekiq/web'
@@ -90,10 +96,33 @@ Sidekiq::Web.register(Sidekiq::Prometheus::Exporter)
90
96
 
91
97
  and then `curl https://<your-sidekiq-web-uri>/metrics`
92
98
 
99
+ # Sidekiq Contribs
100
+
101
+ By default we try to detect as many as possible [sidekiq contribs](https://github.com/mperham/sidekiq/wiki/Related-Projects)
102
+ and add their metrics to the output.
103
+ But you can change this behaviour by configuring exporters setting
104
+
105
+ ```ruby
106
+ require 'sidekiq/prometheus/exporter'
107
+
108
+ # Keep the default auto-detect behaviour
109
+ Sidekiq::Prometheus::Exporter.configure do |config|
110
+ config.exporters = :auto_detect
111
+ end
112
+
113
+ # Keep only standard (by default) and cron metrics
114
+ Sidekiq::Prometheus::Exporter.configure do |config|
115
+ config.exporters = %i(cron)
116
+ end
117
+ ```
118
+
93
119
  ## Contributing
94
120
 
95
121
  Bug reports and pull requests to support earlier versions of Sidekiq are welcome on GitHub at https://github.com/Strech/sidekiq-prometheus-exporter/issues.
96
122
 
123
+ If you are missing your favourite Sidekiq contrib and want to contribute,
124
+ please make sure that you are following naming conventions from [Prometheus](https://prometheus.io/docs/practices/naming/).
125
+
97
126
  # License
98
127
 
99
128
  Please see [LICENSE](https://github.com/mperham/sidekiq/blob/master/LICENSE) for licensing details.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- sidekiq-prometheus-exporter (0.1.6)
4
+ sidekiq-prometheus-exporter (0.1.8)
5
5
  sidekiq (>= 3.3.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- sidekiq-prometheus-exporter (0.1.6)
4
+ sidekiq-prometheus-exporter (0.1.8)
5
5
  sidekiq (>= 3.3.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- sidekiq-prometheus-exporter (0.1.6)
4
+ sidekiq-prometheus-exporter (0.1.8)
5
5
  sidekiq (>= 3.3.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- sidekiq-prometheus-exporter (0.1.6)
4
+ sidekiq-prometheus-exporter (0.1.8)
5
5
  sidekiq (>= 3.3.1)
6
6
 
7
7
  GEM
@@ -1,41 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
4
3
  require 'sidekiq/prometheus/exporter/version'
5
- require 'sidekiq/prometheus/exporter/metrics'
4
+ require 'sidekiq/prometheus/exporter/exporters'
6
5
 
7
6
  module Sidekiq
8
7
  module Prometheus
9
8
  # Expose Prometheus metrics via Rack application or Sidekiq::Web application
10
9
  module Exporter
11
- HTTP_GET = 'GET'.freeze
12
- NOT_FOUND_TEXT = 'Not Found'.freeze
10
+ REQUEST_VERB = 'GET'.freeze
13
11
  REQUEST_METHOD = 'REQUEST_METHOD'.freeze
14
- HEADERS = {
15
- 'Content-Type' => 'text/plain; version=0.0.4',
16
- 'Cache-Control' => 'no-cache'
17
- }.freeze
18
- TEMPLATE = ERB.new(File.read(File.expand_path('exporter/templates/metrics.erb', __dir__)))
12
+ NOT_FOUND_TEXT = 'Not Found'.freeze
13
+ MOUNT_PATH = '/metrics'.freeze
14
+ HEADERS = {'Content-Type' => 'text/plain; version=0.0.4', 'Cache-Control' => 'no-cache'}.freeze
15
+ EXPORTERS = Exporters.new
19
16
 
20
- def self.registered(app)
21
- app.get('/metrics') do
22
- Sidekiq::Prometheus::Exporter.call(REQUEST_METHOD => HTTP_GET)
17
+ class << self
18
+ def configure
19
+ yield(EXPORTERS)
23
20
  end
24
- end
25
21
 
26
- def self.to_app
27
- Rack::Builder.app do
28
- map('/metrics') do
29
- run Sidekiq::Prometheus::Exporter
22
+ def registered(app)
23
+ app.get(MOUNT_PATH) do
24
+ Sidekiq::Prometheus::Exporter.call(REQUEST_METHOD => REQUEST_VERB)
30
25
  end
31
26
  end
32
- end
33
27
 
34
- def self.call(env)
35
- return [404, HEADERS, [NOT_FOUND_TEXT]] if env[REQUEST_METHOD] != HTTP_GET
28
+ def to_app
29
+ Rack::Builder.app do
30
+ map(MOUNT_PATH) do
31
+ run Sidekiq::Prometheus::Exporter
32
+ end
33
+ end
34
+ end
36
35
 
37
- body = TEMPLATE.result(Metrics.new.__binding__).chomp!
38
- [200, HEADERS, [body]]
36
+ def call(env)
37
+ return [404, HEADERS, [NOT_FOUND_TEXT]] if env[REQUEST_METHOD] != REQUEST_VERB
38
+
39
+ [200, HEADERS, [EXPORTERS.to_s]]
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ # Exporter for the https://github.com/ondrejbartas/sidekiq-cron
6
+ module Sidekiq
7
+ module Prometheus
8
+ module Exporter
9
+ class Cron
10
+ TEMPLATE = ERB.new(File.read(File.expand_path('templates/cron.erb', __dir__)))
11
+
12
+ def self.available?
13
+ defined?(Sidekiq::Cron)
14
+ end
15
+
16
+ def initialize
17
+ @cron_jobs_count = Sidekiq::Cron::Job.count
18
+ end
19
+
20
+ def to_s
21
+ TEMPLATE.result(binding).chomp!
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sidekiq/prometheus/exporter/standard'
4
+ require 'sidekiq/prometheus/exporter/cron'
5
+
6
+ module Sidekiq
7
+ module Prometheus
8
+ module Exporter
9
+ class Exporters
10
+ AVAILABLE_EXPORTERS = {
11
+ standard: Sidekiq::Prometheus::Exporter::Standard,
12
+ cron: Sidekiq::Prometheus::Exporter::Cron
13
+ }.freeze
14
+
15
+ def initialize
16
+ @enabled = AVAILABLE_EXPORTERS.values.select(&:available?)
17
+ end
18
+
19
+ def exporters=(value)
20
+ value = Array(value) unless value.respond_to?(:select)
21
+ potential = AVAILABLE_EXPORTERS
22
+
23
+ unless value.include?(:auto_detect)
24
+ potential = potential.select { |name, _| value.include?(name) }
25
+ end
26
+
27
+ @enabled =
28
+ %i(standard).concat(potential.keys).uniq
29
+ .map { |name| AVAILABLE_EXPORTERS.fetch(name) }
30
+ .select(&:available?)
31
+ end
32
+
33
+ def to_s
34
+ @enabled.map { |exporter| exporter.new.to_s }.join("\n".freeze)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'sidekiq/api'
5
+
6
+ module Sidekiq
7
+ module Prometheus
8
+ module Exporter
9
+ class Standard
10
+ TEMPLATE = ERB.new(File.read(File.expand_path('templates/standard.erb', __dir__)))
11
+
12
+ QueueStats = Struct.new(:name, :size, :latency)
13
+
14
+ def self.available?
15
+ true
16
+ end
17
+
18
+ def initialize
19
+ @overview_stats = Sidekiq::Stats.new
20
+ @queues_stats = queues_stats
21
+ @max_processing_times = max_processing_times
22
+ end
23
+
24
+ def to_s
25
+ TEMPLATE.result(binding).chomp!
26
+ end
27
+
28
+ private
29
+
30
+ def queues_stats
31
+ Sidekiq::Queue.all.map do |queue|
32
+ QueueStats.new(queue.name, queue.size, queue.latency)
33
+ end
34
+ end
35
+
36
+ def max_processing_times
37
+ now = Time.now.to_i
38
+ Sidekiq::Workers.new
39
+ .map { |_, _, execution| execution }
40
+ .group_by { |execution| execution['queue'] }
41
+ .each_with_object({}) do |(queue, executions), memo|
42
+ oldest_execution = executions.min_by { |execution| execution['run_at'] }
43
+ memo[queue] = now - oldest_execution['run_at']
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ # HELP sidekiq_cron_jobs The number of cron jobs.
2
+ # TYPE sidekiq_cron_jobs gauge
3
+ sidekiq_cron_jobs <%= format('%d', @cron_jobs_count) %>
@@ -3,7 +3,7 @@
3
3
  module Sidekiq
4
4
  module Prometheus
5
5
  module Exporter
6
- VERSION = '0.1.7'
6
+ VERSION = '0.1.8'.freeze
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-prometheus-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Fedorov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-04 00:00:00.000000000 Z
11
+ date: 2019-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -201,8 +201,11 @@ files:
201
201
  - gemfiles/sidekiq_5.x.gemfile
202
202
  - gemfiles/sidekiq_5.x.gemfile.lock
203
203
  - lib/sidekiq/prometheus/exporter.rb
204
- - lib/sidekiq/prometheus/exporter/metrics.rb
205
- - lib/sidekiq/prometheus/exporter/templates/metrics.erb
204
+ - lib/sidekiq/prometheus/exporter/cron.rb
205
+ - lib/sidekiq/prometheus/exporter/exporters.rb
206
+ - lib/sidekiq/prometheus/exporter/standard.rb
207
+ - lib/sidekiq/prometheus/exporter/templates/cron.erb
208
+ - lib/sidekiq/prometheus/exporter/templates/standard.erb
206
209
  - lib/sidekiq/prometheus/exporter/version.rb
207
210
  - sidekiq-prometheus-exporter.gemspec
208
211
  homepage: https://github.com/Strech/sidekiq-prometheus-exporter
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'sidekiq/api'
4
-
5
- module Sidekiq
6
- module Prometheus
7
- class Metrics
8
- QueueStats = Struct.new(:name, :size, :latency)
9
-
10
- def initialize
11
- @overview_stats = Sidekiq::Stats.new
12
- @queues_stats = queues_stats
13
- @max_processing_times = max_processing_times
14
- end
15
-
16
- def __binding__
17
- binding
18
- end
19
-
20
- private
21
-
22
- def queues_stats
23
- Sidekiq::Queue.all.map do |queue|
24
- QueueStats.new(queue.name, queue.size, queue.latency)
25
- end
26
- end
27
-
28
- def max_processing_times
29
- now = Time.now.to_i
30
- Sidekiq::Workers.new
31
- .map { |_, _, execution| execution }
32
- .group_by { |execution| execution['queue'] }
33
- .each_with_object({}) do |(queue, executions), memo|
34
- oldest_execution = executions.min_by { |execution| execution['run_at'] }
35
- memo[queue] = now - oldest_execution['run_at']
36
- end
37
- end
38
- end
39
- end
40
- end