puma-plugin-statsd 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +62 -15
- data/lib/puma/plugin/statsd.rb +18 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d758cafa62bb07175a7c0a21a78e55414bfbb03b619fd5aad6bc311ccbbfaef
|
4
|
+
data.tar.gz: 6fd5c3b92fff9fe73305e7bc41149804765363d6cf0d108f7076325a75a4c57e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a86c803e4ae70ed64335db450a7965f928abcea69dee6cfdf9fcc0b733526f166fe17eefde8aac8db3f90b631c783ce13d437c7458c09729859c8b489d4cc20
|
7
|
+
data.tar.gz: dd6b1cf13cdbcc419b7e50b82dc2d1932904132dec9511be84fb2f8e321d6e9db900c823115f7154d7c1a13d24dad0e7efa9c25b5ee6e3bc944a1eee430121be
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.6.0 2023-12-11
|
4
|
+
|
5
|
+
* New metric: `puma.percent_busy` - The percentage of busy threads calculated as pool capacity relative to max threads (PR #[58](https://github.com/yob/puma-plugin-statsd/pull/58))
|
6
|
+
|
7
|
+
## 2.5.0 2023-08-27
|
8
|
+
|
9
|
+
* Support adjusting the default reporting interval of 2s (set STATSD_INTERVAL_SECONDS env var) (PR #[54](https://github.com/yob/puma-plugin-statsd/pull/54))
|
10
|
+
* New metric: `puma.requests` - the number of requests served since the last report (PR #[55](https://github.com/yob/puma-plugin-statsd/pull/55))
|
11
|
+
* Improved documentation in the README
|
12
|
+
|
3
13
|
## 2.4.0 2022-12-27
|
4
14
|
|
5
15
|
* Support puma 6 (PR #[46](https://github.com/yob/puma-plugin-statsd/pull/46))
|
6
16
|
|
7
17
|
## 2.3.0 2022-11-26
|
8
18
|
|
9
|
-
* Support the origin detection over UDP from Datadog via DD_ENTITY_ID env var
|
19
|
+
* Support the origin detection over UDP from Datadog via DD_ENTITY_ID env var (PR #[42](https://github.com/yob/puma-plugin-statsd/pull/42))
|
10
20
|
|
11
21
|
## 2.2.0 2022-07-31
|
12
22
|
|
data/README.md
CHANGED
@@ -3,14 +3,21 @@
|
|
3
3
|
[Puma][puma] integration with [statsd][statsd] for easy tracking of key metrics
|
4
4
|
that puma can provide:
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
* puma.running
|
9
|
-
* puma.
|
10
|
-
* puma.
|
11
|
-
* puma.
|
12
|
-
* puma.
|
13
|
-
* puma.
|
6
|
+
Gauges:
|
7
|
+
|
8
|
+
* puma.workers - The number of distinct process running. In single mode this will be 1, in cluster mode the number of worker processes
|
9
|
+
* puma.old_workers - The number of worker processes that are about to be shut down as part of a phased restart. Will normally be 0
|
10
|
+
* puma.booted_workers - The number of worker processes that are in a booted state
|
11
|
+
* puma.running - The number of worker threads currently running. In quiet times, idle threads may be shutdown, but they'll start back up again when traffic arrives
|
12
|
+
* puma.backlog - The number of requests that have made it to a worker but are yet to be processed. This will normally be zero, as requests queue on the tcp/unix socket in front of the master puma process, not in the worker thread pool
|
13
|
+
* puma.pool_capacity - The number of idle and unused worker threads. When this is low/zero, puma is running at full capacity and might need scaling up
|
14
|
+
* puma.max_threads - The maximum number of worker threads that might run at one time
|
15
|
+
* puma.percent_busy - The percentage of busy threads calculated as pool capacity relative to max threads
|
16
|
+
* puma.requests_count - Total number of requests served by this puma since it started
|
17
|
+
|
18
|
+
Counters:
|
19
|
+
|
20
|
+
* puma.requests - The number of requests served since the previous report
|
14
21
|
|
15
22
|
[puma]: https://github.com/puma/puma
|
16
23
|
[statsd]: https://github.com/etsy/statsd
|
@@ -37,27 +44,61 @@ threads 8, 16
|
|
37
44
|
plugin :statsd
|
38
45
|
```
|
39
46
|
|
40
|
-
##
|
47
|
+
## Configuration
|
48
|
+
|
49
|
+
### Statsd Connection
|
41
50
|
|
42
|
-
By default the plugin assumes statsd is available at 127.0.0.1. If that's true
|
51
|
+
By default the plugin assumes statsd is available at 127.0.0.1. If that's true
|
52
|
+
in your environment, just start puma like normal:
|
43
53
|
|
44
54
|
```
|
45
55
|
bundle exec puma
|
46
56
|
```
|
47
57
|
|
48
|
-
If statsd isn't on 127.0.0.1 or the port is non-standard, you can configure
|
58
|
+
If statsd isn't on 127.0.0.1 or the UDP port is non-standard, you can configure
|
59
|
+
them using optional environment variables:
|
49
60
|
|
50
61
|
```
|
51
62
|
STATSD_HOST=127.0.0.1 STATSD_PORT=9125 bundle exec puma
|
52
63
|
```
|
53
64
|
|
65
|
+
Some setups have statsd listening on a Unix socket rather than UDP. In that case, specify the socket path:
|
66
|
+
|
67
|
+
```
|
68
|
+
STATSD_SOCKET_PATH=/tmp/statsd.socket bundle exec puma
|
69
|
+
```
|
70
|
+
|
71
|
+
### Interval
|
72
|
+
|
73
|
+
By default values will be reported to statsd every 2 seconds. To customise that
|
74
|
+
internal, set the `STATSD_INTERVAL_SECONDS` environment variable.
|
75
|
+
|
76
|
+
```
|
77
|
+
STATSD_INTERVAL_SECONDS=1 bundle exec puma
|
78
|
+
```
|
79
|
+
|
80
|
+
Fractional seconds are supported. Here's how you'd opt into 500ms:
|
81
|
+
|
82
|
+
```
|
83
|
+
STATSD_INTERVAL_SECONDS="0.5" bundle exec puma
|
84
|
+
```
|
85
|
+
|
86
|
+
### Prefix
|
87
|
+
|
88
|
+
In some environments you may want to prefix the metric names. To report
|
89
|
+
`foo.puma.pool_capacity` instead of `puma.pool_capacity`:
|
90
|
+
|
91
|
+
```
|
92
|
+
STATSD_METRIC_PREFIX=foo bundle exec puma
|
93
|
+
```
|
94
|
+
|
54
95
|
### Datadog Integration
|
55
96
|
|
56
97
|
metric tags are a non-standard addition to the statsd protocol, supported by
|
57
98
|
the datadog "dogstatsd" server.
|
58
99
|
|
59
100
|
Should you be reporting the puma metrics to a dogstatsd server, you can set
|
60
|
-
tags via the following
|
101
|
+
tags via the following environment variables.
|
61
102
|
|
62
103
|
#### DD_TAGS
|
63
104
|
|
@@ -67,10 +108,16 @@ tags via the following three environment variables.
|
|
67
108
|
For example, you could set this environment variable to set three datadog tags,
|
68
109
|
and then you can filter by in the datadog interface:
|
69
110
|
|
70
|
-
```bash
|
71
|
-
export DD_TAGS="env:test simple-tag-0 tag-key-1:tag-value-1"
|
72
|
-
bundle exec rails server
|
73
111
|
```
|
112
|
+
DD_TAGS="env:test simple-tag-0 tag-key-1:tag-value-1" bundle exec puma
|
113
|
+
```
|
114
|
+
|
115
|
+
#### DD_ENV, DD_SERVICE, DD_VERSION, DD_ENTITY_ID
|
116
|
+
|
117
|
+
The `env`, `service`, `version` and `dd.internal.entity_id` tags have special
|
118
|
+
meaning to datadog, and they can be set using the above environment variables.
|
119
|
+
These are the conventional environment variables recommended by datadog, so
|
120
|
+
they're likely to be set in many deployments.
|
74
121
|
|
75
122
|
#### MY_POD_NAME
|
76
123
|
|
data/lib/puma/plugin/statsd.rb
CHANGED
@@ -36,8 +36,9 @@ end
|
|
36
36
|
|
37
37
|
# Wrap puma's stats in a safe API
|
38
38
|
class PumaStats
|
39
|
-
def initialize(stats)
|
39
|
+
def initialize(stats, previous_requests_count = 0)
|
40
40
|
@stats = stats
|
41
|
+
@previous_requests_count = previous_requests_count
|
41
42
|
end
|
42
43
|
|
43
44
|
def clustered?
|
@@ -95,6 +96,14 @@ class PumaStats
|
|
95
96
|
@stats.fetch(:requests_count, 0)
|
96
97
|
end
|
97
98
|
end
|
99
|
+
|
100
|
+
def percent_busy
|
101
|
+
(1 - (pool_capacity / max_threads.to_f)) * 100
|
102
|
+
end
|
103
|
+
|
104
|
+
def requests_delta
|
105
|
+
requests_count - @previous_requests_count
|
106
|
+
end
|
98
107
|
end
|
99
108
|
|
100
109
|
Puma::Plugin.create do
|
@@ -109,7 +118,8 @@ Puma::Plugin.create do
|
|
109
118
|
end
|
110
119
|
|
111
120
|
@statsd = ::StatsdConnector.new
|
112
|
-
@
|
121
|
+
@interval_seconds = ENV.fetch("STATSD_INTERVAL_SECONDS", "2").to_f
|
122
|
+
@log_writer.debug "statsd: enabled (host: #{@statsd.host}, interval: #{@interval})"
|
113
123
|
|
114
124
|
# Fetch global metric prefix from env variable
|
115
125
|
@metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
|
@@ -192,12 +202,14 @@ Puma::Plugin.create do
|
|
192
202
|
# Send data to statsd every few seconds
|
193
203
|
def stats_loop
|
194
204
|
tags = environment_variable_tags
|
205
|
+
previous_requests_count = 0
|
195
206
|
|
196
207
|
sleep 5
|
197
208
|
loop do
|
198
209
|
@log_writer.debug "statsd: notify statsd"
|
199
210
|
begin
|
200
|
-
stats = ::PumaStats.new(Puma.stats_hash)
|
211
|
+
stats = ::PumaStats.new(Puma.stats_hash, previous_requests_count)
|
212
|
+
previous_requests_count = stats.requests_count
|
201
213
|
@statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
|
202
214
|
@statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers, type: :gauge, tags: tags)
|
203
215
|
@statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge, tags: tags)
|
@@ -205,11 +217,13 @@ Puma::Plugin.create do
|
|
205
217
|
@statsd.send(metric_name: prefixed_metric_name("puma.backlog"), value: stats.backlog, type: :gauge, tags: tags)
|
206
218
|
@statsd.send(metric_name: prefixed_metric_name("puma.pool_capacity"), value: stats.pool_capacity, type: :gauge, tags: tags)
|
207
219
|
@statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge, tags: tags)
|
220
|
+
@statsd.send(metric_name: prefixed_metric_name("puma.percent_busy"), value: stats.percent_busy, type: :gauge, tags: tags)
|
208
221
|
@statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count, type: :gauge, tags: tags)
|
222
|
+
@statsd.send(metric_name: prefixed_metric_name("puma.requests"), value: stats.requests_delta, type: :count, tags: tags)
|
209
223
|
rescue StandardError => e
|
210
224
|
@log_writer.unknown_error e, nil, "! statsd: notify stats failed"
|
211
225
|
ensure
|
212
|
-
sleep
|
226
|
+
sleep @interval_seconds
|
213
227
|
end
|
214
228
|
end
|
215
229
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-plugin-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.4.10
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Send puma metrics to statsd via a background thread
|