sidekiq-cloudwatchmetrics 2.3.0 → 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: dcda0d610239286e3289711209bcd52f55a9ab00f9e37d8d768531ec125e24aa
4
- data.tar.gz: 3214895b04fdff713a7ed11c110b7c895e91307594f6ad73c80064a390a89323
3
+ metadata.gz: 3a7b965ddae391fa045355a90b73aab7f57bdbde6447f9126fc0d7d4736c74bc
4
+ data.tar.gz: ceb4ed049aa4c2e52bf813e14ed9b3a3763f470fc9205f40d6a5221b35a16bb9
5
5
  SHA512:
6
- metadata.gz: 96944fbb1a4b5669280e6146533d5f9d19ed9e67fec5feff31d1cdcb79c545bd0fb7529701bb72fdf72cef2fadc7e6a728c53d5d81726760a7dc4bf781f26d82
7
- data.tar.gz: 12fdaf02f031a14937ca4dfc03ab47e96f2e77f43b2b6b635784367326fcf2a94a0c6fbe284981dab7f1fd06cc4876ce8b197bcdd9cca3660c4dbcdb1caa50e5
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
@@ -1 +1,3 @@
1
- V����i�&(���׽���:j.��(�̊�����2���%Da�N-������NL@4%�%W
1
+
2
+ 0|����� W� �|�7��m@Մwj����
3
+ �{�d��] ��oP�X�}R�.-�������x^�?�F��W �`�x���];?��G,�5����vq
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.0
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: 2022-08-15 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
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '5.0'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '7.0'
43
+ version: '8.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: '5.0'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '7.0'
53
+ version: '8.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: aws-sdk-cloudwatch
56
56
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- �����舤-�pq*
2
- �D����J�����@}��%��b`O�Tpg�"���v�W�h�m�g�X���3�6VεH�%��As�"���}�|kؐ˦�>����1����x��+��JL�:���J���6��/��R�<⩋No�V.�OF2u�!�쥅}/e)��1���7�� t�����U;�-8uti����@�劋nY��/����\��.W`om���1`o�r�� ���q�G,T�ŋ
1
+ cE��=�B�ȶ5