prometheus_exporter 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +17 -4
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +5 -0
  5. data/Appraisals +10 -0
  6. data/CHANGELOG +33 -1
  7. data/README.md +115 -18
  8. data/bin/prometheus_exporter +17 -4
  9. data/gemfiles/.bundle/config +2 -0
  10. data/gemfiles/ar_60.gemfile +5 -0
  11. data/gemfiles/ar_61.gemfile +7 -0
  12. data/lib/prometheus_exporter/client.rb +16 -6
  13. data/lib/prometheus_exporter/instrumentation/active_record.rb +19 -12
  14. data/lib/prometheus_exporter/instrumentation/delayed_job.rb +3 -2
  15. data/lib/prometheus_exporter/instrumentation/method_profiler.rb +2 -1
  16. data/lib/prometheus_exporter/instrumentation/process.rb +1 -1
  17. data/lib/prometheus_exporter/instrumentation/puma.rb +28 -16
  18. data/lib/prometheus_exporter/instrumentation/resque.rb +40 -0
  19. data/lib/prometheus_exporter/instrumentation/sidekiq_process.rb +58 -0
  20. data/lib/prometheus_exporter/instrumentation/sidekiq_queue.rb +27 -13
  21. data/lib/prometheus_exporter/instrumentation/unicorn.rb +4 -4
  22. data/lib/prometheus_exporter/instrumentation.rb +2 -0
  23. data/lib/prometheus_exporter/metric/base.rb +9 -0
  24. data/lib/prometheus_exporter/metric/gauge.rb +4 -0
  25. data/lib/prometheus_exporter/middleware.rb +31 -19
  26. data/lib/prometheus_exporter/server/active_record_collector.rb +2 -1
  27. data/lib/prometheus_exporter/server/collector.rb +2 -0
  28. data/lib/prometheus_exporter/server/delayed_job_collector.rb +17 -17
  29. data/lib/prometheus_exporter/server/puma_collector.rb +16 -8
  30. data/lib/prometheus_exporter/server/resque_collector.rb +54 -0
  31. data/lib/prometheus_exporter/server/runner.rb +11 -2
  32. data/lib/prometheus_exporter/server/sidekiq_collector.rb +1 -1
  33. data/lib/prometheus_exporter/server/sidekiq_process_collector.rb +46 -0
  34. data/lib/prometheus_exporter/server/sidekiq_queue_collector.rb +1 -1
  35. data/lib/prometheus_exporter/server/unicorn_collector.rb +3 -3
  36. data/lib/prometheus_exporter/server/web_collector.rb +6 -9
  37. data/lib/prometheus_exporter/server/web_server.rb +6 -8
  38. data/lib/prometheus_exporter/server.rb +2 -0
  39. data/lib/prometheus_exporter/version.rb +1 -1
  40. data/prometheus_exporter.gemspec +7 -3
  41. metadata +62 -12
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrometheusExporter::Server
4
+ class SidekiqProcessCollector < PrometheusExporter::Server::TypeCollector
5
+ MAX_SIDEKIQ_METRIC_AGE = 60
6
+
7
+ SIDEKIQ_PROCESS_GAUGES = {
8
+ 'busy' => 'Number of running jobs',
9
+ 'concurrency' => 'Maximum concurrency',
10
+ }.freeze
11
+
12
+ attr_reader :sidekiq_metrics, :gauges
13
+
14
+ def initialize
15
+ @sidekiq_metrics = []
16
+ @gauges = {}
17
+ end
18
+
19
+ def type
20
+ 'sidekiq_process'
21
+ end
22
+
23
+ def metrics
24
+ sidekiq_metrics.map do |metric|
25
+ labels = metric.fetch('labels', {})
26
+ SIDEKIQ_PROCESS_GAUGES.map do |name, help|
27
+ if (value = metric[name])
28
+ gauge = gauges[name] ||= PrometheusExporter::Metric::Gauge.new("sidekiq_process_#{name}", help)
29
+ gauges[name].observe(value, labels)
30
+ end
31
+ end
32
+ end
33
+
34
+ gauges.values
35
+ end
36
+
37
+ def collect(object)
38
+ now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
39
+ process = object['process']
40
+
41
+ process["created_at"] = now
42
+ sidekiq_metrics.delete_if { |metric| metric['created_at'] + MAX_SIDEKIQ_METRIC_AGE < now }
43
+ sidekiq_metrics << process
44
+ end
45
+ end
46
+ end
@@ -4,7 +4,7 @@ module PrometheusExporter::Server
4
4
  MAX_SIDEKIQ_METRIC_AGE = 60
5
5
 
6
6
  SIDEKIQ_QUEUE_GAUGES = {
7
- 'backlog_total' => 'Size of the sidekiq queue.',
7
+ 'backlog' => 'Size of the sidekiq queue.',
8
8
  'latency_seconds' => 'Latency of the sidekiq queue.',
9
9
  }.freeze
10
10
 
@@ -6,9 +6,9 @@ class PrometheusExporter::Server::UnicornCollector < PrometheusExporter::Server:
6
6
  MAX_UNICORN_METRIC_AGE = 60
7
7
 
8
8
  UNICORN_GAUGES = {
9
- workers_total: 'Number of unicorn workers.',
10
- active_workers_total: 'Number of active unicorn workers',
11
- request_backlog_total: 'Number of requests waiting to be processed by a unicorn worker.'
9
+ workers: 'Number of unicorn workers.',
10
+ active_workers: 'Number of active unicorn workers',
11
+ request_backlog: 'Number of requests waiting to be processed by a unicorn worker.'
12
12
  }.freeze
13
13
 
14
14
  def initialize
@@ -33,22 +33,22 @@ module PrometheusExporter::Server
33
33
  "Total HTTP requests from web app."
34
34
  )
35
35
 
36
- @metrics["http_duration_seconds"] = @http_duration_seconds = PrometheusExporter::Metric::Summary.new(
36
+ @metrics["http_duration_seconds"] = @http_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
37
37
  "http_duration_seconds",
38
38
  "Time spent in HTTP reqs in seconds."
39
39
  )
40
40
 
41
- @metrics["http_redis_duration_seconds"] = @http_redis_duration_seconds = PrometheusExporter::Metric::Summary.new(
41
+ @metrics["http_redis_duration_seconds"] = @http_redis_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
42
42
  "http_redis_duration_seconds",
43
43
  "Time spent in HTTP reqs in Redis, in seconds."
44
44
  )
45
45
 
46
- @metrics["http_sql_duration_seconds"] = @http_sql_duration_seconds = PrometheusExporter::Metric::Summary.new(
46
+ @metrics["http_sql_duration_seconds"] = @http_sql_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
47
47
  "http_sql_duration_seconds",
48
48
  "Time spent in HTTP reqs in SQL in seconds."
49
49
  )
50
50
 
51
- @metrics["http_queue_duration_seconds"] = @http_queue_duration_seconds = PrometheusExporter::Metric::Summary.new(
51
+ @metrics["http_queue_duration_seconds"] = @http_queue_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
52
52
  "http_queue_duration_seconds",
53
53
  "Time spent queueing the request in load balancer in seconds."
54
54
  )
@@ -56,14 +56,11 @@ module PrometheusExporter::Server
56
56
  end
57
57
 
58
58
  def observe(obj)
59
- default_labels = {
60
- controller: obj['controller'] || 'other',
61
- action: obj['action'] || 'other'
62
- }
59
+ default_labels = obj['default_labels']
63
60
  custom_labels = obj['custom_labels']
64
61
  labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
65
62
 
66
- @http_requests_total.observe(1, labels.merge(status: obj["status"]))
63
+ @http_requests_total.observe(1, labels)
67
64
 
68
65
  if timings = obj["timings"]
69
66
  @http_duration_seconds.observe(timings["total_duration"], labels)
@@ -29,16 +29,17 @@ module PrometheusExporter::Server
29
29
  @bad_metrics_total.observe(0)
30
30
 
31
31
  @access_log, @logger = nil
32
+ log_target = opts[:log_target]
32
33
 
33
34
  if @verbose
34
35
  @access_log = [
35
36
  [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
36
37
  [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
37
38
  ]
38
- @logger = WEBrick::Log.new($stderr)
39
+ @logger = WEBrick::Log.new(log_target || $stderr)
39
40
  else
40
41
  @access_log = []
41
- @logger = WEBrick::Log.new("/dev/null")
42
+ @logger = WEBrick::Log.new(log_target || "/dev/null")
42
43
  end
43
44
 
44
45
  @logger.info "Using Basic Authentication via #{@auth}" if @verbose && @auth
@@ -87,10 +88,7 @@ module PrometheusExporter::Server
87
88
  @collector.process(block)
88
89
  rescue => e
89
90
  if @verbose
90
- STDERR.puts
91
- STDERR.puts e.inspect
92
- STDERR.puts e.backtrace
93
- STDERR.puts
91
+ @logger.error "\n\n#{e.inspect}\n#{e.backtrace}\n\n"
94
92
  end
95
93
  @bad_metrics_total.observe
96
94
  res.body = "Bad Metrics #{e}"
@@ -108,7 +106,7 @@ module PrometheusExporter::Server
108
106
  begin
109
107
  @server.start
110
108
  rescue => e
111
- STDERR.puts "Failed to start prometheus collector web on port #{@port}: #{e}"
109
+ @logger.error "Failed to start prometheus collector web on port #{@port}: #{e}"
112
110
  end
113
111
  end
114
112
  end
@@ -125,7 +123,7 @@ module PrometheusExporter::Server
125
123
  end
126
124
  rescue Timeout::Error
127
125
  # we timed out ... bummer
128
- STDERR.puts "Generating Prometheus metrics text timed out"
126
+ @logger.error "Generating Prometheus metrics text timed out"
129
127
  end
130
128
 
131
129
  metrics = []
@@ -6,6 +6,7 @@ require_relative "server/web_collector"
6
6
  require_relative "server/process_collector"
7
7
  require_relative "server/sidekiq_collector"
8
8
  require_relative "server/sidekiq_queue_collector"
9
+ require_relative "server/sidekiq_process_collector"
9
10
  require_relative "server/delayed_job_collector"
10
11
  require_relative "server/collector_base"
11
12
  require_relative "server/collector"
@@ -16,3 +17,4 @@ require_relative "server/hutch_collector"
16
17
  require_relative "server/unicorn_collector"
17
18
  require_relative "server/active_record_collector"
18
19
  require_relative "server/shoryuken_collector"
20
+ require_relative "server/resque_collector"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrometheusExporter
4
- VERSION = '0.6.0'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -24,19 +24,23 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = ["prometheus_exporter"]
25
25
  spec.require_paths = ["lib"]
26
26
 
27
+ spec.add_dependency "webrick"
28
+
27
29
  spec.add_development_dependency "rubocop", ">= 0.69"
28
- spec.add_development_dependency "bundler", "> 1.16"
30
+ spec.add_development_dependency "bundler", ">= 2.1.4"
29
31
  spec.add_development_dependency "rake", "~> 13.0"
30
32
  spec.add_development_dependency "minitest", "~> 5.0"
31
33
  spec.add_development_dependency "guard", "~> 2.0"
32
- spec.add_development_dependency "mini_racer", "~> 0.1"
34
+ spec.add_development_dependency "mini_racer", "~> 0.3.1"
33
35
  spec.add_development_dependency "guard-minitest", "~> 2.0"
34
36
  spec.add_development_dependency "oj", "~> 3.0"
35
37
  spec.add_development_dependency "rack-test", "~> 0.8.3"
36
38
  spec.add_development_dependency "minitest-stub-const", "~> 0.6"
37
39
  spec.add_development_dependency "rubocop-discourse", ">2"
40
+ spec.add_development_dependency "appraisal", "~> 2.3"
41
+ spec.add_development_dependency "activerecord", "~> 6.0.0"
38
42
  if !RUBY_ENGINE == 'jruby'
39
43
  spec.add_development_dependency "raindrops", "~> 0.19"
40
44
  end
41
- spec.required_ruby_version = '>= 2.3.0'
45
+ spec.required_ruby_version = '>= 2.6.0'
42
46
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webrick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -28,16 +42,16 @@ dependencies:
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '1.16'
47
+ version: 2.1.4
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '1.16'
54
+ version: 2.1.4
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.1'
103
+ version: 0.3.1
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.1'
110
+ version: 0.3.1
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: guard-minitest
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,34 @@ dependencies:
164
178
  - - ">"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '2'
181
+ - !ruby/object:Gem::Dependency
182
+ name: appraisal
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '2.3'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '2.3'
195
+ - !ruby/object:Gem::Dependency
196
+ name: activerecord
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 6.0.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 6.0.0
167
209
  description: Prometheus metric collector and exporter for Ruby
168
210
  email:
169
211
  - sam.saffron@gmail.com
@@ -175,6 +217,7 @@ files:
175
217
  - ".github/workflows/ci.yml"
176
218
  - ".gitignore"
177
219
  - ".rubocop.yml"
220
+ - Appraisals
178
221
  - CHANGELOG
179
222
  - CODE_OF_CONDUCT.md
180
223
  - Gemfile
@@ -185,6 +228,9 @@ files:
185
228
  - bench/bench.rb
186
229
  - bin/prometheus_exporter
187
230
  - examples/custom_collector.rb
231
+ - gemfiles/.bundle/config
232
+ - gemfiles/ar_60.gemfile
233
+ - gemfiles/ar_61.gemfile
188
234
  - lib/prometheus_exporter.rb
189
235
  - lib/prometheus_exporter/client.rb
190
236
  - lib/prometheus_exporter/instrumentation.rb
@@ -194,8 +240,10 @@ files:
194
240
  - lib/prometheus_exporter/instrumentation/method_profiler.rb
195
241
  - lib/prometheus_exporter/instrumentation/process.rb
196
242
  - lib/prometheus_exporter/instrumentation/puma.rb
243
+ - lib/prometheus_exporter/instrumentation/resque.rb
197
244
  - lib/prometheus_exporter/instrumentation/shoryuken.rb
198
245
  - lib/prometheus_exporter/instrumentation/sidekiq.rb
246
+ - lib/prometheus_exporter/instrumentation/sidekiq_process.rb
199
247
  - lib/prometheus_exporter/instrumentation/sidekiq_queue.rb
200
248
  - lib/prometheus_exporter/instrumentation/unicorn.rb
201
249
  - lib/prometheus_exporter/metric.rb
@@ -213,9 +261,11 @@ files:
213
261
  - lib/prometheus_exporter/server/hutch_collector.rb
214
262
  - lib/prometheus_exporter/server/process_collector.rb
215
263
  - lib/prometheus_exporter/server/puma_collector.rb
264
+ - lib/prometheus_exporter/server/resque_collector.rb
216
265
  - lib/prometheus_exporter/server/runner.rb
217
266
  - lib/prometheus_exporter/server/shoryuken_collector.rb
218
267
  - lib/prometheus_exporter/server/sidekiq_collector.rb
268
+ - lib/prometheus_exporter/server/sidekiq_process_collector.rb
219
269
  - lib/prometheus_exporter/server/sidekiq_queue_collector.rb
220
270
  - lib/prometheus_exporter/server/type_collector.rb
221
271
  - lib/prometheus_exporter/server/unicorn_collector.rb
@@ -236,15 +286,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
286
  requirements:
237
287
  - - ">="
238
288
  - !ruby/object:Gem::Version
239
- version: 2.3.0
289
+ version: 2.6.0
240
290
  required_rubygems_version: !ruby/object:Gem::Requirement
241
291
  requirements:
242
292
  - - ">="
243
293
  - !ruby/object:Gem::Version
244
294
  version: '0'
245
295
  requirements: []
246
- rubygems_version: 3.0.3
247
- signing_key:
296
+ rubygems_version: 3.1.6
297
+ signing_key:
248
298
  specification_version: 4
249
299
  summary: Prometheus Exporter
250
300
  test_files: []