sidekiq-instrument 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/README.md +13 -4
- data/lib/sidekiq/instrument/version.rb +1 -1
- data/lib/sidekiq/instrument/worker.rb +2 -2
- data/lib/sidekiq/instrument/worker_metrics.rb +12 -59
- data/sidekiq-instrument.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06c38373f208fd6ec2ed7d3ab01f8cd763d71cc5c44a1684eeaebc824eed489d
|
4
|
+
data.tar.gz: 5207e4868b8190e4a1501977a1736265c501b179fdb66bc0945da9128f3aff66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0380968a8a88a122fea11c487126ce03094a02db41749c663966a2317aa0892a96fd966d373160477a9855e52421bb7d7c2892dcc42ea78f27ed1a7c42704fd1'
|
7
|
+
data.tar.gz: a89416da29a199afdb5930a62ad2bb479bdccac9b4a4af378094e53d3139d41a867f0af69920a03096d43e7ed7f2e6d9145c70c9a1fc4a34e9836506dcfa0656
|
data/.github/workflows/ci.yml
CHANGED
data/README.md
CHANGED
@@ -67,6 +67,9 @@ Sidekiq.configure_client do |config|
|
|
67
67
|
chain.add Sidekiq::Instrument::ClientMiddleware
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
Sidekiq::Instrument::WorkerMetrics.enabled = true # Set true to enable worker metrics
|
72
|
+
Sidekiq::Instrument::WorkerMetrics.namespace = <APP_NAME>
|
70
73
|
```
|
71
74
|
|
72
75
|
## StatsD Keys
|
@@ -78,7 +81,7 @@ For each job, the following metrics will be reported:
|
|
78
81
|
worker begins performing a job.
|
79
82
|
3. **shared.sidekiq._queue_._job_.runtime**: timer of the total time spent
|
80
83
|
in `perform`, in milliseconds.
|
81
|
-
|
84
|
+
4. **shared.sidekiq._queue_._job_.error**: counter incremented each time a
|
82
85
|
job fails.
|
83
86
|
|
84
87
|
The metric names can be changed by overriding the `statsd_metric_name`
|
@@ -86,7 +89,10 @@ method in your worker classes.
|
|
86
89
|
|
87
90
|
For each queue, the following metrics will be reported:
|
88
91
|
1. **shared.sidekiq._queue_.size**: gauge of how many jobs are in the queue
|
89
|
-
|
92
|
+
2. **shared.sidekiq._queue_.latency**: gauge of how long the oldest job has been in the queue
|
93
|
+
|
94
|
+
For each worker, the following metrics and tags will be reported:
|
95
|
+
1. **sidekiq.worker_metrics.inqueue.#{key}**: number of jobs "in queue" per worker, uses redis to track increment/decrement
|
90
96
|
|
91
97
|
## DogStatsD Keys
|
92
98
|
For each job, the following metrics and tags will be reported:
|
@@ -97,12 +103,15 @@ For each job, the following metrics and tags will be reported:
|
|
97
103
|
worker begins performing a job.
|
98
104
|
3. **sidekiq.runtime (tags: {queue: _queue_, worker: _job_})**: timer of the total time spent
|
99
105
|
in `perform`, in milliseconds.
|
100
|
-
|
106
|
+
4. **sidekiq.error (tags: {queue: _queue_, worker: _job_})**: counter incremented each time a
|
101
107
|
job fails.
|
102
108
|
|
103
109
|
For each queue, the following metrics and tags will be reported:
|
104
110
|
1. **sidekiq.queue.size (tags: {queue: _queue_})**: gauge of how many jobs are in the queue
|
105
|
-
|
111
|
+
2. **sidekiq.queue.latency (tags: {queue: _queue_})**: gauge of how long the oldest job has been in the queue
|
112
|
+
|
113
|
+
For each worker, the following metrics and tags will be reported:
|
114
|
+
1. **sidekiq.worker_metrics.inqueue.#{key}**: number of jobs "in queue" per worker, uses redis to track increment/decrement
|
106
115
|
|
107
116
|
## Worker
|
108
117
|
There is a worker, `Sidekiq::Instrument::Worker`, that submits gauges
|
@@ -64,8 +64,8 @@ module Sidekiq::Instrument
|
|
64
64
|
return unless WorkerMetrics.enabled
|
65
65
|
|
66
66
|
WorkerMetrics.workers_in_queue.each do |key, value|
|
67
|
-
Statter.statsd.gauge("shared.sidekiq.
|
68
|
-
Statter.dogstatsd&.gauge("shared.sidekiq.
|
67
|
+
Statter.statsd.gauge("shared.sidekiq.worker_metrics.inqueue.#{key}", value)
|
68
|
+
Statter.dogstatsd&.gauge("shared.sidekiq.worker_metrics.inqueue.#{key}", value)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -7,93 +7,46 @@ module Sidekiq
|
|
7
7
|
# Stores worker count with a key sidekiq_instrument_trace_workers:#{namespace}:in_queue
|
8
8
|
# Values are hash having keys as worker names.
|
9
9
|
class WorkerMetrics
|
10
|
-
class_attribute :enabled, :namespace
|
11
|
-
|
12
|
-
class_attribute :redis_password
|
10
|
+
class_attribute :enabled, :namespace
|
13
11
|
|
14
12
|
class << self
|
15
|
-
def redis_pool_user
|
16
|
-
@redis_pool_user ||= begin
|
17
|
-
redis_client_config = RedisClient.config(**redis_config)
|
18
|
-
@redis = redis_client_config.new_pool(
|
19
|
-
timeout: 0.5, size: Integer(ENV.fetch('RAILS_MAX_THREADS', 5))
|
20
|
-
)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def reset_redis
|
25
|
-
@redis = nil
|
26
|
-
end
|
27
|
-
|
28
13
|
def trace_workers_increment_counter(klass_name, sidekiq_redis_pool_user)
|
29
14
|
return unless enabled?
|
30
15
|
|
31
|
-
|
32
|
-
|
33
|
-
redis.call 'HINCRBY', worker_metric_name, klass_name, 1
|
34
|
-
end
|
35
|
-
else
|
36
|
-
sidekiq_redis_pool_user.with do |redis|
|
37
|
-
redis.hincrby worker_metric_name, klass_name, 1
|
38
|
-
end
|
16
|
+
Sidekiq.redis do |redis|
|
17
|
+
redis.hincrby(worker_metric_name, klass_name, 1)
|
39
18
|
end
|
40
19
|
end
|
41
20
|
|
42
21
|
def trace_workers_decrement_counter(klass_name)
|
43
22
|
return unless enabled?
|
44
23
|
|
45
|
-
|
46
|
-
|
47
|
-
redis.call 'HINCRBY', worker_metric_name, klass_name, -1
|
48
|
-
end
|
49
|
-
else
|
50
|
-
Sidekiq.redis do |redis|
|
51
|
-
redis.hincrby worker_metric_name, klass_name, -1
|
52
|
-
end
|
24
|
+
Sidekiq.redis do |redis|
|
25
|
+
redis.hincrby(worker_metric_name, klass_name, -1)
|
53
26
|
end
|
54
27
|
end
|
55
28
|
|
56
29
|
def reset_counters
|
57
30
|
return unless enabled?
|
58
31
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
redis.call 'HDEL', worker_metric_name, all_keys.keys
|
63
|
-
end
|
64
|
-
else
|
65
|
-
Sidekiq.redis do |redis|
|
66
|
-
all_keys = redis.hgetall worker_metric_name
|
67
|
-
redis.hdel worker_metric_name, all_keys.keys
|
68
|
-
end
|
32
|
+
Sidekiq.redis do |redis|
|
33
|
+
all_keys = redis.hgetall(worker_metric_name)
|
34
|
+
redis.hdel(worker_metric_name, all_keys.keys)
|
69
35
|
end
|
70
36
|
end
|
71
37
|
|
72
38
|
def reset_counter(key)
|
73
39
|
return unless enabled?
|
74
40
|
|
75
|
-
|
76
|
-
|
77
|
-
redis.call 'HDEL', worker_metric_name, key
|
78
|
-
end
|
79
|
-
else
|
80
|
-
Sidekiq.redis do |redis|
|
81
|
-
redis.hdel worker_metric_name, key
|
82
|
-
end
|
41
|
+
Sidekiq.redis do |redis|
|
42
|
+
redis.hdel(worker_metric_name, key)
|
83
43
|
end
|
84
44
|
end
|
85
45
|
|
86
46
|
def workers_in_queue
|
87
47
|
return unless enabled?
|
88
|
-
|
89
|
-
|
90
|
-
redis_pool_user.with do |redis|
|
91
|
-
redis.call 'HGETALL', worker_metric_name
|
92
|
-
end
|
93
|
-
else
|
94
|
-
Sidekiq.redis do |redis|
|
95
|
-
redis.hgetall worker_metric_name
|
96
|
-
end
|
48
|
+
Sidekiq.redis do |redis|
|
49
|
+
redis.hgetall(worker_metric_name)
|
97
50
|
end
|
98
51
|
end
|
99
52
|
|
data/sidekiq-instrument.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_dependency 'statsd-instrument', '>= 2.0.4'
|
21
21
|
spec.add_dependency 'dogstatsd-ruby', '~> 5.5'
|
22
22
|
spec.add_dependency 'activesupport', '>= 5.1', '< 7'
|
23
|
-
spec.add_dependency "redis-client", ">= 0.
|
23
|
+
spec.add_dependency "redis-client", ">= 0.14.1"
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.2'
|
26
26
|
spec.add_development_dependency 'rake', '~> 12.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loan Application Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -84,14 +84,14 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0.
|
87
|
+
version: 0.14.1
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: 0.
|
94
|
+
version: 0.14.1
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: bundler
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|