sidekiq-cloudwatchmetrics 2.3.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93c28ff2cfaca3875a7519787116e4d1e748485a697432b4dd92659e167bf6cf
4
- data.tar.gz: f1ba283d86ad4626910f0ead50d5d30868d7f491c970e38d6fbf0c0641562b30
3
+ metadata.gz: 004deef714e38c04cb032d6b38391314e93549fe2cc6727b650b269cdd6f1413
4
+ data.tar.gz: 22470a586aaf2444b9997fd1e56ce6ce9ed581389fdba76c012fddb7ebbf914c
5
5
  SHA512:
6
- metadata.gz: b85fa07e697fd3e993cd2e73dd177c2ba1409ca5bd0456592459aff97606dfbe981a085a51cba50c27e9220bbec9c3efd2035dd0c47f4b159be075d56338f78d
7
- data.tar.gz: b56863b700fb48a48553895383dc3c9a6884a12515891baa61d2d3e8181fa51add282bd156fc08ea9a64705e009e160397d1c1104936fb0209e8e7916e930bac
6
+ metadata.gz: 04bc3f32a5e25b0ee25ace2a349a85a4e9313ef1555bc14757b0f102f02e3819d9f46ed9aefc23e9c8662dbe901194e154bd6a4ed52e8765a86bed7cb2ed7821
7
+ data.tar.gz: afe7fe3476aaa4fb8b431df1e05b357e46e437f775235a02ef0a31daf7d3c454e8fb4b63eff9f261a91b49c772212c4b8691822f92918b2543ac89d37e194c03
checksums.yaml.gz.sig CHANGED
Binary file
@@ -45,12 +45,13 @@ module Sidekiq::CloudWatchMetrics
45
45
 
46
46
  INTERVAL = 60 # seconds
47
47
 
48
- def initialize(config: Sidekiq, client: Aws::CloudWatch::Client.new, namespace: "Sidekiq", additional_dimensions: {})
48
+ def initialize(config: Sidekiq, client: Aws::CloudWatch::Client.new, namespace: "Sidekiq", process_metrics: true, additional_dimensions: {})
49
49
  # Sidekiq 6.5+ requires @config, which defaults to the top-level
50
50
  # `Sidekiq` module, but can be overridden when running multiple Sidekiqs.
51
51
  @config = config
52
52
  @client = client
53
53
  @namespace = namespace
54
+ @process_metrics = process_metrics
54
55
  @additional_dimensions = additional_dimensions.map { |k, v| {name: k.to_s, value: v.to_s} }
55
56
  end
56
57
 
@@ -150,32 +151,59 @@ module Sidekiq::CloudWatchMetrics
150
151
  value: calculate_capacity(processes),
151
152
  unit: "Count",
152
153
  },
153
- {
154
- metric_name: "Utilization",
155
- timestamp: now,
156
- value: calculate_utilization(processes) * 100.0,
157
- unit: "Percent",
158
- },
159
154
  ]
160
155
 
161
- processes.each do |process|
162
- metrics << {
163
- metric_name: "Utilization",
164
- dimensions: [{name: "Hostname", value: process["hostname"]}],
165
- timestamp: now,
166
- value: process["busy"] / process["concurrency"].to_f * 100.0,
167
- unit: "Percent",
168
- }
156
+ utilization = calculate_utilization(processes) * 100.0
169
157
 
158
+ unless utilization.nan?
170
159
  metrics << {
171
160
  metric_name: "Utilization",
172
- dimensions: [{name: "Tag", value: process["tag"]}],
173
161
  timestamp: now,
174
- value: process["busy"] / process["concurrency"].to_f * 100.0,
162
+ value: utilization,
175
163
  unit: "Percent",
176
164
  }
177
165
  end
178
166
 
167
+ processes.group_by do |process|
168
+ process["tag"]
169
+ end.each do |(tag, tag_processes)|
170
+ next if tag.nil?
171
+
172
+ tag_utilization = calculate_utilization(tag_processes) * 100.0
173
+
174
+ unless tag_utilization.nan?
175
+ metrics << {
176
+ metric_name: "Utilization",
177
+ dimensions: [{name: "Tag", value: tag}],
178
+ timestamp: now,
179
+ value: tag_utilization,
180
+ unit: "Percent",
181
+ }
182
+ end
183
+ end
184
+
185
+ if @process_metrics
186
+ processes.each do |process|
187
+ process_utilization = process["busy"] / process["concurrency"].to_f * 100.0
188
+
189
+ unless process_utilization.nan?
190
+ process_dimensions = [{name: "Hostname", value: process["hostname"]}]
191
+
192
+ if process["tag"]
193
+ process_dimensions << {name: "Tag", value: process["tag"]}
194
+ end
195
+
196
+ metrics << {
197
+ metric_name: "Utilization",
198
+ dimensions: process_dimensions,
199
+ timestamp: now,
200
+ value: process_utilization,
201
+ unit: "Percent",
202
+ }
203
+ end
204
+ end
205
+ end
206
+
179
207
  queues.each do |(queue_name, queue_size)|
180
208
  metrics << {
181
209
  metric_name: "QueueSize",
@@ -201,6 +229,7 @@ module Sidekiq::CloudWatchMetrics
201
229
  metric[:dimensions] = (metric[:dimensions] || []) + @additional_dimensions
202
230
  end
203
231
  end
232
+
204
233
  # We can only put 20 metrics at a time
205
234
  metrics.each_slice(20) do |some_metrics|
206
235
  @client.put_metric_data(
@@ -218,10 +247,13 @@ module Sidekiq::CloudWatchMetrics
218
247
  end
219
248
 
220
249
  # Returns busy / concurrency averaged across processes (for scaling)
250
+ # Avoid considering processes not yet running any threads
221
251
  private def calculate_utilization(processes)
222
- processes.map do |process|
252
+ process_utilizations = processes.map do |process|
223
253
  process["busy"] / process["concurrency"].to_f
224
- end.sum / processes.size.to_f
254
+ end.reject(&:nan?)
255
+
256
+ process_utilizations.sum / process_utilizations.size.to_f
225
257
  end
226
258
 
227
259
  def quiet
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-cloudwatchmetrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Cochran
@@ -29,7 +29,7 @@ cert_chain:
29
29
  AAMioxgB6J5QhXQ42OSWIzwHZIbSv3DV9Lf5sde50HIW5f9u5jn29TUGDhSWYKkh
30
30
  LDvy9dfwMMOdIZi75Q8SBBib84AuwhMHIlUv9FcHhh3dXsDDYkrVrpUAwCsG6yCm
31
31
  -----END CERTIFICATE-----
32
- date: 2023-01-24 00:00:00.000000000 Z
32
+ date: 2023-03-24 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sidekiq
metadata.gz.sig CHANGED
Binary file