prometheus_exporter 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/prometheus_exporter/instrumentation.rb +1 -0
- data/lib/prometheus_exporter/instrumentation/hutch.rb +26 -0
- data/lib/prometheus_exporter/middleware.rb +5 -0
- data/lib/prometheus_exporter/server.rb +1 -0
- data/lib/prometheus_exporter/server/collector.rb +1 -0
- data/lib/prometheus_exporter/server/hutch_collector.rb +43 -0
- data/lib/prometheus_exporter/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61f6c4ee8ed7b6a57307fc9c5af44f492375ce2e4c07a8995d0877e1142f95bb
|
4
|
+
data.tar.gz: fcfe58d17d6e6ec8e2e6c0421a78426b18822483958445bec239a9c4358cb0df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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).
|
@@ -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
|
|
@@ -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
|
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.
|
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-
|
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
|