sidekiq_prometheus 0.9.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +51 -0
- data/README.md +31 -12
- data/lib/sidekiq_prometheus.rb +29 -11
- data/lib/sidekiq_prometheus/job_metrics.rb +12 -7
- data/lib/sidekiq_prometheus/metrics.rb +32 -17
- data/lib/sidekiq_prometheus/periodic_metrics.rb +10 -10
- data/lib/sidekiq_prometheus/version.rb +1 -1
- data/sidekiq_prometheus.gemspec +3 -3
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93a2d8b5cbc5f31163889e382d144bdc328a9c9aae03be27587575f59e811d14
|
4
|
+
data.tar.gz: d5570e6a8164ce9245f02db0962211d26dc54ae9194db204c4f448ba71984040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19985d0d0bdefb543223d6da1020c504d0ca903a9c227fda38ed31e36238e1f19a6d5d5e0044c4090fe0e65816616cb0f70c3f52d69364dc4cba9b143efccc14
|
7
|
+
data.tar.gz: 2ec3230d70cdc40939b1371b2ac1c0c14cc7c4a20741d8f9690217d2eb19a8e15be0be85c06ae66051c06ba3916e2b4a88c3b8672acddfcdedd1a444a93d68af
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,56 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
|
3
|
+
<a name="v1.3.0"></a>
|
4
|
+
## [v1.3.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.2.0...v1.3.0) (2021-03-26)
|
5
|
+
|
6
|
+
### Pull Requests
|
7
|
+
|
8
|
+
* Merge pull request [#22](https://github.com/fastly/sidekiq-prometheus/issues/22) from mirubiri/add-active-job-support
|
9
|
+
* Merge pull request [#20](https://github.com/fastly/sidekiq-prometheus/issues/20) from fastly/aw/move-to-main
|
10
|
+
|
11
|
+
<a name="v1.2.0"></a>
|
12
|
+
## [v1.2.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.1.0...v1.2.0) (2020-10-01)
|
13
|
+
|
14
|
+
### Feature
|
15
|
+
|
16
|
+
* allow the metrics host to be disabled with a configuration option
|
17
|
+
* use prometheus-client ~> 2.0
|
18
|
+
|
19
|
+
### Pull Requests
|
20
|
+
|
21
|
+
* Merge pull request [#17](https://github.com/fastly/sidekiq-prometheus/issues/17) from jetpks/add-option-to-disable-metrics-server
|
22
|
+
* Merge pull request [#15](https://github.com/fastly/sidekiq-prometheus/issues/15) from silicakes/master
|
23
|
+
|
24
|
+
<a name="v1.1.0"></a>
|
25
|
+
## [v1.1.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.0.1...v1.1.0) (2020-02-12)
|
26
|
+
|
27
|
+
### Feature
|
28
|
+
|
29
|
+
* allow for configuration of the metrics host (instead of always binding to 127.0.0.1)
|
30
|
+
* Use prometheus-client ~> 1.0.0
|
31
|
+
|
32
|
+
### Pull Requests
|
33
|
+
|
34
|
+
* Merge pull request [#13](https://github.com/fastly/sidekiq-prometheus/issues/13) from postmodern/metrics_host
|
35
|
+
* Merge pull request [#11](https://github.com/fastly/sidekiq-prometheus/issues/11) from rossjones/patch-1
|
36
|
+
* Merge pull request [#12](https://github.com/fastly/sidekiq-prometheus/issues/12) from fastly/hr
|
37
|
+
|
38
|
+
<a name="v1.0.0"></a>
|
39
|
+
## [v1.0.0](https://github.com/fastly/sidekiq-prometheus/compare/v0.9.1...v1.0.0) (2019-10-24)
|
40
|
+
|
41
|
+
### Pull Requests
|
42
|
+
|
43
|
+
* Merge pull request [#9](https://github.com/fastly/sidekiq-prometheus/issues/9) from we4tech/features/update-prometheus-client
|
44
|
+
|
45
|
+
|
46
|
+
<a name="v0.9.1"></a>
|
47
|
+
## [v0.9.1](https://github.com/fastly/sidekiq-prometheus/compare/v0.9.0...v0.9.1) (2019-07-08)
|
48
|
+
|
49
|
+
### Bug Fixes
|
50
|
+
|
51
|
+
* properly alias configure!
|
52
|
+
|
53
|
+
|
3
54
|
<a name="v0.9.0"></a>
|
4
55
|
## [v0.9.0](https://github.com/fastly/sidekiq-prometheus/compare/v0.8.1...v0.9.0) (2019-03-18)
|
5
56
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Sidekiq Prometheus
|
2
2
|
|
3
3
|
|
4
|
-
[![Status](https://travis-ci.org/fastly/sidekiq-prometheus.svg?branch=
|
4
|
+
[![Status](https://travis-ci.org/fastly/sidekiq-prometheus.svg?branch=main)](https://travis-ci.org/fastly/sidekiq-prometheus)
|
5
5
|
![Gem](https://img.shields.io/gem/v/sidekiq_prometheus.svg?color=blue)
|
6
6
|
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
|
7
7
|
|
@@ -58,43 +58,50 @@ You can configure the gem by calling `configure`:
|
|
58
58
|
|
59
59
|
```ruby
|
60
60
|
SidekiqPrometheus.configure do |config|
|
61
|
-
config.
|
61
|
+
config.preset_labels = { service: 'kubernandos_api' }
|
62
62
|
end
|
63
63
|
```
|
64
64
|
|
65
65
|
`configure` will automatically call setup so
|
66
66
|
|
67
|
-
If you are running multiple services that will be reporting Sidekiq metrics you will want to take advantage of the `
|
67
|
+
If you are running multiple services that will be reporting Sidekiq metrics you will want to take advantage of the `preset_labels` configuration option. For example:
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
SidekiqPrometheus.configure do |config|
|
71
|
-
config.
|
71
|
+
config.preset_labels = { service: 'image_api' }
|
72
72
|
config.metrics_port = 9090
|
73
73
|
end
|
74
74
|
```
|
75
75
|
|
76
76
|
#### Configuration options
|
77
77
|
|
78
|
-
* `
|
78
|
+
* `preset_labels`: Hash of labels that will be included with every metric when they are registered.
|
79
|
+
* `custom_labels`: Array of names for each label that will be passed during the reporting.
|
79
80
|
* `gc_metrics_enabled`: Boolean that determines whether to record object allocation metrics per job. The default is `true`. Setting this to `false` if you don't need this metric.
|
80
81
|
* `global_metrics_enabled`: Boolean that determines whether to report global metrics from the PeriodicMetrics reporter. When `true` this will report on a number of stats from the Sidekiq API for the cluster. This requires Sidekiq::Enterprise as the reporter uses the leader election functionality to ensure that only one worker per cluster is reporting metrics.
|
81
82
|
* `periodic_metrics_enabled`: Boolean that determines whether to run the periodic metrics reporter. `PeriodicMetrics` runs a separate thread that reports on global metrics (if enabled) as well worker GC stats (if enabled). It reports metrics on the interval defined by `periodic_reporting_interval`. Defaults to `true`.
|
82
83
|
* `periodic_reporting_interval`: interval in seconds for reporting periodic metrics. Default: `30`
|
84
|
+
* `metrics_server_enabled`: Boolean that determines whether to run the rack server. Defaults to `true`
|
85
|
+
* `metrics_host`: Host on which the rack server will listen. Defaults to
|
86
|
+
`localhost`
|
83
87
|
* `metrics_port`: Port on which the rack server will listen. Defaults to `9359`
|
84
88
|
* `registry`: An instance of `Prometheus::Client::Registry`. If you have a registry with defined metrics you can use this option to pass in your registry.
|
85
89
|
|
86
90
|
```ruby
|
87
91
|
SidekiqPrometheus.configure do |config|
|
88
|
-
config.
|
92
|
+
config.preset_labels = { service: 'myapp' }
|
93
|
+
config.custom_labels = [:worker_class, :job_type, :any_other_label]
|
89
94
|
config.gc_metrics_enabled = false
|
90
95
|
config.global_metrics_enabled = true
|
91
96
|
config.periodic_metrics_enabled = true
|
92
97
|
config.periodic_reporting_interval = 20
|
98
|
+
config.metrics_server_enabled = true
|
93
99
|
config.metrics_port = 8675
|
94
100
|
end
|
95
101
|
```
|
96
102
|
|
97
|
-
Custom labels may be added by defining the `prometheus_labels` method in the worker class
|
103
|
+
Custom labels may be added by defining the `prometheus_labels` method in the worker class,
|
104
|
+
prior you need to register the custom labels as of the above example:
|
98
105
|
|
99
106
|
```ruby
|
100
107
|
class SomeWorker
|
@@ -164,7 +171,7 @@ which ensures that metrics are only reported once per cluster.
|
|
164
171
|
| sidekiq_redis_keys | gauge | Number of redis keys |
|
165
172
|
| sidekiq_redis_expires | gauge | Number of redis keys with expiry set |
|
166
173
|
|
167
|
-
The global metrics are reported with the only the `
|
174
|
+
The global metrics are reported with the only the `preset_labels` with the exception of `sidekiq_enqueued` which will add a `queue` label and record a metric per Sidekiq queue.
|
168
175
|
|
169
176
|
## Custom Worker Metrics
|
170
177
|
|
@@ -175,14 +182,14 @@ There are a few different ways to register custom metrics with SidekiqPrometheus
|
|
175
182
|
name: :metric_name,
|
176
183
|
type: :gauge,
|
177
184
|
docstring: 'description',
|
178
|
-
|
185
|
+
preset_labels: { label_name: 'label_text' },
|
179
186
|
}
|
180
187
|
```
|
181
188
|
|
182
189
|
* `:name` (required) - Unique name of the metric and should be a symbol.
|
183
190
|
* `:type` (required) - Prometheus metric type. Supported values are: `:counter`, `:gauge`, `:histogram`, and `:summary`.
|
184
191
|
* `:docstring` (required) - Human readable description of the metric.
|
185
|
-
* `:
|
192
|
+
* `:preset_labels` (optional) - Hash of labels that will be applied to every instance of this metric.
|
186
193
|
|
187
194
|
#### Registering custom metrics:
|
188
195
|
|
@@ -240,10 +247,18 @@ See the [documentation of the Prometheus::Client library](https://github.com/pro
|
|
240
247
|
|
241
248
|
## Development
|
242
249
|
|
243
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
250
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
244
251
|
|
245
252
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
246
253
|
|
254
|
+
## Contributors
|
255
|
+
|
256
|
+
* Lukas Eklund ([@leklund](https://github.com/leklund))
|
257
|
+
* NHM Tanveer Hossain Khan ([@we4tech](https://github.com/we4tech))
|
258
|
+
* [@Postmodern](https://github.com/postmodern)
|
259
|
+
* Ross Jones ([@rossjones](https://github.com/rossjones))
|
260
|
+
* Alejandro Arrufat ([@mirubiri](https://github.com/mirubiri))
|
261
|
+
|
247
262
|
## Contributing
|
248
263
|
|
249
264
|
Bug reports and pull requests are welcome on GitHub at https://github.com/fastly/sidekiq-prometheus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -258,4 +273,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
258
273
|
|
259
274
|
## Code of Conduct
|
260
275
|
|
261
|
-
Everyone interacting in the SidekiqPrometheus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fastly/sidekiq-prometheus/blob/
|
276
|
+
Everyone interacting in the SidekiqPrometheus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fastly/sidekiq-prometheus/blob/main/CODE_OF_CONDUCT.md).
|
277
|
+
|
278
|
+
# Metadata
|
279
|
+
|
280
|
+
- Ignore
|
data/lib/sidekiq_prometheus.rb
CHANGED
@@ -14,10 +14,10 @@ end
|
|
14
14
|
|
15
15
|
module SidekiqPrometheus
|
16
16
|
class << self
|
17
|
-
# @return [Hash]
|
18
|
-
attr_accessor :
|
17
|
+
# @return [Hash] Preset labels applied to every registered metric
|
18
|
+
attr_accessor :preset_labels
|
19
19
|
|
20
|
-
# @return [Hash] Custom labels applied to specific metrics
|
20
|
+
# @return [Hash{Symbol => Array<Symbol>}] Custom labels applied to specific metrics
|
21
21
|
attr_accessor :custom_labels
|
22
22
|
|
23
23
|
# @return [Array] Custom metrics that will be registered on setup.
|
@@ -27,12 +27,12 @@ module SidekiqPrometheus
|
|
27
27
|
# name: :metric_name,
|
28
28
|
# type: :prometheus_metric_type,
|
29
29
|
# docstring: 'Description of the metric',
|
30
|
-
#
|
30
|
+
# preset_labels : { label: 'value' },
|
31
31
|
# }
|
32
32
|
# ]
|
33
33
|
# @note Each element of the array is a hash and must have the required keys: `:name`, `:type`, and `:docstring`.
|
34
34
|
# The values for `:name` and `:type` should be symbols and `:docstring` should be a string.
|
35
|
-
# `
|
35
|
+
# `preset_labels` is optional and, if used, must be a hash of labels that will be included on every instance of this metric.
|
36
36
|
attr_accessor :custom_metrics
|
37
37
|
|
38
38
|
# @return [Boolean] Setting to control enabling/disabling GC metrics. Default: true
|
@@ -47,6 +47,12 @@ module SidekiqPrometheus
|
|
47
47
|
# @return [Integer] Interval in seconds to record metrics. Default: 30
|
48
48
|
attr_accessor :periodic_reporting_interval
|
49
49
|
|
50
|
+
# @return [Boolean] Setting to control enabling/disabling the metrics server. Default: true
|
51
|
+
attr_accessor :metrics_server_enabled
|
52
|
+
|
53
|
+
# @return [String] Host on which the metrics server will listen. Default: localhost
|
54
|
+
attr_accessor :metrics_host
|
55
|
+
|
50
56
|
# @return [Integer] Port on which the metrics server will listen. Default: 9357
|
51
57
|
attr_accessor :metrics_port
|
52
58
|
|
@@ -66,6 +72,8 @@ module SidekiqPrometheus
|
|
66
72
|
self.periodic_metrics_enabled = true
|
67
73
|
self.global_metrics_enabled = true
|
68
74
|
self.periodic_reporting_interval = 30
|
75
|
+
self.metrics_server_enabled = true
|
76
|
+
self.metrics_host = 'localhost'
|
69
77
|
self.metrics_port = 9359
|
70
78
|
self.custom_labels = {}
|
71
79
|
self.custom_metrics = []
|
@@ -82,8 +90,8 @@ module SidekiqPrometheus
|
|
82
90
|
# Configure SidekiqPrometheus and setup for reporting
|
83
91
|
# @example
|
84
92
|
# SidekiqPrometheus.configure do |config|
|
85
|
-
# config.
|
86
|
-
# config.custom_labels = { sidekiq_job_count:
|
93
|
+
# config.preset_labels = { service: 'images_api' }
|
94
|
+
# config.custom_labels = { sidekiq_job_count: [:custom_label_1, :custom_label_2] } }
|
87
95
|
# config.gc_metrics_enabled = true
|
88
96
|
# end
|
89
97
|
def configure
|
@@ -113,6 +121,13 @@ module SidekiqPrometheus
|
|
113
121
|
periodic_metrics_enabled
|
114
122
|
end
|
115
123
|
|
124
|
+
##
|
125
|
+
# Helper method for +metrics_server_enabled+ configuration setting
|
126
|
+
# @return [Boolean] defaults to true
|
127
|
+
def metrics_server_enabled?
|
128
|
+
metrics_server_enabled
|
129
|
+
end
|
130
|
+
|
116
131
|
##
|
117
132
|
# Get a metric from the registry
|
118
133
|
# @param metric [Symbol] name of metric to fetch
|
@@ -172,14 +187,17 @@ module SidekiqPrometheus
|
|
172
187
|
config.on(:shutdown) { SidekiqPrometheus::PeriodicMetrics.reporter.stop }
|
173
188
|
end
|
174
189
|
|
175
|
-
|
176
|
-
|
190
|
+
if metrics_server_enabled?
|
191
|
+
config.on(:startup) { SidekiqPrometheus.metrics_server }
|
192
|
+
config.on(:shutdown) { SidekiqPrometheus.metrics_server.kill }
|
193
|
+
end
|
177
194
|
end
|
178
195
|
end
|
179
196
|
|
180
197
|
##
|
181
198
|
# Start a new Prometheus exporter in a new thread.
|
182
|
-
# Will listen on SidekiqPrometheus.
|
199
|
+
# Will listen on SidekiqPrometheus.metrics_host and
|
200
|
+
# SidekiqPrometheus.metrics_port
|
183
201
|
def metrics_server
|
184
202
|
@_metrics_server ||= Thread.new do
|
185
203
|
Rack::Handler::WEBrick.run(
|
@@ -188,7 +206,7 @@ module SidekiqPrometheus
|
|
188
206
|
run ->(_) { [301, { 'Location' => '/metrics' }, []] }
|
189
207
|
},
|
190
208
|
Port: SidekiqPrometheus.metrics_port,
|
191
|
-
|
209
|
+
Host: SidekiqPrometheus.metrics_host,
|
192
210
|
)
|
193
211
|
end
|
194
212
|
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class SidekiqPrometheus::JobMetrics
|
4
|
-
def call(worker,
|
4
|
+
def call(worker, job, queue)
|
5
5
|
before = GC.stat(:total_allocated_objects) if SidekiqPrometheus.gc_metrics_enabled?
|
6
6
|
|
7
|
-
|
7
|
+
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
8
|
+
# attribute to expose the underlying thing.
|
9
|
+
labels = {
|
10
|
+
class: job['wrapped'] || worker.class.to_s,
|
11
|
+
queue: queue,
|
12
|
+
}
|
8
13
|
|
9
14
|
begin
|
10
15
|
labels.merge!(custom_labels(worker))
|
@@ -15,20 +20,20 @@ class SidekiqPrometheus::JobMetrics
|
|
15
20
|
# In case the labels have changed after the worker perform method has been called
|
16
21
|
labels.merge!(custom_labels(worker))
|
17
22
|
|
18
|
-
registry[:sidekiq_job_duration].observe(
|
19
|
-
registry[:sidekiq_job_success].increment(labels)
|
23
|
+
registry[:sidekiq_job_duration].observe(duration, labels: labels)
|
24
|
+
registry[:sidekiq_job_success].increment(labels: labels)
|
20
25
|
|
21
26
|
if SidekiqPrometheus.gc_metrics_enabled?
|
22
27
|
allocated = GC.stat(:total_allocated_objects) - before
|
23
|
-
registry[:sidekiq_job_allocated_objects].observe(
|
28
|
+
registry[:sidekiq_job_allocated_objects].observe(allocated, labels: labels)
|
24
29
|
end
|
25
30
|
|
26
31
|
result
|
27
32
|
rescue StandardError => e
|
28
|
-
registry[:sidekiq_job_failed].increment(labels)
|
33
|
+
registry[:sidekiq_job_failed].increment(labels: labels)
|
29
34
|
raise e
|
30
35
|
ensure
|
31
|
-
registry[:sidekiq_job_count].increment(labels)
|
36
|
+
registry[:sidekiq_job_count].increment(labels: labels)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
@@ -6,6 +6,7 @@ module SidekiqPrometheus::Metrics
|
|
6
6
|
UNKNOWN = 'unknown'
|
7
7
|
|
8
8
|
VALID_TYPES = %i[counter gauge histogram summary].freeze
|
9
|
+
JOB_LABELS = %i[class queue].freeze
|
9
10
|
SIDEKIQ_GLOBAL_METRICS = [
|
10
11
|
{ name: :sidekiq_workers_size,
|
11
12
|
type: :gauge,
|
@@ -15,10 +16,12 @@ module SidekiqPrometheus::Metrics
|
|
15
16
|
docstring: 'Total Dead Size', },
|
16
17
|
{ name: :sidekiq_enqueued,
|
17
18
|
type: :gauge,
|
18
|
-
docstring: 'Total Size of all known queues',
|
19
|
+
docstring: 'Total Size of all known queues',
|
20
|
+
labels: %i[queue], },
|
19
21
|
{ name: :sidekiq_queue_latency,
|
20
22
|
type: :summary,
|
21
|
-
docstring: 'Latency (in seconds) of all queues',
|
23
|
+
docstring: 'Latency (in seconds) of all queues',
|
24
|
+
labels: %i[queue], },
|
22
25
|
{ name: :sidekiq_failed,
|
23
26
|
type: :gauge,
|
24
27
|
docstring: 'Number of job executions which raised an error', },
|
@@ -42,30 +45,37 @@ module SidekiqPrometheus::Metrics
|
|
42
45
|
docstring: 'Used memory peak from Redis.info', },
|
43
46
|
{ name: :sidekiq_redis_keys,
|
44
47
|
type: :gauge,
|
45
|
-
docstring: 'Number of redis keys',
|
48
|
+
docstring: 'Number of redis keys',
|
49
|
+
labels: %i[database], },
|
46
50
|
{ name: :sidekiq_redis_expires,
|
47
51
|
type: :gauge,
|
48
|
-
docstring: 'Number of redis keys with expiry set',
|
52
|
+
docstring: 'Number of redis keys with expiry set',
|
53
|
+
labels: %i[database], },
|
49
54
|
].freeze
|
50
55
|
SIDEKIQ_JOB_METRICS = [
|
51
56
|
{ name: :sidekiq_job_count,
|
52
57
|
type: :counter,
|
53
|
-
docstring: 'Count of Sidekiq jobs',
|
58
|
+
docstring: 'Count of Sidekiq jobs',
|
59
|
+
labels: JOB_LABELS, },
|
54
60
|
{ name: :sidekiq_job_duration,
|
55
61
|
type: :histogram,
|
56
|
-
docstring: 'Sidekiq job processing duration',
|
62
|
+
docstring: 'Sidekiq job processing duration',
|
63
|
+
labels: JOB_LABELS, },
|
57
64
|
{ name: :sidekiq_job_failed,
|
58
65
|
type: :counter,
|
59
|
-
docstring: 'Count of failed Sidekiq jobs',
|
66
|
+
docstring: 'Count of failed Sidekiq jobs',
|
67
|
+
labels: JOB_LABELS, },
|
60
68
|
{ name: :sidekiq_job_success,
|
61
69
|
type: :counter,
|
62
|
-
docstring: 'Count of successful Sidekiq jobs',
|
70
|
+
docstring: 'Count of successful Sidekiq jobs',
|
71
|
+
labels: JOB_LABELS, },
|
63
72
|
].freeze
|
64
73
|
SIDEKIQ_GC_METRIC = {
|
65
74
|
name: :sidekiq_job_allocated_objects,
|
66
75
|
type: :histogram,
|
67
76
|
docstring: 'Count of ruby objects allocated by a Sidekiq job',
|
68
77
|
buckets: [10, 50, 100, 500, 1_000, 2_500, 5_000, 10_000, 50_000, 100_000, 500_000, 1_000_000, 5_000_000, 10_000_000, 25_000_000],
|
78
|
+
labels: JOB_LABELS,
|
69
79
|
}.freeze
|
70
80
|
SIDEKIQ_WORKER_GC_METRICS = [
|
71
81
|
{ name: :sidekiq_allocated_objects,
|
@@ -130,21 +140,26 @@ module SidekiqPrometheus::Metrics
|
|
130
140
|
# @param types [Symbol] type of metric to register. Valid types: %w(counter gauge summary histogram)
|
131
141
|
# @param name [Symbol] name of metric
|
132
142
|
# @param docstring [String] help text for metric
|
133
|
-
# @param
|
143
|
+
# @param labels [Array] Optionally an array of labels to configure for every instance of this metric
|
144
|
+
# @param preset_labels [Hash] Optionally a Hash of labels to use for every instance of this metric
|
134
145
|
# @param buckets [Hash] Optional hash of bucket values. Only used for histogram metrics.
|
135
|
-
def register(type:, name:, docstring:,
|
146
|
+
def register(type:, name:, docstring:, labels: [], preset_labels: {}, buckets: nil)
|
136
147
|
raise InvalidMetricType, type unless VALID_TYPES.include? type
|
137
148
|
|
138
|
-
|
149
|
+
# Aggregate all preset labels
|
150
|
+
all_preset_labels = preset_labels.dup
|
151
|
+
all_preset_labels.merge!(SidekiqPrometheus.preset_labels) if SidekiqPrometheus.preset_labels
|
139
152
|
|
140
|
-
|
141
|
-
|
153
|
+
# Aggregate all labels
|
154
|
+
all_labels = labels | SidekiqPrometheus.custom_labels.fetch(name, []) | all_preset_labels.keys
|
142
155
|
|
143
|
-
|
144
|
-
|
145
|
-
|
156
|
+
options = { docstring: docstring,
|
157
|
+
labels: all_labels,
|
158
|
+
preset_labels: all_preset_labels, }
|
146
159
|
|
147
|
-
|
160
|
+
options[:buckets] = buckets if buckets
|
161
|
+
|
162
|
+
registry.send(type, name.to_sym, options)
|
148
163
|
end
|
149
164
|
|
150
165
|
def unregister(name:)
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# one worker.
|
9
9
|
#
|
10
10
|
# @see https://github.com/mperham/sidekiq/wiki/Ent-Leader-Election
|
11
|
-
# @see https://github.com/mperham/sidekiq/blob/
|
11
|
+
# @see https://github.com/mperham/sidekiq/blob/main/lib/sidekiq/api.rb
|
12
12
|
|
13
13
|
class SidekiqPrometheus::PeriodicMetrics
|
14
14
|
# @return [Boolean] When +true+ will stop the reporting loop.
|
@@ -71,13 +71,13 @@ class SidekiqPrometheus::PeriodicMetrics
|
|
71
71
|
def report_gc_metrics
|
72
72
|
stats = GC.stat
|
73
73
|
GC_STATS[:counters].each do |stat|
|
74
|
-
SidekiqPrometheus["sidekiq_#{stat}"]&.increment({}, stats[stat])
|
74
|
+
SidekiqPrometheus["sidekiq_#{stat}"]&.increment(labels: {}, by: stats[stat])
|
75
75
|
end
|
76
76
|
GC_STATS[:gauges].each do |stat|
|
77
|
-
SidekiqPrometheus["sidekiq_#{stat}"]&.set(
|
77
|
+
SidekiqPrometheus["sidekiq_#{stat}"]&.set(stats[stat], labels: {})
|
78
78
|
end
|
79
79
|
|
80
|
-
SidekiqPrometheus[:sidekiq_rss]&.set({}
|
80
|
+
SidekiqPrometheus[:sidekiq_rss]&.set(rss, labels: {})
|
81
81
|
end
|
82
82
|
|
83
83
|
##
|
@@ -85,12 +85,12 @@ class SidekiqPrometheus::PeriodicMetrics
|
|
85
85
|
def report_global_metrics
|
86
86
|
current_stats = sidekiq_stats.new
|
87
87
|
GLOBAL_STATS.each do |stat|
|
88
|
-
SidekiqPrometheus["sidekiq_#{stat}"]&.set(
|
88
|
+
SidekiqPrometheus["sidekiq_#{stat}"]&.set(current_stats.send(stat), labels: {})
|
89
89
|
end
|
90
90
|
|
91
91
|
sidekiq_queue.all.each do |queue|
|
92
|
-
SidekiqPrometheus[:sidekiq_enqueued]&.set({ queue: queue.name }
|
93
|
-
SidekiqPrometheus[:sidekiq_queue_latency]&.observe({ queue: queue.name }
|
92
|
+
SidekiqPrometheus[:sidekiq_enqueued]&.set(queue.size, labels: { queue: queue.name })
|
93
|
+
SidekiqPrometheus[:sidekiq_queue_latency]&.observe(queue.latency, labels: { queue: queue.name })
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -106,15 +106,15 @@ class SidekiqPrometheus::PeriodicMetrics
|
|
106
106
|
return if redis_info.nil?
|
107
107
|
|
108
108
|
REDIS_STATS.each do |stat|
|
109
|
-
SidekiqPrometheus["sidekiq_redis_#{stat}"]&.set(
|
109
|
+
SidekiqPrometheus["sidekiq_redis_#{stat}"]&.set(redis_info[stat].to_i, labels: {})
|
110
110
|
end
|
111
111
|
|
112
112
|
db_stats = redis_info.select { |k, _v| k.match(/^db/) }
|
113
113
|
db_stats.each do |db, stat|
|
114
114
|
label = { database: db }
|
115
115
|
values = stat.scan(/\d+/)
|
116
|
-
SidekiqPrometheus[:sidekiq_redis_keys]&.set(
|
117
|
-
SidekiqPrometheus[:sidekiq_redis_expires]&.set(
|
116
|
+
SidekiqPrometheus[:sidekiq_redis_keys]&.set(values[0].to_i, labels: label)
|
117
|
+
SidekiqPrometheus[:sidekiq_redis_expires]&.set(values[1].to_i, labels: label)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
data/sidekiq_prometheus.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'sidekiq_prometheus/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'sidekiq_prometheus'
|
9
9
|
spec.version = SidekiqPrometheus::VERSION
|
10
|
-
spec.authors = ['Lukas Eklund']
|
10
|
+
spec.authors = ['Lukas Eklund', 'NHM Tanveer Hossain Khan']
|
11
11
|
spec.email = ['leklund@fastly.com']
|
12
12
|
|
13
13
|
spec.summary = 'Prometheus Instrumentation for Sidekiq'
|
@@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'pry'
|
26
|
-
spec.add_development_dependency 'rake', '~>
|
26
|
+
spec.add_development_dependency 'rake', '~> 12.3.3'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
28
|
spec.add_development_dependency 'rubocop', '~> 0.58.0'
|
29
29
|
|
30
|
-
spec.add_runtime_dependency 'prometheus-client', '~>
|
30
|
+
spec.add_runtime_dependency 'prometheus-client', '~> 2.0'
|
31
31
|
spec.add_runtime_dependency 'rack'
|
32
32
|
spec.add_runtime_dependency 'sidekiq', '> 5.1'
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq_prometheus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Eklund
|
8
|
-
|
8
|
+
- NHM Tanveer Hossain Khan
|
9
|
+
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -44,14 +45,14 @@ dependencies:
|
|
44
45
|
requirements:
|
45
46
|
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
+
version: 12.3.3
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
+
version: 12.3.3
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +87,14 @@ dependencies:
|
|
86
87
|
requirements:
|
87
88
|
- - "~>"
|
88
89
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
+
version: '2.0'
|
90
91
|
type: :runtime
|
91
92
|
prerelease: false
|
92
93
|
version_requirements: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
95
|
- - "~>"
|
95
96
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
+
version: '2.0'
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
99
|
name: rack
|
99
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +123,7 @@ dependencies:
|
|
122
123
|
- - ">"
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: '5.1'
|
125
|
-
description:
|
126
|
+
description:
|
126
127
|
email:
|
127
128
|
- leklund@fastly.com
|
128
129
|
executables: []
|
@@ -152,7 +153,7 @@ homepage: https://github.com/fastly/sidekiq-prometheus
|
|
152
153
|
licenses:
|
153
154
|
- MIT
|
154
155
|
metadata: {}
|
155
|
-
post_install_message:
|
156
|
+
post_install_message:
|
156
157
|
rdoc_options: []
|
157
158
|
require_paths:
|
158
159
|
- lib
|
@@ -167,9 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
168
|
- !ruby/object:Gem::Version
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
|
-
|
171
|
-
|
172
|
-
signing_key:
|
171
|
+
rubygems_version: 3.0.6
|
172
|
+
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: Prometheus Instrumentation for Sidekiq
|
175
175
|
test_files: []
|