puma-plugin-statsd 2.4.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: 024db26ca54b74eb4cc86cfbc8aacda5f5b68d25177b007a9050a22545466351
4
- data.tar.gz: 1e42d780def66948cd9fd01357b0a424ad04aaac86bfa6f8e5c26de82a430e11
3
+ metadata.gz: 15aae3abb8fd429c80e9f80235278b5e4d3d98f9b00efd72e369f40f01c36b03
4
+ data.tar.gz: 61fbb46bd7c5845228daf85f293c3a672133378c7e9374c1e15bfb45f6ae4dfe
5
5
  SHA512:
6
- metadata.gz: 6c44f94b38dc4c1848827bf20a3503f639be3cd13a0501beb807dd75d092403b229caf0c83c24b57caec9a255a76b2f371ce9b2e2cfa9efabc9e06ba07d9730c
7
- data.tar.gz: af204a3591ff96c4bd876d42eec731037236265208abdb58f492145beda7e9124a511317623918bf9ce213c5e76c87307f26659e8cc12feea7a364b31d1a4ad3
6
+ metadata.gz: c96b8f351feac2013070964b5b281156b5a1d46b2d3e14ce74e4459b8bbacde741aae9a4df0f3ce7b1939ad2cb6e3428dc636fd87f2cfad851abad8b7d6f1a36
7
+ data.tar.gz: 8918fdb4bb3020661b9f935e1562870e7c67777404fa2bf2cda33fea6539a62aca1e117155c22c5c8fed034865724a56746129be739d3bfd6e469bd7c99d05c5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 2.4.0 2022-12-27
4
10
 
5
11
  * Support puma 6 (PR #[46](https://github.com/yob/puma-plugin-statsd/pull/46))
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
 
@@ -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,10 @@ class PumaStats
95
96
  @stats.fetch(:requests_count, 0)
96
97
  end
97
98
  end
99
+
100
+ def requests_delta
101
+ requests_count - @previous_requests_count
102
+ end
98
103
  end
99
104
 
100
105
  Puma::Plugin.create do
@@ -109,7 +114,8 @@ Puma::Plugin.create do
109
114
  end
110
115
 
111
116
  @statsd = ::StatsdConnector.new
112
- @log_writer.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})"
113
119
 
114
120
  # Fetch global metric prefix from env variable
115
121
  @metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
@@ -192,12 +198,14 @@ Puma::Plugin.create do
192
198
  # Send data to statsd every few seconds
193
199
  def stats_loop
194
200
  tags = environment_variable_tags
201
+ previous_requests_count = 0
195
202
 
196
203
  sleep 5
197
204
  loop do
198
205
  @log_writer.debug "statsd: notify statsd"
199
206
  begin
200
- stats = ::PumaStats.new(Puma.stats_hash)
207
+ stats = ::PumaStats.new(Puma.stats_hash, previous_requests_count)
208
+ previous_requests_count = stats.requests_count
201
209
  @statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
202
210
  @statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers, type: :gauge, tags: tags)
203
211
  @statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge, tags: tags)
@@ -206,10 +214,11 @@ Puma::Plugin.create do
206
214
  @statsd.send(metric_name: prefixed_metric_name("puma.pool_capacity"), value: stats.pool_capacity, type: :gauge, tags: tags)
207
215
  @statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge, tags: tags)
208
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)
209
218
  rescue StandardError => e
210
219
  @log_writer.unknown_error e, nil, "! statsd: notify stats failed"
211
220
  ensure
212
- sleep 2
221
+ sleep @interval_seconds
213
222
  end
214
223
  end
215
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.4.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-12-27 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