Skip to content

Commit 1daa6f8

Browse files
Expose worker_count in utilization metrics.
1 parent fe349a6 commit 1daa6f8

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/async/service/supervisor/utilization_monitor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ def as_json
303303
aggregated[service_name][key] = value
304304
end
305305
end
306+
307+
# Count workers per service (for utilization denominator)
308+
aggregated[service_name][:worker_count] = (aggregated[service_name][:worker_count] || 0) + 1
306309
end
307310

308311
aggregated

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Add `worker_count` to `UtilizationMonitor` aggregated metrics per service, indicating how many workers contributed to each service's metrics (useful for utilization denominator).
6+
37
## v0.12.0
48

59
- Introduce `UtilizationMonitor`, that uses shared memory to track worker utilization metrics, like total and active requests, connections, etc.

test/async/service/utilization_monitor.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
status = monitor.status
123123
expect(status[:data]["test_service"]).to have_keys(
124124
connections_total: be == 100,
125-
connections_active: be == 5
125+
connections_active: be == 5,
126+
worker_count: be == 1
126127
)
127128
end
128129

@@ -157,7 +158,8 @@
157158
status = monitor.status
158159
expect(status[:data]["test_service"]).to have_keys(
159160
connections_total: be == 125, # 50 + 75
160-
connections_active: be == 5 # 3 + 2
161+
connections_active: be == 5, # 3 + 2
162+
worker_count: be == 2 # two workers for same service
161163
)
162164
end
163165

@@ -193,11 +195,13 @@
193195
expect(status[:data]).to have_keys("test_service", "other_service")
194196
expect(status[:data]["test_service"]).to have_keys(
195197
connections_total: be == 100,
196-
connections_active: be == 5
198+
connections_active: be == 5,
199+
worker_count: be == 1
197200
)
198201
expect(status[:data]["other_service"]).to have_keys(
199202
connections_total: be == 200,
200-
connections_active: be == 10
203+
connections_active: be == 10,
204+
worker_count: be == 1
201205
)
202206
end
203207

@@ -224,7 +228,8 @@
224228
status = monitor.status
225229
expect(status[:data]).to have_keys("unknown")
226230
expect(status[:data]["unknown"]).to have_keys(
227-
connections_total: be == 50
231+
connections_total: be == 50,
232+
worker_count: be == 1
228233
)
229234
end
230235

0 commit comments

Comments
 (0)