prometheus_exporter 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +4 -1
  3. data/.streerc +2 -0
  4. data/CHANGELOG +5 -0
  5. data/README.md +9 -7
  6. data/bench/bench.rb +12 -11
  7. data/examples/custom_collector.rb +1 -3
  8. data/lib/prometheus_exporter/client.rb +16 -32
  9. data/lib/prometheus_exporter/instrumentation/active_record.rb +20 -8
  10. data/lib/prometheus_exporter/instrumentation/delayed_job.rb +20 -11
  11. data/lib/prometheus_exporter/instrumentation/good_job.rb +2 -4
  12. data/lib/prometheus_exporter/instrumentation/hutch.rb +1 -1
  13. data/lib/prometheus_exporter/instrumentation/method_profiler.rb +12 -12
  14. data/lib/prometheus_exporter/instrumentation/periodic_stats.rb +13 -21
  15. data/lib/prometheus_exporter/instrumentation/process.rb +12 -6
  16. data/lib/prometheus_exporter/instrumentation/puma.rb +1 -1
  17. data/lib/prometheus_exporter/instrumentation/resque.rb +1 -3
  18. data/lib/prometheus_exporter/instrumentation/shoryuken.rb +6 -7
  19. data/lib/prometheus_exporter/instrumentation/sidekiq.rb +4 -6
  20. data/lib/prometheus_exporter/instrumentation/sidekiq_process.rb +12 -19
  21. data/lib/prometheus_exporter/instrumentation/sidekiq_queue.rb +15 -18
  22. data/lib/prometheus_exporter/instrumentation/sidekiq_stats.rb +10 -15
  23. data/lib/prometheus_exporter/instrumentation/unicorn.rb +2 -2
  24. data/lib/prometheus_exporter/metric/base.rb +8 -7
  25. data/lib/prometheus_exporter/metric/counter.rb +1 -3
  26. data/lib/prometheus_exporter/metric/gauge.rb +2 -6
  27. data/lib/prometheus_exporter/metric/histogram.rb +0 -2
  28. data/lib/prometheus_exporter/metric/summary.rb +5 -14
  29. data/lib/prometheus_exporter/middleware.rb +40 -32
  30. data/lib/prometheus_exporter/server/active_record_collector.rb +11 -6
  31. data/lib/prometheus_exporter/server/collector.rb +12 -16
  32. data/lib/prometheus_exporter/server/collector_base.rb +0 -2
  33. data/lib/prometheus_exporter/server/delayed_job_collector.rb +65 -28
  34. data/lib/prometheus_exporter/server/good_job_collector.rb +1 -1
  35. data/lib/prometheus_exporter/server/hutch_collector.rb +19 -11
  36. data/lib/prometheus_exporter/server/metrics_container.rb +4 -4
  37. data/lib/prometheus_exporter/server/process_collector.rb +7 -5
  38. data/lib/prometheus_exporter/server/puma_collector.rb +4 -10
  39. data/lib/prometheus_exporter/server/resque_collector.rb +1 -1
  40. data/lib/prometheus_exporter/server/runner.rb +34 -13
  41. data/lib/prometheus_exporter/server/shoryuken_collector.rb +22 -17
  42. data/lib/prometheus_exporter/server/sidekiq_collector.rb +22 -14
  43. data/lib/prometheus_exporter/server/sidekiq_process_collector.rb +9 -5
  44. data/lib/prometheus_exporter/server/sidekiq_queue_collector.rb +7 -6
  45. data/lib/prometheus_exporter/server/sidekiq_stats_collector.rb +12 -11
  46. data/lib/prometheus_exporter/server/unicorn_collector.rb +4 -4
  47. data/lib/prometheus_exporter/server/web_collector.rb +39 -22
  48. data/lib/prometheus_exporter/server/web_server.rb +10 -20
  49. data/lib/prometheus_exporter/version.rb +1 -1
  50. data/prometheus_exporter.gemspec +16 -18
  51. metadata +31 -2
@@ -9,6 +9,7 @@ module PrometheusExporter::Server
9
9
  @http_request_redis_duration_seconds = nil
10
10
  @http_request_sql_duration_seconds = nil
11
11
  @http_request_queue_duration_seconds = nil
12
+ @http_request_memcache_duration_seconds = nil
12
13
  end
13
14
 
14
15
  def type
@@ -28,36 +29,49 @@ module PrometheusExporter::Server
28
29
 
29
30
  def ensure_metrics
30
31
  unless @http_requests_total
31
- @metrics["http_requests_total"] = @http_requests_total = PrometheusExporter::Metric::Counter.new(
32
- "http_requests_total",
33
- "Total HTTP requests from web app."
34
- )
32
+ @metrics["http_requests_total"] = @http_requests_total =
33
+ PrometheusExporter::Metric::Counter.new(
34
+ "http_requests_total",
35
+ "Total HTTP requests from web app.",
36
+ )
35
37
 
36
- @metrics["http_request_duration_seconds"] = @http_request_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
37
- "http_request_duration_seconds",
38
- "Time spent in HTTP reqs in seconds."
39
- )
38
+ @metrics["http_request_duration_seconds"] = @http_request_duration_seconds =
39
+ PrometheusExporter::Metric::Base.default_aggregation.new(
40
+ "http_request_duration_seconds",
41
+ "Time spent in HTTP reqs in seconds.",
42
+ )
40
43
 
41
- @metrics["http_request_redis_duration_seconds"] = @http_request_redis_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
42
- "http_request_redis_duration_seconds",
43
- "Time spent in HTTP reqs in Redis, in seconds."
44
- )
44
+ @metrics["http_request_redis_duration_seconds"] = @http_request_redis_duration_seconds =
45
+ PrometheusExporter::Metric::Base.default_aggregation.new(
46
+ "http_request_redis_duration_seconds",
47
+ "Time spent in HTTP reqs in Redis, in seconds.",
48
+ )
45
49
 
46
- @metrics["http_request_sql_duration_seconds"] = @http_request_sql_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
47
- "http_request_sql_duration_seconds",
48
- "Time spent in HTTP reqs in SQL in seconds."
49
- )
50
+ @metrics["http_request_sql_duration_seconds"] = @http_request_sql_duration_seconds =
51
+ PrometheusExporter::Metric::Base.default_aggregation.new(
52
+ "http_request_sql_duration_seconds",
53
+ "Time spent in HTTP reqs in SQL in seconds.",
54
+ )
50
55
 
51
- @metrics["http_request_queue_duration_seconds"] = @http_request_queue_duration_seconds = PrometheusExporter::Metric::Base.default_aggregation.new(
52
- "http_request_queue_duration_seconds",
53
- "Time spent queueing the request in load balancer in seconds."
54
- )
56
+ @metrics[
57
+ "http_request_memcache_duration_seconds"
58
+ ] = @http_request_memcache_duration_seconds =
59
+ PrometheusExporter::Metric::Base.default_aggregation.new(
60
+ "http_request_memcache_duration_seconds",
61
+ "Time spent in HTTP reqs in Memcache in seconds.",
62
+ )
63
+
64
+ @metrics["http_request_queue_duration_seconds"] = @http_request_queue_duration_seconds =
65
+ PrometheusExporter::Metric::Base.default_aggregation.new(
66
+ "http_request_queue_duration_seconds",
67
+ "Time spent queueing the request in load balancer in seconds.",
68
+ )
55
69
  end
56
70
  end
57
71
 
58
72
  def observe(obj)
59
- default_labels = obj['default_labels']
60
- custom_labels = obj['custom_labels']
73
+ default_labels = obj["default_labels"]
74
+ custom_labels = obj["custom_labels"]
61
75
  labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
62
76
 
63
77
  @http_requests_total.observe(1, labels.merge("status" => obj["status"]))
@@ -70,6 +84,9 @@ module PrometheusExporter::Server
70
84
  if sql = timings["sql"]
71
85
  @http_request_sql_duration_seconds.observe(sql["duration"], labels)
72
86
  end
87
+ if memcache = timings["memcache"]
88
+ @http_request_memcache_duration_seconds.observe(memcache["duration"], labels)
89
+ end
73
90
  end
74
91
  if queue_time = obj["queue_time"]
75
92
  @http_request_queue_duration_seconds.observe(queue_time, labels)
@@ -21,19 +21,19 @@ module PrometheusExporter::Server
21
21
  @metrics_total =
22
22
  PrometheusExporter::Metric::Counter.new(
23
23
  "collector_metrics_total",
24
- "Total metrics processed by exporter web."
24
+ "Total metrics processed by exporter web.",
25
25
  )
26
26
 
27
27
  @sessions_total =
28
28
  PrometheusExporter::Metric::Counter.new(
29
29
  "collector_sessions_total",
30
- "Total send_metric sessions processed by exporter web."
30
+ "Total send_metric sessions processed by exporter web.",
31
31
  )
32
32
 
33
33
  @bad_metrics_total =
34
34
  PrometheusExporter::Metric::Counter.new(
35
35
  "collector_bad_metrics_total",
36
- "Total mis-handled metrics by collector."
36
+ "Total mis-handled metrics by collector.",
37
37
  )
38
38
 
39
39
  @metrics_total.observe(0)
@@ -46,7 +46,7 @@ module PrometheusExporter::Server
46
46
  if @verbose
47
47
  @access_log = [
48
48
  [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
49
- [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT]
49
+ [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
50
50
  ]
51
51
  @logger = WEBrick::Log.new(log_target || $stderr)
52
52
  else
@@ -54,9 +54,7 @@ module PrometheusExporter::Server
54
54
  @logger = WEBrick::Log.new(log_target || "/dev/null")
55
55
  end
56
56
 
57
- if @verbose && @auth
58
- @logger.info "Using Basic Authentication via #{@auth}"
59
- end
57
+ @logger.info "Using Basic Authentication via #{@auth}" if @verbose && @auth
60
58
 
61
59
  if %w[ALL ANY].include?(@bind)
62
60
  @logger.info "Listening on both 0.0.0.0/:: network interfaces"
@@ -68,7 +66,7 @@ module PrometheusExporter::Server
68
66
  Port: @port,
69
67
  BindAddress: @bind,
70
68
  Logger: @logger,
71
- AccessLog: @access_log
69
+ AccessLog: @access_log,
72
70
  )
73
71
 
74
72
  @server.mount_proc "/" do |req, res|
@@ -140,9 +138,7 @@ module PrometheusExporter::Server
140
138
  def metrics
141
139
  metric_text = nil
142
140
  begin
143
- Timeout.timeout(@timeout) do
144
- metric_text = @collector.prometheus_metrics_text
145
- end
141
+ Timeout.timeout(@timeout) { metric_text = @collector.prometheus_metrics_text }
146
142
  rescue Timeout::Error
147
143
  # we timed out ... bummer
148
144
  @logger.error "Generating Prometheus metrics text timed out"
@@ -153,14 +149,10 @@ module PrometheusExporter::Server
153
149
  metrics << add_gauge(
154
150
  "collector_working",
155
151
  "Is the master process collector able to collect metrics",
156
- metric_text && metric_text.length > 0 ? 1 : 0
152
+ metric_text && metric_text.length > 0 ? 1 : 0,
157
153
  )
158
154
 
159
- metrics << add_gauge(
160
- "collector_rss",
161
- "total memory used by collector process",
162
- get_rss
163
- )
155
+ metrics << add_gauge("collector_rss", "total memory used by collector process", get_rss)
164
156
 
165
157
  metrics << @metrics_total
166
158
  metrics << @sessions_total
@@ -196,9 +188,7 @@ module PrometheusExporter::Server
196
188
  def authenticate(req, res)
197
189
  htpasswd = WEBrick::HTTPAuth::Htpasswd.new(@auth)
198
190
  basic_auth =
199
- WEBrick::HTTPAuth::BasicAuth.new(
200
- { Realm: @realm, UserDB: htpasswd, Logger: @logger }
201
- )
191
+ WEBrick::HTTPAuth::BasicAuth.new({ Realm: @realm, UserDB: htpasswd, Logger: @logger })
202
192
 
203
193
  basic_auth.authenticate(req, res)
204
194
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrometheusExporter
4
- VERSION = "2.1.1"
4
+ VERSION = "2.2.0"
5
5
  end
@@ -5,22 +5,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "prometheus_exporter/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "prometheus_exporter"
9
- spec.version = PrometheusExporter::VERSION
10
- spec.authors = ["Sam Saffron"]
11
- spec.email = ["sam.saffron@gmail.com"]
8
+ spec.name = "prometheus_exporter"
9
+ spec.version = PrometheusExporter::VERSION
10
+ spec.authors = ["Sam Saffron"]
11
+ spec.email = ["sam.saffron@gmail.com"]
12
12
 
13
- spec.summary = %q{Prometheus Exporter}
14
- spec.description = %q{Prometheus metric collector and exporter for Ruby}
15
- spec.homepage = "https://github.com/discourse/prometheus_exporter"
16
- spec.license = "MIT"
13
+ spec.summary = "Prometheus Exporter"
14
+ spec.description = "Prometheus metric collector and exporter for Ruby"
15
+ spec.homepage = "https://github.com/discourse/prometheus_exporter"
16
+ spec.license = "MIT"
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
- f.match(%r{^(test|spec|features|bin)/})
20
- end
21
- spec.bindir = "bin"
22
- spec.executables = ["prometheus_exporter"]
23
- spec.require_paths = ["lib"]
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
19
+ spec.bindir = "bin"
20
+ spec.executables = ["prometheus_exporter"]
21
+ spec.require_paths = ["lib"]
24
22
 
25
23
  spec.add_dependency "webrick"
26
24
 
@@ -39,8 +37,8 @@ Gem::Specification.new do |spec|
39
37
  spec.add_development_dependency "activerecord", "~> 6.0.0"
40
38
  spec.add_development_dependency "redis", "> 5"
41
39
  spec.add_development_dependency "m"
42
- if !RUBY_ENGINE == 'jruby'
43
- spec.add_development_dependency "raindrops", "~> 0.19"
44
- end
45
- spec.required_ruby_version = '>= 3.0.0'
40
+ spec.add_development_dependency "syntax_tree"
41
+ spec.add_development_dependency "syntax_tree-disable_ternary"
42
+ spec.add_development_dependency "raindrops", "~> 0.19" if !RUBY_ENGINE == "jruby"
43
+ spec.required_ruby_version = ">= 3.0.0"
46
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webrick
@@ -234,6 +234,34 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: syntax_tree
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: syntax_tree-disable_ternary
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
237
265
  description: Prometheus metric collector and exporter for Ruby
238
266
  email:
239
267
  - sam.saffron@gmail.com
@@ -246,6 +274,7 @@ files:
246
274
  - ".gitignore"
247
275
  - ".rubocop"
248
276
  - ".rubocop.yml"
277
+ - ".streerc"
249
278
  - Appraisals
250
279
  - CHANGELOG
251
280
  - CODE_OF_CONDUCT.md