prometheus_exporter 0.5.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +7 -1
  5. data/Appraisals +10 -0
  6. data/CHANGELOG +36 -3
  7. data/README.md +278 -5
  8. data/bin/prometheus_exporter +21 -0
  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.rb +2 -0
  13. data/lib/prometheus_exporter/client.rb +27 -3
  14. data/lib/prometheus_exporter/instrumentation.rb +2 -0
  15. data/lib/prometheus_exporter/instrumentation/active_record.rb +14 -7
  16. data/lib/prometheus_exporter/instrumentation/delayed_job.rb +3 -2
  17. data/lib/prometheus_exporter/instrumentation/method_profiler.rb +2 -1
  18. data/lib/prometheus_exporter/instrumentation/process.rb +2 -0
  19. data/lib/prometheus_exporter/instrumentation/puma.rb +16 -4
  20. data/lib/prometheus_exporter/instrumentation/resque.rb +40 -0
  21. data/lib/prometheus_exporter/instrumentation/sidekiq.rb +44 -3
  22. data/lib/prometheus_exporter/instrumentation/sidekiq_queue.rb +50 -0
  23. data/lib/prometheus_exporter/metric/base.rb +4 -0
  24. data/lib/prometheus_exporter/metric/counter.rb +4 -0
  25. data/lib/prometheus_exporter/metric/gauge.rb +4 -0
  26. data/lib/prometheus_exporter/metric/histogram.rb +6 -0
  27. data/lib/prometheus_exporter/metric/summary.rb +7 -0
  28. data/lib/prometheus_exporter/middleware.rb +40 -17
  29. data/lib/prometheus_exporter/server.rb +2 -0
  30. data/lib/prometheus_exporter/server/active_record_collector.rb +3 -1
  31. data/lib/prometheus_exporter/server/collector.rb +2 -0
  32. data/lib/prometheus_exporter/server/delayed_job_collector.rb +20 -8
  33. data/lib/prometheus_exporter/server/hutch_collector.rb +6 -0
  34. data/lib/prometheus_exporter/server/puma_collector.rb +9 -1
  35. data/lib/prometheus_exporter/server/resque_collector.rb +54 -0
  36. data/lib/prometheus_exporter/server/runner.rb +24 -2
  37. data/lib/prometheus_exporter/server/shoryuken_collector.rb +8 -0
  38. data/lib/prometheus_exporter/server/sidekiq_collector.rb +11 -2
  39. data/lib/prometheus_exporter/server/sidekiq_queue_collector.rb +46 -0
  40. data/lib/prometheus_exporter/server/web_collector.rb +7 -5
  41. data/lib/prometheus_exporter/server/web_server.rb +29 -17
  42. data/lib/prometheus_exporter/version.rb +1 -1
  43. data/prometheus_exporter.gemspec +9 -5
  44. metadata +67 -17
  45. data/.travis.yml +0 -12
@@ -4,6 +4,11 @@ module PrometheusExporter::Server
4
4
  class WebCollector < TypeCollector
5
5
  def initialize
6
6
  @metrics = {}
7
+ @http_requests_total = nil
8
+ @http_duration_seconds = nil
9
+ @http_redis_duration_seconds = nil
10
+ @http_sql_duration_seconds = nil
11
+ @http_queue_duration_seconds = nil
7
12
  end
8
13
 
9
14
  def type
@@ -51,14 +56,11 @@ module PrometheusExporter::Server
51
56
  end
52
57
 
53
58
  def observe(obj)
54
- default_labels = {
55
- controller: obj['controller'] || 'other',
56
- action: obj['action'] || 'other'
57
- }
59
+ default_labels = obj['default_labels']
58
60
  custom_labels = obj['custom_labels']
59
61
  labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
60
62
 
61
- @http_requests_total.observe(1, labels.merge(status: obj["status"]))
63
+ @http_requests_total.observe(1, labels)
62
64
 
63
65
  if timings = obj["timings"]
64
66
  @http_duration_seconds.observe(timings["total_duration"], labels)
@@ -9,9 +9,14 @@ module PrometheusExporter::Server
9
9
  class WebServer
10
10
  attr_reader :collector
11
11
 
12
- def initialize(port: , bind: nil, collector: nil, timeout: PrometheusExporter::DEFAULT_TIMEOUT, verbose: false)
13
-
14
- @verbose = verbose
12
+ def initialize(opts)
13
+ @port = opts[:port] || PrometheusExporter::DEFAULT_PORT
14
+ @bind = opts[:bind] || PrometheusExporter::DEFAULT_BIND_ADDRESS
15
+ @collector = opts[:collector] || Collector.new
16
+ @timeout = opts[:timeout] || PrometheusExporter::DEFAULT_TIMEOUT
17
+ @verbose = opts[:verbose] || false
18
+ @auth = opts[:auth]
19
+ @realm = opts[:realm] || PrometheusExporter::DEFAULT_REALM
15
20
 
16
21
  @metrics_total = PrometheusExporter::Metric::Counter.new("collector_metrics_total", "Total metrics processed by exporter web.")
17
22
 
@@ -23,33 +28,33 @@ module PrometheusExporter::Server
23
28
  @sessions_total.observe(0)
24
29
  @bad_metrics_total.observe(0)
25
30
 
26
- access_log, logger = nil
31
+ @access_log, @logger = nil
27
32
 
28
- if verbose
29
- access_log = [
33
+ if @verbose
34
+ @access_log = [
30
35
  [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
31
36
  [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
32
37
  ]
33
- logger = WEBrick::Log.new($stderr)
38
+ @logger = WEBrick::Log.new($stderr)
34
39
  else
35
- access_log = []
36
- logger = WEBrick::Log.new("/dev/null")
40
+ @access_log = []
41
+ @logger = WEBrick::Log.new("/dev/null")
37
42
  end
38
43
 
44
+ @logger.info "Using Basic Authentication via #{@auth}" if @verbose && @auth
45
+
39
46
  @server = WEBrick::HTTPServer.new(
40
- Port: port,
41
- BindAddress: bind,
42
- Logger: logger,
43
- AccessLog: access_log,
47
+ Port: @port,
48
+ BindAddress: @bind,
49
+ Logger: @logger,
50
+ AccessLog: @access_log,
44
51
  )
45
52
 
46
- @collector = collector || Collector.new
47
- @port = port
48
- @timeout = timeout
49
-
50
53
  @server.mount_proc '/' do |req, res|
51
54
  res['Content-Type'] = 'text/plain; charset=utf-8'
52
55
  if req.path == '/metrics'
56
+ authenticate(req, res) if @auth
57
+
53
58
  res.status = 200
54
59
  if req.header["accept-encoding"].to_s.include?("gzip")
55
60
  sio = StringIO.new
@@ -159,5 +164,12 @@ module PrometheusExporter::Server
159
164
  gauge
160
165
  end
161
166
 
167
+ def authenticate(req, res)
168
+ htpasswd = WEBrick::HTTPAuth::Htpasswd.new(@auth)
169
+ basic_auth = WEBrick::HTTPAuth::BasicAuth.new({ Realm: @realm, UserDB: htpasswd, Logger: @logger })
170
+
171
+ basic_auth.authenticate(req, res)
172
+ end
173
+
162
174
  end
163
175
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrometheusExporter
4
- VERSION = '0.5.1'
4
+ VERSION = '0.8.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"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "bundler", ">= 2.1.4"
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
- spec.add_development_dependency 'rubocop-discourse', '~> 1.0'
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.5.1
4
+ version: 0.8.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-02-25 00:00:00.000000000 Z
11
+ date: 2021-07-05 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,30 +42,30 @@ 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
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
61
+ version: '13.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '13.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest
57
71
  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
@@ -152,18 +166,46 @@ dependencies:
152
166
  version: '0.6'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-discourse
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">"
172
+ - !ruby/object:Gem::Version
173
+ version: '2'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">"
179
+ - !ruby/object:Gem::Version
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
155
197
  requirement: !ruby/object:Gem::Requirement
156
198
  requirements:
157
199
  - - "~>"
158
200
  - !ruby/object:Gem::Version
159
- version: '1.0'
201
+ version: 6.0.0
160
202
  type: :development
161
203
  prerelease: false
162
204
  version_requirements: !ruby/object:Gem::Requirement
163
205
  requirements:
164
206
  - - "~>"
165
207
  - !ruby/object:Gem::Version
166
- version: '1.0'
208
+ version: 6.0.0
167
209
  description: Prometheus metric collector and exporter for Ruby
168
210
  email:
169
211
  - sam.saffron@gmail.com
@@ -172,9 +214,10 @@ executables:
172
214
  extensions: []
173
215
  extra_rdoc_files: []
174
216
  files:
217
+ - ".github/workflows/ci.yml"
175
218
  - ".gitignore"
176
219
  - ".rubocop.yml"
177
- - ".travis.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_queue.rb
199
247
  - lib/prometheus_exporter/instrumentation/unicorn.rb
200
248
  - lib/prometheus_exporter/metric.rb
201
249
  - lib/prometheus_exporter/metric/base.rb
@@ -212,9 +260,11 @@ files:
212
260
  - lib/prometheus_exporter/server/hutch_collector.rb
213
261
  - lib/prometheus_exporter/server/process_collector.rb
214
262
  - lib/prometheus_exporter/server/puma_collector.rb
263
+ - lib/prometheus_exporter/server/resque_collector.rb
215
264
  - lib/prometheus_exporter/server/runner.rb
216
265
  - lib/prometheus_exporter/server/shoryuken_collector.rb
217
266
  - lib/prometheus_exporter/server/sidekiq_collector.rb
267
+ - lib/prometheus_exporter/server/sidekiq_queue_collector.rb
218
268
  - lib/prometheus_exporter/server/type_collector.rb
219
269
  - lib/prometheus_exporter/server/unicorn_collector.rb
220
270
  - lib/prometheus_exporter/server/web_collector.rb
@@ -234,15 +284,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
284
  requirements:
235
285
  - - ">="
236
286
  - !ruby/object:Gem::Version
237
- version: 2.3.0
287
+ version: 2.6.0
238
288
  required_rubygems_version: !ruby/object:Gem::Requirement
239
289
  requirements:
240
290
  - - ">="
241
291
  - !ruby/object:Gem::Version
242
292
  version: '0'
243
293
  requirements: []
244
- rubygems_version: 3.0.3
245
- signing_key:
294
+ rubygems_version: 3.1.6
295
+ signing_key:
246
296
  specification_version: 4
247
297
  summary: Prometheus Exporter
248
298
  test_files: []
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- sudo: required
2
- language: ruby
3
- dist: trusty
4
- rvm:
5
- - 2.3
6
- - 2.4
7
- - 2.5
8
- - 2.6
9
- before_install: gem install bundler -v 1.16.1
10
- before_script: sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
11
-
12
- script: bundle exec rubocop && bundle exec rake