Skip to content

Commit 1cd5e22

Browse files
f1shermanmaycmleesteveny91
authored
Add busy_threads metric to Puma integration (DataDog#2697)
* Add `busy_threads` metric to Puma integration This new stat was [added about 6 months ago](puma/puma#3517) to track "the overall current state of work to be done and the capacity to do it". It seems like it could be useful to track, potentially for autoscaling or other applications. * Update puma/metadata.csv Co-authored-by: May Lee <[email protected]> * Update puma/metadata.csv Co-authored-by: Steven Yuen <[email protected]> --------- Co-authored-by: May Lee <[email protected]> Co-authored-by: Steven Yuen <[email protected]>
1 parent ad77a3c commit 1cd5e22

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

puma/datadog_checks/puma/puma.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
METRICS = [
88
('backlog', 'backlog', AgentCheck.gauge),
99
('booted_workers', 'booted_workers', AgentCheck.gauge),
10+
('busy_threads', 'busy_threads', AgentCheck.gauge),
1011
('max_threads', 'max_threads', AgentCheck.gauge),
1112
('pool_capacity', 'pool_capacity', AgentCheck.gauge),
1213
('requests_count', 'requests_count', AgentCheck.gauge),
@@ -32,6 +33,7 @@ def _extract_metrics(self, response):
3233
metrics = {
3334
'backlog': 0,
3435
'booted_workers': 0,
36+
'busy_threads': 0,
3537
'max_threads': 0,
3638
'pool_capacity': 0,
3739
'requests_count': 0,
@@ -46,13 +48,15 @@ def _extract_metrics(self, response):
4648
for worker in response['worker_status']:
4749
last_status = worker.get('last_status')
4850
metrics['backlog'] += int(last_status.get('backlog', 0))
51+
metrics['busy_threads'] += int(last_status.get('busy_threads', 0))
4952
metrics['max_threads'] += int(last_status.get('max_threads', 0))
5053
metrics['pool_capacity'] += int(last_status.get('pool_capacity', 0))
5154
metrics['requests_count'] += int(last_status.get('requests_count', 0))
5255
metrics['running'] += int(last_status.get('running', 0))
5356

5457
else: # Puma is not clustered
5558
metrics['backlog'] = int(response.get('backlog', 0))
59+
metrics['busy_threads'] = int(response.get('busy_threads', 0))
5660
metrics['max_threads'] = int(response.get('max_threads', 0))
5761
metrics['pool_capacity'] = int(response.get('pool_capacity', 0))
5862
metrics['requests_count'] = int(response.get('requests_count', 0))

puma/metadata.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric
22
puma.backlog,gauge,,unit,,Pending request backlog,0,puma,request backlog,
33
puma.booted_workers,gauge,,unit,,Number of booted puma workers,0,puma,booted workers,
4+
puma.busy_threads,gauge,,unit,,"Number of threads that are running, including requests waiting on a thread, but excluding requests waiting for work.",0,puma,booted workers,
45
puma.max_threads,gauge,,unit,,Maximum threads,0,puma,max threads,
56
puma.pool_capacity,gauge,,unit,,Pool capacity,0,puma,pool capacity,
67
puma.requests_count,gauge,,unit,,Request count,0,puma,request count,

puma/tests/test_puma.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_metrics_for_puma_in_cluster_mode(aggregator, instance):
2929
{
3030
'last_status': {
3131
'backlog': 0,
32+
'busy_threads': 6,
3233
'max_threads': 20,
3334
'pool_capacity': 15,
3435
'running': 20,
@@ -38,6 +39,7 @@ def test_metrics_for_puma_in_cluster_mode(aggregator, instance):
3839
{
3940
'last_status': {
4041
'backlog': 1,
42+
'busy_threads': 4,
4143
'max_threads': 20,
4244
'pool_capacity': 15,
4345
'running': 20,
@@ -58,6 +60,7 @@ def test_metrics_for_puma_in_cluster_mode(aggregator, instance):
5860
aggregator.assert_metric('puma.workers', value=2.0, tags=[])
5961
aggregator.assert_metric('puma.backlog', value=1.0, tags=[])
6062
aggregator.assert_metric('puma.booted_workers', value=2.0, tags=[])
63+
aggregator.assert_metric('puma.busy_threads', value=10.0, tags=[])
6164
aggregator.assert_metric('puma.pool_capacity', value=30.0, tags=[])
6265
aggregator.assert_metric('puma.running', value=40.0, tags=[])
6366
aggregator.assert_metric('puma.requests_count', value=270.0, tags=[])
@@ -71,7 +74,9 @@ def test_metrics_for_puma_in_single_mode(aggregator, instance):
7174
'content-type': 'application/json',
7275
}
7376

74-
content = json.dumps({"backlog": 1, "running": 2, "pool_capacity": 15, "max_threads": 20, "requests_count": 120})
77+
content = json.dumps(
78+
{"backlog": 1, "busy_threads": 6, "running": 2, "pool_capacity": 15, "max_threads": 20, "requests_count": 120}
79+
)
7580

7681
response = Mock(headers=headers, content=content)
7782

@@ -81,6 +86,7 @@ def test_metrics_for_puma_in_single_mode(aggregator, instance):
8186

8287
aggregator.assert_metric('puma.max_threads', value=20.0, tags=[])
8388
aggregator.assert_metric('puma.backlog', value=1.0, tags=[])
89+
aggregator.assert_metric('puma.busy_threads', value=6.0, tags=[])
8490
aggregator.assert_metric('puma.pool_capacity', value=15.0, tags=[])
8591
aggregator.assert_metric('puma.running', value=2.0, tags=[])
8692
aggregator.assert_metric('puma.requests_count', value=120.0, tags=[])
@@ -107,6 +113,7 @@ def test_check(aggregator, instance, test_server):
107113
aggregator.assert_metric('puma.workers', value=2.0, tags=[])
108114
aggregator.assert_metric('puma.backlog', value=0.0, tags=[])
109115
aggregator.assert_metric('puma.booted_workers', value=2.0, tags=[])
116+
aggregator.assert_metric('puma.busy_threads', value=0.0, tags=[])
110117
aggregator.assert_metric('puma.pool_capacity', value=10.0, tags=[])
111118
aggregator.assert_metric('puma.running', value=10.0, tags=[])
112119
aggregator.assert_metric('puma.requests_count', value=1.0, tags=[])

0 commit comments

Comments
 (0)