puma-plugin-statsd 1.1.0 → 1.2.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: 0b3cd5c0412cc60e11ea2d99dbf080b9ffe81054b8a4d8c8bfa2c7279d8e921b
4
- data.tar.gz: 7d9345141eab89e4c2b0b6a0ed66fecabaaa1fea80e039d050593cbba42bd695
3
+ metadata.gz: d0b1cd40cd7e6d081b35483c8319f4b1eb3463ded57a1f015e5f78db3771f5a8
4
+ data.tar.gz: 8df635d04448770b411364182f7d6466f736065ce2b4f396b6daec14c2abf364
5
5
  SHA512:
6
- metadata.gz: 86bb26d1b1af5b213380b4e7be6ec51f5fb216175304d3d78f36010afd4bfd3b7c37aaed877d84277ef88c9f504792f408ec6d287a0d8a06671154398965231f
7
- data.tar.gz: 2b8b0b0d0b1d4902b0ef7114b19adb8f31dd1206dc9185248f3008edb074f118976f56554f5b34689c43f3b12ef069ec2c5a773c9a50b1b16e84bffc4e00b3e3
6
+ metadata.gz: 892042e3683ca475e062e2439189dd9a17c3fd595eae0e86bb1f687111e6d8f158ff9d8fba034f5fabc8dd066f55289bf0dc0013e2330be59f9bcb764eacfeaa
7
+ data.tar.gz: e2a05da7f70a78c584f34b1b45ca3a8655f20437828be9462d0e83b87c73cb7389ad72081136929c989a34e572601d1bf0208208aa571e29794a7a4f503aab88
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.2.0 2021-01-07
4
+
5
+ * New metrics: old_workers (PR #[21](https://github.com/yob/puma-plugin-statsd/pull/21)) and requsts_count (PR #[28](https://github.com/yob/puma-plugin-statsd/pull/28))
6
+ * Require json at runtime to be extra sure we don't load the wrong version before bundler has initialised the LOAD_PATH
7
+
3
8
  ## 1.1.0 2021-01-03
4
9
 
5
10
  * Assume localhost for statsd host (PR #[20](https://github.com/yob/puma-plugin-statsd/pull/20))
@@ -1,5 +1,4 @@
1
1
  # coding: utf-8, frozen_string_literal: true
2
- require "json"
3
2
  require "puma"
4
3
  require "puma/plugin"
5
4
  require 'socket'
@@ -16,10 +15,6 @@ class StatsdConnector
16
15
  @port = ENV.fetch("STATSD_PORT", 8125)
17
16
  end
18
17
 
19
- def enabled?
20
- !!host
21
- end
22
-
23
18
  def send(metric_name:, value:, type:, tags: nil)
24
19
  data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}"
25
20
  data = "#{data}|##{tags}" unless tags.nil?
@@ -49,6 +44,10 @@ class PumaStats
49
44
  @stats.fetch(:booted_workers, 1)
50
45
  end
51
46
 
47
+ def old_workers
48
+ @stats.fetch(:old_workers, 0)
49
+ end
50
+
52
51
  def running
53
52
  if clustered?
54
53
  @stats[:worker_status].map { |s| s[:last_status].fetch(:running, 0) }.inject(0, &:+)
@@ -80,6 +79,14 @@ class PumaStats
80
79
  @stats.fetch(:max_threads, 0)
81
80
  end
82
81
  end
82
+
83
+ def requests_count
84
+ if clustered?
85
+ @stats[:worker_status].map { |s| s[:last_status].fetch(:requests_count, 0) }.inject(0, &:+)
86
+ else
87
+ @stats.fetch(:requests_count, 0)
88
+ end
89
+ end
83
90
  end
84
91
 
85
92
  Puma::Plugin.create do
@@ -88,19 +95,15 @@ Puma::Plugin.create do
88
95
  @launcher = launcher
89
96
 
90
97
  @statsd = ::StatsdConnector.new
91
- if @statsd.enabled?
92
- @launcher.events.debug "statsd: enabled (host: #{@statsd.host})"
93
-
94
- # Fetch global metric prefix from env variable
95
- @metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
96
- if @metric_prefix && !@metric_prefix.end_with?(::StatsdConnector::METRIC_DELIMETER)
97
- @metric_prefix += ::StatsdConnector::METRIC_DELIMETER
98
- end
98
+ @launcher.events.debug "statsd: enabled (host: #{@statsd.host})"
99
99
 
100
- register_hooks
101
- else
102
- @launcher.events.debug "statsd: not enabled (no #{StatsdConnector::ENV_NAME} env var found)"
100
+ # Fetch global metric prefix from env variable
101
+ @metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
102
+ if @metric_prefix && !@metric_prefix.end_with?(::StatsdConnector::METRIC_DELIMETER)
103
+ @metric_prefix += ::StatsdConnector::METRIC_DELIMETER
103
104
  end
105
+
106
+ register_hooks
104
107
  end
105
108
 
106
109
  private
@@ -115,6 +118,7 @@ Puma::Plugin.create do
115
118
  end
116
119
  else
117
120
  def fetch_stats
121
+ require "json"
118
122
  stats = Puma.stats
119
123
  JSON.parse(stats, symbolize_names: true)
120
124
  end
@@ -170,10 +174,12 @@ Puma::Plugin.create do
170
174
  stats = ::PumaStats.new(fetch_stats)
171
175
  @statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
172
176
  @statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers, type: :gauge, tags: tags)
177
+ @statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge, tags: tags)
173
178
  @statsd.send(metric_name: prefixed_metric_name("puma.running"), value: stats.running, type: :gauge, tags: tags)
174
179
  @statsd.send(metric_name: prefixed_metric_name("puma.backlog"), value: stats.backlog, type: :gauge, tags: tags)
175
180
  @statsd.send(metric_name: prefixed_metric_name("puma.pool_capacity"), value: stats.pool_capacity, type: :gauge, tags: tags)
176
181
  @statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge, tags: tags)
182
+ @statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count, type: :gauge, tags: tags)
177
183
  rescue StandardError => e
178
184
  @launcher.events.error "! statsd: notify stats failed:\n #{e.to_s}\n #{e.backtrace.join("\n ")}"
179
185
  ensure
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: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -114,7 +114,7 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
- description:
117
+ description:
118
118
  email: james@yob.id.au
119
119
  executables: []
120
120
  extensions: []
@@ -128,7 +128,7 @@ homepage: https://github.com/yob/puma-plugin-statsd
128
128
  licenses:
129
129
  - MIT
130
130
  metadata: {}
131
- post_install_message:
131
+ post_install_message:
132
132
  rdoc_options: []
133
133
  require_paths:
134
134
  - lib
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.2.3
147
- signing_key:
146
+ rubygems_version: 3.0.3
147
+ signing_key:
148
148
  specification_version: 4
149
149
  summary: Send puma metrics to statsd via a background thread
150
150
  test_files: []