puma-plugin-statsd 2.3.0 → 2.5.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: 1ae9c9480d1241bd90b7a2b0deb90b48e5effd7c48e85131db1c76b67a58934d
4
- data.tar.gz: 1037c175245a0f94d4c73e8531cf8de04e619840516fc00a910353933bf44172
3
+ metadata.gz: 15aae3abb8fd429c80e9f80235278b5e4d3d98f9b00efd72e369f40f01c36b03
4
+ data.tar.gz: 61fbb46bd7c5845228daf85f293c3a672133378c7e9374c1e15bfb45f6ae4dfe
5
5
  SHA512:
6
- metadata.gz: 2f69cf9f81b61a53aeb195b8f3706232e2793a0bc365c654b2a8338573c10e6ff0ca7e6ecf39651d128c5929111ef350bd3284c5f22d1d15bf5560d807b90e15
7
- data.tar.gz: 9c5b0671b4c9e62c790b1e534e11990b93542f56e8da9b42ab050bc007c631ac961b2d66d99d05d7ab3a8b7bd2a1113200ec439306e1f937ff8c97c2c3f342e9
6
+ metadata.gz: c96b8f351feac2013070964b5b281156b5a1d46b2d3e14ce74e4459b8bbacde741aae9a4df0f3ce7b1939ad2cb6e3428dc636fd87f2cfad851abad8b7d6f1a36
7
+ data.tar.gz: 8918fdb4bb3020661b9f935e1562870e7c67777404fa2bf2cda33fea6539a62aca1e117155c22c5c8fed034865724a56746129be739d3bfd6e469bd7c99d05c5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.5.0 2023-08-27
4
+
5
+ * 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))
6
+ * New metric: `puma.requests` - the number of requests served since the last report (PR #[55](https://github.com/yob/puma-plugin-statsd/pull/55))
7
+ * Improved documentation in the README
8
+
9
+ ## 2.4.0 2022-12-27
10
+
11
+ * Support puma 6 (PR #[46](https://github.com/yob/puma-plugin-statsd/pull/46))
12
+
3
13
  ## 2.3.0 2022-11-26
4
14
 
5
15
  * Support the origin detection over UDP from Datadog via DD_ENTITY_ID env var
data/README.md CHANGED
@@ -3,14 +3,20 @@
3
3
  [Puma][puma] integration with [statsd][statsd] for easy tracking of key metrics
4
4
  that puma can provide:
5
5
 
6
- * puma.workers
7
- * puma.booted_workers
8
- * puma.running
9
- * puma.backlog
10
- * puma.pool_capacity
11
- * puma.max_threads
12
- * puma.old_workers
13
- * puma.requests_count
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.requests_count - Total number of requests served by this puma since it started
16
+
17
+ Counters:
18
+
19
+ * puma.requests - The number of requests served since the previous report
14
20
 
15
21
  [puma]: https://github.com/puma/puma
16
22
  [statsd]: https://github.com/etsy/statsd
@@ -37,27 +43,61 @@ threads 8, 16
37
43
  plugin :statsd
38
44
  ```
39
45
 
40
- ## Usage
46
+ ## Configuration
47
+
48
+ ### Statsd Connection
41
49
 
42
- By default the plugin assumes statsd is available at 127.0.0.1. If that's true in your environment, just start puma like normal:
50
+ By default the plugin assumes statsd is available at 127.0.0.1. If that's true
51
+ in your environment, just start puma like normal:
43
52
 
44
53
  ```
45
54
  bundle exec puma
46
55
  ```
47
56
 
48
- If statsd isn't on 127.0.0.1 or the port is non-standard, you can configure them using optional environment variables:
57
+ If statsd isn't on 127.0.0.1 or the UDP port is non-standard, you can configure
58
+ them using optional environment variables:
49
59
 
50
60
  ```
51
61
  STATSD_HOST=127.0.0.1 STATSD_PORT=9125 bundle exec puma
52
62
  ```
53
63
 
64
+ Some setups have statsd listening on a Unix socket rather than UDP. In that case, specify the socket path:
65
+
66
+ ```
67
+ STATSD_SOCKET_PATH=/tmp/statsd.socket bundle exec puma
68
+ ```
69
+
70
+ ### Interval
71
+
72
+ By default values will be reported to statsd every 2 seconds. To customise that
73
+ internal, set the `STATSD_INTERVAL_SECONDS` environment variable.
74
+
75
+ ```
76
+ STATSD_INTERVAL_SECONDS=1 bundle exec puma
77
+ ```
78
+
79
+ Fractional seconds are supported. Here's how you'd opt into 500ms:
80
+
81
+ ```
82
+ STATSD_INTERVAL_SECONDS="0.5" bundle exec puma
83
+ ```
84
+
85
+ ### Prefix
86
+
87
+ In some environments you may want to prefix the metric names. To report
88
+ `foo.puma.pool_capacity` instead of `puma.pool_capacity`:
89
+
90
+ ```
91
+ STATSD_METRIC_PREFIX=foo bundle exec puma
92
+ ```
93
+
54
94
  ### Datadog Integration
55
95
 
56
96
  metric tags are a non-standard addition to the statsd protocol, supported by
57
97
  the datadog "dogstatsd" server.
58
98
 
59
99
  Should you be reporting the puma metrics to a dogstatsd server, you can set
60
- tags via the following three environment variables.
100
+ tags via the following environment variables.
61
101
 
62
102
  #### DD_TAGS
63
103
 
@@ -67,10 +107,16 @@ tags via the following three environment variables.
67
107
  For example, you could set this environment variable to set three datadog tags,
68
108
  and then you can filter by in the datadog interface:
69
109
 
70
- ```bash
71
- export DD_TAGS="env:test simple-tag-0 tag-key-1:tag-value-1"
72
- bundle exec rails server
73
110
  ```
111
+ DD_TAGS="env:test simple-tag-0 tag-key-1:tag-value-1" bundle exec puma
112
+ ```
113
+
114
+ #### DD_ENV, DD_SERVICE, DD_VERSION, DD_ENTITY_ID
115
+
116
+ The `env`, `service`, `version` and `dd.internal.entity_id` tags have special
117
+ meaning to datadog, and they can be set using the above environment variables.
118
+ These are the conventional environment variables recommended by datadog, so
119
+ they're likely to be set in many deployments.
74
120
 
75
121
  #### MY_POD_NAME
76
122
 
@@ -1,4 +1,5 @@
1
- # coding: utf-8, frozen_string_literal: true
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  require "puma"
3
4
  require "puma/plugin"
4
5
  require 'socket'
@@ -6,7 +7,7 @@ require 'socket'
6
7
  class StatsdConnector
7
8
  ENV_NAME = "STATSD_HOST"
8
9
  STATSD_TYPES = { count: 'c', gauge: 'g' }
9
- METRIC_DELIMETER = ".".freeze
10
+ METRIC_DELIMETER = "."
10
11
 
11
12
  attr_reader :host, :port
12
13
 
@@ -35,8 +36,9 @@ end
35
36
 
36
37
  # Wrap puma's stats in a safe API
37
38
  class PumaStats
38
- def initialize(stats)
39
+ def initialize(stats, previous_requests_count = 0)
39
40
  @stats = stats
41
+ @previous_requests_count = previous_requests_count
40
42
  end
41
43
 
42
44
  def clustered?
@@ -94,15 +96,26 @@ class PumaStats
94
96
  @stats.fetch(:requests_count, 0)
95
97
  end
96
98
  end
99
+
100
+ def requests_delta
101
+ requests_count - @previous_requests_count
102
+ end
97
103
  end
98
104
 
99
105
  Puma::Plugin.create do
100
106
  # We can start doing something when we have a launcher:
101
107
  def start(launcher)
102
108
  @launcher = launcher
109
+ @log_writer =
110
+ if Gem::Version.new(Puma::Const::PUMA_VERSION) >= Gem::Version.new(6)
111
+ @launcher.log_writer
112
+ else
113
+ @launcher.events
114
+ end
103
115
 
104
116
  @statsd = ::StatsdConnector.new
105
- @launcher.events.debug "statsd: enabled (host: #{@statsd.host})"
117
+ @interval_seconds = ENV.fetch("STATSD_INTERVAL_SECONDS", "2").to_f
118
+ @log_writer.debug "statsd: enabled (host: #{@statsd.host}, interval: #{@interval})"
106
119
 
107
120
  # Fetch global metric prefix from env variable
108
121
  @metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
@@ -185,12 +198,14 @@ Puma::Plugin.create do
185
198
  # Send data to statsd every few seconds
186
199
  def stats_loop
187
200
  tags = environment_variable_tags
201
+ previous_requests_count = 0
188
202
 
189
203
  sleep 5
190
204
  loop do
191
- @launcher.events.debug "statsd: notify statsd"
205
+ @log_writer.debug "statsd: notify statsd"
192
206
  begin
193
- stats = ::PumaStats.new(Puma.stats_hash)
207
+ stats = ::PumaStats.new(Puma.stats_hash, previous_requests_count)
208
+ previous_requests_count = stats.requests_count
194
209
  @statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
195
210
  @statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers, type: :gauge, tags: tags)
196
211
  @statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge, tags: tags)
@@ -199,10 +214,11 @@ Puma::Plugin.create do
199
214
  @statsd.send(metric_name: prefixed_metric_name("puma.pool_capacity"), value: stats.pool_capacity, type: :gauge, tags: tags)
200
215
  @statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge, tags: tags)
201
216
  @statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count, type: :gauge, tags: tags)
217
+ @statsd.send(metric_name: prefixed_metric_name("puma.requests"), value: stats.requests_delta, type: :count, tags: tags)
202
218
  rescue StandardError => e
203
- @launcher.events.unknown_error e, nil, "! statsd: notify stats failed"
219
+ @log_writer.unknown_error e, nil, "! statsd: notify stats failed"
204
220
  ensure
205
- sleep 2
221
+ sleep @interval_seconds
206
222
  end
207
223
  end
208
224
  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.3.0
4
+ version: 2.5.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: 2022-11-26 00:00:00.000000000 Z
11
+ date: 2023-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6'
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6'
32
+ version: '7'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -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.3.7
134
+ rubygems_version: 3.3.26
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Send puma metrics to statsd via a background thread