sidekiq-cloudwatchmetrics 2.3.1 → 2.4.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: 3a7b965ddae391fa045355a90b73aab7f57bdbde6447f9126fc0d7d4736c74bc
4
+ data.tar.gz: ceb4ed049aa4c2e52bf813e14ed9b3a3763f470fc9205f40d6a5221b35a16bb9
5
5
  SHA512:
6
- metadata.gz: b85fa07e697fd3e993cd2e73dd177c2ba1409ca5bd0456592459aff97606dfbe981a085a51cba50c27e9220bbec9c3efd2035dd0c47f4b159be075d56338f78d
7
- data.tar.gz: b56863b700fb48a48553895383dc3c9a6884a12515891baa61d2d3e8181fa51add282bd156fc08ea9a64705e009e160397d1c1104936fb0209e8e7916e930bac
6
+ metadata.gz: 82c7cb6ea74a0df7a1e21fbf5961c05dce7129179327e9a5b50568923766ac99e747bb10a45f950ad5b1266930c3f7c3e6a02d90cc370343dc301934dd3d5436
7
+ data.tar.gz: a988deae4a7d902c291e6c6ee258459d3864d5da2672b685b783ab93b8e0140a0f54d26a51f75bcbc07b2e66a6962baf22c92659a3d10558432c56ae1287af17
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,41 @@ 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
+ if @process_metrics
168
+ processes.each do |process|
169
+ process_utilization = process["busy"] / process["concurrency"].to_f * 100.0
170
+
171
+ unless process_utilization.nan?
172
+ process_dimensions = [{name: "Hostname", value: process["hostname"]}]
173
+
174
+ if process["tag"]
175
+ process_dimensions << {name: "Tag", value: process["tag"]}
176
+ end
177
+
178
+ metrics << {
179
+ metric_name: "Utilization",
180
+ dimensions: process_dimensions,
181
+ timestamp: now,
182
+ value: process_utilization,
183
+ unit: "Percent",
184
+ }
185
+ end
186
+ end
187
+ end
188
+
179
189
  queues.each do |(queue_name, queue_size)|
180
190
  metrics << {
181
191
  metric_name: "QueueSize",
@@ -201,6 +211,7 @@ module Sidekiq::CloudWatchMetrics
201
211
  metric[:dimensions] = (metric[:dimensions] || []) + @additional_dimensions
202
212
  end
203
213
  end
214
+
204
215
  # We can only put 20 metrics at a time
205
216
  metrics.each_slice(20) do |some_metrics|
206
217
  @client.put_metric_data(
@@ -218,10 +229,13 @@ module Sidekiq::CloudWatchMetrics
218
229
  end
219
230
 
220
231
  # Returns busy / concurrency averaged across processes (for scaling)
232
+ # Avoid considering processes not yet running any threads
221
233
  private def calculate_utilization(processes)
222
- processes.map do |process|
234
+ process_utilizations = processes.map do |process|
223
235
  process["busy"] / process["concurrency"].to_f
224
- end.sum / processes.size.to_f
236
+ end.reject(&:nan?)
237
+
238
+ process_utilizations.sum / process_utilizations.size.to_f
225
239
  end
226
240
 
227
241
  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.4.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-07 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sidekiq
metadata.gz.sig CHANGED
@@ -1,3 +1 @@
1
- 5�J�~�;�lCm���Ǐ�c����d��z�q�&��l ��E�����3X
2
- ͜��O'=��7�*HY�h�sT�^_�
3
- }R���1�0�t�1�trX1rzIx>�09��<%��.��.�"��1Oi�WvK~��E��U��.����[.�����>�ث���&μ9W��� �
1
+ cE��=�B�ȶ5