prometheus_exporter 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -1
- data/README.md +12 -1
- data/lib/prometheus_exporter/client.rb +10 -4
- data/lib/prometheus_exporter/instrumentation/sidekiq.rb +14 -1
- data/lib/prometheus_exporter/metric/counter.rb +4 -0
- data/lib/prometheus_exporter/server/sidekiq_collector.rb +24 -5
- data/lib/prometheus_exporter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 194941c0e02ab01e7e35d9931b66d2403100eab66b7b8708b5e512a400293bb8
|
4
|
+
data.tar.gz: 4059f738ec94d58d91c676ac24da5f2d6abd006d4b38ac42ca18ba92af43ab6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1b835e597e67fbe25e3d8c61869f68e7c5d7d5dd51e6c0972508a3816dc81f3454ad7680b74245496a73e14e86ff43dc0569d50fe8488ece2637631f1f4c4cf
|
7
|
+
data.tar.gz: dcb886ecc1e568e93509fd73046cf2f498015791a41521ae567b14467ad4b2e33b93899a9145b997604bbc35916d45303e6845d31a2b284bd268bd685e4dea1e
|
data/CHANGELOG
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.6 - 02-04-2019
|
2
|
+
|
3
|
+
- Feature: Allow resetting a counter
|
4
|
+
- Feature: Add sidekiq metrics: restarted, dead jobs counters
|
5
|
+
- Fix: Client shutting down before sending metrics to collector
|
6
|
+
|
7
|
+
0.4.5 - 14-02-2019
|
2
8
|
|
3
9
|
- Feature: Allow process collector to ship custom labels for all process metrics
|
4
10
|
- Fix: Always scope process metrics on hostname in collector
|
5
11
|
|
12
|
+
0.4.4 - 13-02-2019
|
13
|
+
|
14
|
+
- Feature: add support for local metric collection without using HTTP
|
15
|
+
|
6
16
|
0.4.3 - 11-02-2019
|
7
17
|
|
8
18
|
- Feature: Add alias for Gauge #observe called #set, this makes it a bit easier to migrate from prom
|
data/README.md
CHANGED
@@ -196,7 +196,7 @@ end
|
|
196
196
|
|
197
197
|
#### Sidekiq metrics
|
198
198
|
|
199
|
-
Including Sidekiq metrics (how many jobs ran? how many failed? how long did they take?)
|
199
|
+
Including Sidekiq metrics (how many jobs ran? how many failed? how long did they take? how many are dead? how many were restarted?)
|
200
200
|
|
201
201
|
```ruby
|
202
202
|
Sidekiq.configure_server do |config|
|
@@ -204,6 +204,7 @@ Sidekiq.configure_server do |config|
|
|
204
204
|
require 'prometheus_exporter/instrumentation'
|
205
205
|
chain.add PrometheusExporter::Instrumentation::Sidekiq
|
206
206
|
end
|
207
|
+
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
|
207
208
|
end
|
208
209
|
```
|
209
210
|
|
@@ -218,6 +219,16 @@ Sidekiq.configure_server do |config|
|
|
218
219
|
end
|
219
220
|
```
|
220
221
|
|
222
|
+
Sometimes the Sidekiq server shuts down before it can send metrics, that were generated right before the shutdown, to the collector. Especially if you care about the `sidekiq_restarted_jobs_total` metric, it is a good idea to explicitly stop the client:
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
Sidekiq.configure_server do |config|
|
226
|
+
at_exit do
|
227
|
+
PrometheusExporter::Client.default.stop(wait_timeout_seconds: 10)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
```
|
231
|
+
|
221
232
|
#### Delayed Job plugin
|
222
233
|
|
223
234
|
In an initializer:
|
@@ -120,16 +120,16 @@ module PrometheusExporter
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
def stop
|
123
|
+
def stop(wait_timeout_seconds: 0)
|
124
124
|
@mutex.synchronize do
|
125
|
+
wait_for_empty_queue_with_timeout(wait_timeout_seconds)
|
125
126
|
@worker_thread&.kill
|
126
127
|
while @worker_thread.alive?
|
127
128
|
sleep 0.001
|
128
129
|
end
|
129
130
|
@worker_thread = nil
|
130
131
|
end
|
131
|
-
|
132
|
-
close_socket!
|
132
|
+
close_socket!
|
133
133
|
end
|
134
134
|
|
135
135
|
private
|
@@ -197,6 +197,13 @@ module PrometheusExporter
|
|
197
197
|
raise
|
198
198
|
end
|
199
199
|
|
200
|
+
def wait_for_empty_queue_with_timeout(timeout_seconds)
|
201
|
+
start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
202
|
+
while @queue.length > 0
|
203
|
+
break if start_time + timeout_seconds < ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
204
|
+
sleep(0.05)
|
205
|
+
end
|
206
|
+
end
|
200
207
|
end
|
201
208
|
|
202
209
|
class LocalClient < Client
|
@@ -211,5 +218,4 @@ module PrometheusExporter
|
|
211
218
|
@collector.process(json)
|
212
219
|
end
|
213
220
|
end
|
214
|
-
|
215
221
|
end
|
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
module PrometheusExporter::Instrumentation
|
4
4
|
class Sidekiq
|
5
|
+
def self.death_handler
|
6
|
+
-> (job, ex) do
|
7
|
+
PrometheusExporter::Client.default.send_json(
|
8
|
+
type: "sidekiq",
|
9
|
+
name: job["class"],
|
10
|
+
dead: true,
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
5
14
|
|
6
15
|
def initialize(client: nil)
|
7
16
|
@client = client || PrometheusExporter::Client.default
|
@@ -9,19 +18,23 @@ module PrometheusExporter::Instrumentation
|
|
9
18
|
|
10
19
|
def call(worker, msg, queue)
|
11
20
|
success = false
|
21
|
+
shutdown = false
|
12
22
|
start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
13
23
|
result = yield
|
14
24
|
success = true
|
15
25
|
result
|
26
|
+
rescue ::Sidekiq::Shutdown => e
|
27
|
+
shutdown = true
|
28
|
+
raise e
|
16
29
|
ensure
|
17
30
|
duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
|
18
31
|
class_name = worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper' ?
|
19
32
|
msg['wrapped'] : worker.class.to_s
|
20
|
-
|
21
33
|
@client.send_json(
|
22
34
|
type: "sidekiq",
|
23
35
|
name: class_name,
|
24
36
|
success: success,
|
37
|
+
shutdown: shutdown,
|
25
38
|
duration: duration
|
26
39
|
)
|
27
40
|
end
|
@@ -11,14 +11,25 @@ module PrometheusExporter::Server
|
|
11
11
|
labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
|
12
12
|
|
13
13
|
ensure_sidekiq_metrics
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if obj["dead"]
|
15
|
+
@sidekiq_dead_jobs_total.observe(1, labels)
|
16
|
+
else
|
17
|
+
@sidekiq_job_duration_seconds.observe(obj["duration"], labels)
|
18
|
+
@sidekiq_jobs_total.observe(1, labels)
|
19
|
+
@sidekiq_restarted_jobs_total.observe(1, labels) if obj["shutdown"]
|
20
|
+
@sidekiq_failed_jobs_total.observe(1, labels) if !obj["success"] && !obj["shutdown"]
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
def metrics
|
20
25
|
if @sidekiq_jobs_total
|
21
|
-
[
|
26
|
+
[
|
27
|
+
@sidekiq_job_duration_seconds,
|
28
|
+
@sidekiq_jobs_total,
|
29
|
+
@sidekiq_restarted_jobs_total,
|
30
|
+
@sidekiq_failed_jobs_total,
|
31
|
+
@sidekiq_dead_jobs_total,
|
32
|
+
]
|
22
33
|
else
|
23
34
|
[]
|
24
35
|
end
|
@@ -37,9 +48,17 @@ module PrometheusExporter::Server
|
|
37
48
|
PrometheusExporter::Metric::Counter.new(
|
38
49
|
"sidekiq_jobs_total", "Total number of sidekiq jobs executed.")
|
39
50
|
|
51
|
+
@sidekiq_restarted_jobs_total =
|
52
|
+
PrometheusExporter::Metric::Counter.new(
|
53
|
+
"sidekiq_restarted_jobs_total", "Total number of sidekiq jobs that we restarted because of a sidekiq shutdown.")
|
54
|
+
|
40
55
|
@sidekiq_failed_jobs_total =
|
41
56
|
PrometheusExporter::Metric::Counter.new(
|
42
|
-
"sidekiq_failed_jobs_total", "Total number failed sidekiq jobs
|
57
|
+
"sidekiq_failed_jobs_total", "Total number of failed sidekiq jobs.")
|
58
|
+
|
59
|
+
@sidekiq_dead_jobs_total =
|
60
|
+
PrometheusExporter::Metric::Counter.new(
|
61
|
+
"sidekiq_dead_jobs_total", "Total number of dead sidekiq jobs.")
|
43
62
|
end
|
44
63
|
end
|
45
64
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02
|
11
|
+
date: 2019-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
209
|
requirements: []
|
210
|
-
rubygems_version: 3.0.
|
210
|
+
rubygems_version: 3.0.3
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: Prometheus Exporter
|