puma-plugin-statsd 1.2.1 → 2.2.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 +15 -1
- data/README.md +13 -3
- data/bin/statsd-to-stdout +15 -0
- data/lib/puma/plugin/statsd.rb +28 -17
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 359b3281a2ce1173373bba01c4ca0981772d63af2719daead709efb87b0f19bd
|
4
|
+
data.tar.gz: 2b11561ad00b73a80c8cea674fad5bce390a9e384169f68bb77f0445b006d8b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c5da2367dfa0d796258d9d8ecda4a70d4225946669e4ad30aefd4196c86f3b03f3fd99894dc5cbc55afede49b2559bbaac5217f4b9b97622ab0c4105dd0d5f5
|
7
|
+
data.tar.gz: be824e394c2b04ad4f6e80a32db242e2a3e74db512b8ec3720a41a1e3ba1ca45dd2e0221a951b71f8c6e2c8a90e2fc03b63dd865e0f63978c5f1b4eb9ff816b1
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.2.0 2022-07-31
|
4
|
+
|
5
|
+
* Support communicating with the Datadog agent via a UNIX socket (set STATSD_SOCKET_PATH env var) (PR #[38](https://github.com/yob/puma-plugin-statsd/pull/38))
|
6
|
+
|
7
|
+
## 2.1.0 2021-12-04
|
8
|
+
|
9
|
+
* Adds support for Datadog unified service tagging (env, service, version) (PR #[37](https://github.com/yob/puma-plugin-statsd/pull/37))
|
10
|
+
|
11
|
+
## 2.0.0 2021-07-27
|
12
|
+
|
13
|
+
* Require puma 5 or better
|
14
|
+
* Split DD_TAGS environment variable by commas or spaces (PR #[31](https://github.com/yob/puma-plugin-statsd/pull/31))
|
15
|
+
* Gracefully handle unexpected errors when submitting to statsd (like DNS resolution failures) (PR #[35](https://github.com/yob/puma-plugin-statsd/pull/35))
|
16
|
+
|
3
17
|
## 1.2.1 2021-01-11
|
4
18
|
|
5
19
|
* Remove json from the gemspec
|
6
20
|
|
7
21
|
## 1.2.0 2021-01-07
|
8
22
|
|
9
|
-
* New metrics: old_workers (PR #[21](https://github.com/yob/puma-plugin-statsd/pull/21)) and
|
23
|
+
* New metrics: old_workers (PR #[21](https://github.com/yob/puma-plugin-statsd/pull/21)) and requests_count (PR #[28](https://github.com/yob/puma-plugin-statsd/pull/28))
|
10
24
|
* Require json at runtime to be extra sure we don't load the wrong version before bundler has initialised the LOAD_PATH
|
11
25
|
|
12
26
|
## 1.1.0 2021-01-03
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Puma Statsd Plugin
|
2
2
|
|
3
|
-
[Puma][puma] integration with [statsd]
|
3
|
+
[Puma][puma] integration with [statsd][statsd] for easy tracking of key metrics
|
4
4
|
that puma can provide:
|
5
5
|
|
6
6
|
* puma.workers
|
@@ -9,6 +9,8 @@ that puma can provide:
|
|
9
9
|
* puma.backlog
|
10
10
|
* puma.pool_capacity
|
11
11
|
* puma.max_threads
|
12
|
+
* puma.old_workers
|
13
|
+
* puma.requests_count
|
12
14
|
|
13
15
|
[puma]: https://github.com/puma/puma
|
14
16
|
[statsd]: https://github.com/etsy/statsd
|
@@ -108,9 +110,17 @@ https://github.com/yob/puma-plugin-statsd.
|
|
108
110
|
|
109
111
|
## Testing the data being sent to statsd
|
110
112
|
|
111
|
-
Start a pretend statsd server that listens for UDP packets on port 8125
|
113
|
+
Start a pretend statsd server that listens for UDP packets on port 8125.
|
112
114
|
|
113
|
-
|
115
|
+
If you've installed the gem in your app:
|
116
|
+
|
117
|
+
# only need to install the binstub once
|
118
|
+
bundle binstubs puma-plugin-statsd
|
119
|
+
./bin/statsd-to-stdout
|
120
|
+
|
121
|
+
If you are developing/testing this gem locally:
|
122
|
+
|
123
|
+
./bin/statsd-to-stdout
|
114
124
|
|
115
125
|
Start puma:
|
116
126
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
RECV_BUFFER = 64*1024
|
5
|
+
|
6
|
+
require 'socket'
|
7
|
+
server = UDPSocket.new
|
8
|
+
host, port = "127.0.0.1", 8125
|
9
|
+
server.bind(host, port)
|
10
|
+
|
11
|
+
while true
|
12
|
+
text, sender = server.recvfrom(RECV_BUFFER)
|
13
|
+
remote_host = sender[3]
|
14
|
+
STDOUT.puts "#{remote_host}:" + text
|
15
|
+
end
|
data/lib/puma/plugin/statsd.rb
CHANGED
@@ -13,14 +13,21 @@ class StatsdConnector
|
|
13
13
|
def initialize
|
14
14
|
@host = ENV.fetch(ENV_NAME, "127.0.0.1")
|
15
15
|
@port = ENV.fetch("STATSD_PORT", 8125)
|
16
|
+
@socket_path = ENV.fetch("STATSD_SOCKET_PATH", nil)
|
16
17
|
end
|
17
18
|
|
18
19
|
def send(metric_name:, value:, type:, tags: nil)
|
19
20
|
data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}"
|
20
21
|
data = "#{data}|##{tags}" unless tags.nil?
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
if @socket_path
|
24
|
+
socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM)
|
25
|
+
socket.connect(Socket.pack_sockaddr_un(@socket_path))
|
26
|
+
socket.sendmsg_nonblock(data)
|
27
|
+
else
|
28
|
+
socket = UDPSocket.new
|
29
|
+
socket.send(data, 0, host, port)
|
30
|
+
end
|
24
31
|
ensure
|
25
32
|
socket.close
|
26
33
|
end
|
@@ -112,18 +119,6 @@ Puma::Plugin.create do
|
|
112
119
|
in_background(&method(:stats_loop))
|
113
120
|
end
|
114
121
|
|
115
|
-
if Puma.respond_to?(:stats_hash)
|
116
|
-
def fetch_stats
|
117
|
-
Puma.stats_hash
|
118
|
-
end
|
119
|
-
else
|
120
|
-
def fetch_stats
|
121
|
-
require "json"
|
122
|
-
stats = Puma.stats
|
123
|
-
JSON.parse(stats, symbolize_names: true)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
122
|
def environment_variable_tags
|
128
123
|
# Tags are separated by spaces, and while they are normally a tag and
|
129
124
|
# value separated by a ':', they can also just be tagged without any
|
@@ -147,11 +142,27 @@ Puma::Plugin.create do
|
|
147
142
|
# https://docs.datadoghq.com/agent/docker/?tab=standard#global-options
|
148
143
|
#
|
149
144
|
if ENV.has_key?("DD_TAGS")
|
150
|
-
ENV["DD_TAGS"].split(/\s
|
145
|
+
ENV["DD_TAGS"].split(/\s+|,/).each do |t|
|
151
146
|
tags << t
|
152
147
|
end
|
153
148
|
end
|
154
149
|
|
150
|
+
# Support the Unified Service Tagging from Datadog, so that we can share
|
151
|
+
# the metric tags with the application running
|
152
|
+
#
|
153
|
+
# https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging
|
154
|
+
if ENV.has_key?("DD_ENV")
|
155
|
+
tags << "env:#{ENV["DD_ENV"]}"
|
156
|
+
end
|
157
|
+
|
158
|
+
if ENV.has_key?("DD_SERVICE")
|
159
|
+
tags << "service:#{ENV["DD_SERVICE"]}"
|
160
|
+
end
|
161
|
+
|
162
|
+
if ENV.has_key?("DD_VERSION")
|
163
|
+
tags << "version:#{ENV["DD_VERSION"]}"
|
164
|
+
end
|
165
|
+
|
155
166
|
# Return nil if we have no environment variable tags. This way we don't
|
156
167
|
# send an unnecessary '|' on the end of each stat
|
157
168
|
return nil if tags.empty?
|
@@ -171,7 +182,7 @@ Puma::Plugin.create do
|
|
171
182
|
loop do
|
172
183
|
@launcher.events.debug "statsd: notify statsd"
|
173
184
|
begin
|
174
|
-
stats = ::PumaStats.new(
|
185
|
+
stats = ::PumaStats.new(Puma.stats_hash)
|
175
186
|
@statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
|
176
187
|
@statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers, type: :gauge, tags: tags)
|
177
188
|
@statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge, tags: tags)
|
@@ -181,7 +192,7 @@ Puma::Plugin.create do
|
|
181
192
|
@statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge, tags: tags)
|
182
193
|
@statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count, type: :gauge, tags: tags)
|
183
194
|
rescue StandardError => e
|
184
|
-
@launcher.events.
|
195
|
+
@launcher.events.unknown_error e, nil, "! statsd: notify stats failed"
|
185
196
|
ensure
|
186
197
|
sleep 2
|
187
198
|
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:
|
4
|
+
version: 2.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:
|
11
|
+
date: 2022-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '6'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '6'
|
@@ -100,21 +100,23 @@ dependencies:
|
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
-
description:
|
103
|
+
description:
|
104
104
|
email: james@yob.id.au
|
105
|
-
executables:
|
105
|
+
executables:
|
106
|
+
- statsd-to-stdout
|
106
107
|
extensions: []
|
107
108
|
extra_rdoc_files: []
|
108
109
|
files:
|
109
110
|
- CHANGELOG.md
|
110
111
|
- MIT-LICENSE
|
111
112
|
- README.md
|
113
|
+
- bin/statsd-to-stdout
|
112
114
|
- lib/puma/plugin/statsd.rb
|
113
115
|
homepage: https://github.com/yob/puma-plugin-statsd
|
114
116
|
licenses:
|
115
117
|
- MIT
|
116
118
|
metadata: {}
|
117
|
-
post_install_message:
|
119
|
+
post_install_message:
|
118
120
|
rdoc_options: []
|
119
121
|
require_paths:
|
120
122
|
- lib
|
@@ -129,8 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
131
|
- !ruby/object:Gem::Version
|
130
132
|
version: '0'
|
131
133
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
133
|
-
signing_key:
|
134
|
+
rubygems_version: 3.3.7
|
135
|
+
signing_key:
|
134
136
|
specification_version: 4
|
135
137
|
summary: Send puma metrics to statsd via a background thread
|
136
138
|
test_files: []
|