prometheus_exporter 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e41c3872a56ccec50aa5442ede71eb37509761e1a53c065ff3b877f8ef3732a0
4
- data.tar.gz: 921f95d6a0e28bc17b212fda81984d28327d31e364d9a8efc34718a32d2c4053
3
+ metadata.gz: 61f6c4ee8ed7b6a57307fc9c5af44f492375ce2e4c07a8995d0877e1142f95bb
4
+ data.tar.gz: fcfe58d17d6e6ec8e2e6c0421a78426b18822483958445bec239a9c4358cb0df
5
5
  SHA512:
6
- metadata.gz: e208fd0be610e8a268c0a1dcf7559b07dbdf8745bff9cedf6fb04967d132d36d324b8d76c85cad19f74ec4e623eeb356f90c624f4918d7e264839d55eebb8815
7
- data.tar.gz: e1d6287fa0ca432e59ad48be400e375f75448f539a56117f8fde8c9a32314af5ee37fdaf989229c8d1000115d802012082fc641d098426354b9eccef46622237
6
+ metadata.gz: a15eaf6626b0036228ffaccb6e8ea561cbf5d4eb9286973864a1eae473190b8375cf8a1431f307eef32f3815aad9a70bd9275c399b7daad0f77abf924dd14a2e
7
+ data.tar.gz: 7cb71d3a29cc23b709b11a9cdb0a46452c9b538b84ee6b50b6711d26fe032db6a420e8d2f3494dc4024cd70304d6a35a3af0c4814ea49c810869003672292648
data/README.md CHANGED
@@ -14,6 +14,7 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
14
14
  * [Per-process stats](#per-process-stats)
15
15
  * [Sidekiq metrics](#sidekiq-metrics)
16
16
  * [Delayed Job plugin](#delayed-job-plugin)
17
+ * [Hutch metrics](#hutch-message-processing-tracer)
17
18
  * [Puma metrics](#puma-metrics)
18
19
  * [Custom type collectors](#custom-type-collectors)
19
20
  * [Multi process mode with custom collector](#multi-process-mode-with-custom-collector)
@@ -218,6 +219,17 @@ unless Rails.env == "test"
218
219
  end
219
220
  ```
220
221
 
222
+ #### Hutch Message Processing Tracer
223
+
224
+ Capture [Hutch](https://github.com/gocardless/hutch) metrics (how many jobs ran? how many failed? how long did they take?)
225
+
226
+ ```ruby
227
+ unless Rails.env == "test"
228
+ require 'prometheus_exporter/instrumentation'
229
+ Hutch::Config.set(:tracer, PrometheusExporter::Instrumentation::Hutch)
230
+ end
231
+ ```
232
+
221
233
  #### Instrumenting Request Queueing Time
222
234
 
223
235
  Request Queueing is defined as the time it takes for a request to reach your application (instrumented by this `prometheus_exporter`) from farther upstream (as your load balancer). A high queueing time usually means that your backend cannot handle all the incoming requests in time, so they queue up (= you should see if you need to add more capacity).
@@ -4,3 +4,4 @@ require_relative "instrumentation/sidekiq"
4
4
  require_relative "instrumentation/delayed_job"
5
5
  require_relative "instrumentation/global"
6
6
  require_relative "instrumentation/puma"
7
+ require_relative "instrumentation/hutch"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrometheusExporter::Instrumentation
4
+ class Hutch
5
+ def initialize(klass)
6
+ @klass = klass
7
+ @client = PrometheusExporter::Client.default
8
+ end
9
+
10
+ def handle(message)
11
+ success = false
12
+ start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
13
+ result = @klass.process(message)
14
+ success = true
15
+ result
16
+ ensure
17
+ duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
18
+ @client.send_json(
19
+ type: "hutch",
20
+ name: @klass.class.to_s,
21
+ success: success,
22
+ duration: duration
23
+ )
24
+ end
25
+ end
26
+ end
@@ -19,6 +19,11 @@ class PrometheusExporter::Middleware
19
19
  :exec, :async_exec, :exec_prepared, :send_query_prepared, :query
20
20
  ], :sql)
21
21
  end
22
+ if defined? Mysql2::Client
23
+ MethodProfiler.patch(Mysql2::Client, [:query], :sql)
24
+ MethodProfiler.patch(Mysql2::Statement, [:execute], :sql)
25
+ MethodProfiler.patch(Mysql2::Result, [:each], :sql)
26
+ end
22
27
  end
23
28
  end
24
29
 
@@ -9,3 +9,4 @@ require_relative "server/collector"
9
9
  require_relative "server/web_server"
10
10
  require_relative "server/runner"
11
11
  require_relative "server/puma_collector"
12
+ require_relative "server/hutch_collector"
@@ -31,6 +31,7 @@ module PrometheusExporter::Server
31
31
  register_collector(SidekiqCollector.new)
32
32
  register_collector(DelayedJobCollector.new)
33
33
  register_collector(PumaCollector.new)
34
+ register_collector(HutchCollector.new)
34
35
  end
35
36
 
36
37
  def register_collector(collector)
@@ -0,0 +1,43 @@
1
+ module PrometheusExporter::Server
2
+ class HutchCollector < TypeCollector
3
+
4
+ def type
5
+ "hutch"
6
+ end
7
+
8
+ def collect(obj)
9
+ default_labels = { job_name: obj['name'] }
10
+ custom_labels = obj['custom_labels']
11
+ labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
12
+
13
+ ensure_hutch_metrics
14
+ @hutch_job_duration_seconds.observe(obj["duration"], labels)
15
+ @hutch_jobs_total.observe(1, labels)
16
+ @hutch_failed_jobs_total.observe(1, labels) if !obj["success"]
17
+ end
18
+
19
+ def metrics
20
+ if @hutch_jobs_total
21
+ [@hutch_job_duration_seconds, @hutch_jobs_total, @hutch_failed_jobs_total]
22
+ else
23
+ []
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def ensure_hutch_metrics
30
+ if !@hutch_jobs_total
31
+
32
+ @hutch_job_duration_seconds = PrometheusExporter::Metric::Counter.new(
33
+ "hutch_job_duration_seconds", "Total time spent in hutch jobs.")
34
+
35
+ @hutch_jobs_total = PrometheusExporter::Metric::Counter.new(
36
+ "hutch_jobs_total", "Total number of hutch jobs executed.")
37
+
38
+ @hutch_failed_jobs_total = PrometheusExporter::Metric::Counter.new(
39
+ "hutch_failed_jobs_total", "Total number failed hutch jobs executed.")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module PrometheusExporter
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  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: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-22 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -163,6 +163,7 @@ files:
163
163
  - lib/prometheus_exporter/instrumentation.rb
164
164
  - lib/prometheus_exporter/instrumentation/delayed_job.rb
165
165
  - lib/prometheus_exporter/instrumentation/global.rb
166
+ - lib/prometheus_exporter/instrumentation/hutch.rb
166
167
  - lib/prometheus_exporter/instrumentation/method_profiler.rb
167
168
  - lib/prometheus_exporter/instrumentation/process.rb
168
169
  - lib/prometheus_exporter/instrumentation/puma.rb
@@ -178,6 +179,7 @@ files:
178
179
  - lib/prometheus_exporter/server/collector.rb
179
180
  - lib/prometheus_exporter/server/collector_base.rb
180
181
  - lib/prometheus_exporter/server/delayed_job_collector.rb
182
+ - lib/prometheus_exporter/server/hutch_collector.rb
181
183
  - lib/prometheus_exporter/server/process_collector.rb
182
184
  - lib/prometheus_exporter/server/puma_collector.rb
183
185
  - lib/prometheus_exporter/server/runner.rb