Skip to content

Commit 4db8316

Browse files
authored
Expose more puma metrics in Prometheus (#4423)
1 parent 74923d3 commit 4db8316

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/cloud_controller/metrics/periodic_updater.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ def update_webserver_stats
165165
index: worker_status[:index],
166166
pid: worker_status[:pid],
167167
thread_count: worker_status[:last_status][:running],
168-
backlog: worker_status[:last_status][:backlog]
168+
backlog: worker_status[:last_status][:backlog],
169+
pool_capacity: worker_status[:last_status][:pool_capacity],
170+
busy_threads: worker_status[:last_status][:busy_threads],
171+
requests_count: worker_status[:last_status][:requests_count]
169172
}
170173
end
171174
@prometheus_updater.update_webserver_stats_puma(worker_count, worker_stats)

lib/cloud_controller/metrics/prometheus_updater.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def self.allow_pid_label
5454
{ type: :gauge, name: :cc_puma_worker_count, docstring: 'Puma worker count', aggregation: :most_recent },
5555
{ type: :gauge, name: :cc_puma_worker_started_at, docstring: 'Puma worker: started_at', labels: %i[index pid], aggregation: :most_recent },
5656
{ type: :gauge, name: :cc_puma_worker_thread_count, docstring: 'Puma worker: thread count', labels: %i[index pid], aggregation: :most_recent },
57-
{ type: :gauge, name: :cc_puma_worker_backlog, docstring: 'Puma worker: backlog', labels: %i[index pid], aggregation: :most_recent }
57+
{ type: :gauge, name: :cc_puma_worker_backlog, docstring: 'Puma worker: backlog', labels: %i[index pid], aggregation: :most_recent },
58+
{ type: :gauge, name: :cc_puma_worker_pool_capacity, docstring: 'Puma worker: pool capacity', labels: %i[index pid], aggregation: :most_recent },
59+
{ type: :gauge, name: :cc_puma_worker_requests_count, docstring: 'Puma worker: requests count', labels: %i[index pid], aggregation: :most_recent },
60+
{ type: :gauge, name: :cc_puma_worker_busy_threads, docstring: 'Puma worker: busy threads', labels: %i[index pid], aggregation: :most_recent }
5861
].freeze
5962

6063
DB_CONNECTION_POOL_METRICS = [

spec/unit/lib/cloud_controller/metrics/periodic_updater_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ module VCAP::CloudController::Metrics
705705
stats_hash = {
706706
booted_workers: 2,
707707
worker_status: [
708-
{ started_at: '2023-11-29T13:15:05Z', index: 0, pid: 123, last_status: { running: 1, backlog: 0 } },
709-
{ started_at: '2023-11-29T13:15:10Z', index: 1, pid: 234, last_status: { running: 2, backlog: 1 } }
708+
{ started_at: '2023-11-29T13:15:05Z', index: 0, pid: 123, last_status: { running: 1, backlog: 0, busy_threads: 0, pool_capacity: 1, requests_count: 9 } },
709+
{ started_at: '2023-11-29T13:15:10Z', index: 1, pid: 234, last_status: { running: 2, backlog: 1, busy_threads: 1, pool_capacity: 2, requests_count: 10 } }
710710
]
711711
}
712712
allow(Puma).to receive(:stats_hash).and_return(stats_hash)
@@ -715,8 +715,8 @@ module VCAP::CloudController::Metrics
715715

716716
expected_worker_count = 2
717717
expected_worker_stats = [
718-
{ started_at: 1_701_263_705, index: 0, pid: 123, thread_count: 1, backlog: 0 },
719-
{ started_at: 1_701_263_710, index: 1, pid: 234, thread_count: 2, backlog: 1 }
718+
{ started_at: 1_701_263_705, index: 0, pid: 123, thread_count: 1, backlog: 0, busy_threads: 0, pool_capacity: 1, requests_count: 9 },
719+
{ started_at: 1_701_263_710, index: 1, pid: 234, thread_count: 2, backlog: 1, busy_threads: 1, pool_capacity: 2, requests_count: 10 }
720720
]
721721
expect(prometheus_updater).to have_received(:update_webserver_stats_puma).with(expected_worker_count, expected_worker_stats)
722722
end

spec/unit/lib/cloud_controller/metrics/prometheus_updater_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ module VCAP::CloudController::Metrics
206206
it 'contains Puma stats' do
207207
worker_count = 2
208208
worker_stats = [
209-
{ started_at: 1_701_263_705, index: 0, pid: 123, thread_count: 1, backlog: 0 },
210-
{ started_at: 1_701_263_710, index: 1, pid: 234, thread_count: 2, backlog: 1 }
209+
{ started_at: 1_701_263_705, index: 0, pid: 123, thread_count: 1, backlog: 0, busy_threads: 0, pool_capacity: 1, requests_count: 9 },
210+
{ started_at: 1_701_263_710, index: 1, pid: 234, thread_count: 2, backlog: 1, busy_threads: 1, pool_capacity: 2, requests_count: 10 }
211211
]
212212

213213
updater.update_webserver_stats_puma(worker_count, worker_stats)
@@ -226,6 +226,18 @@ module VCAP::CloudController::Metrics
226226
metric = prom_client.metrics.find { |m| m.name == :cc_puma_worker_backlog }
227227
expect(metric.get(labels: { index: 0, pid: 123 })).to eq(0)
228228
expect(metric.get(labels: { index: 1, pid: 234 })).to eq(1)
229+
230+
metric = prom_client.metrics.find { |m| m.name == :cc_puma_worker_pool_capacity }
231+
expect(metric.get(labels: { index: 0, pid: 123 })).to eq(1)
232+
expect(metric.get(labels: { index: 1, pid: 234 })).to eq(2)
233+
234+
metric = prom_client.metrics.find { |m| m.name == :cc_puma_worker_requests_count }
235+
expect(metric.get(labels: { index: 0, pid: 123 })).to eq(9)
236+
expect(metric.get(labels: { index: 1, pid: 234 })).to eq(10)
237+
238+
metric = prom_client.metrics.find { |m| m.name == :cc_puma_worker_busy_threads }
239+
expect(metric.get(labels: { index: 0, pid: 123 })).to eq(0)
240+
expect(metric.get(labels: { index: 1, pid: 234 })).to eq(1)
229241
end
230242
end
231243

0 commit comments

Comments
 (0)