puma-plugin-statsd 1.0.0 → 2.0.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 +19 -0
- data/README.md +16 -5
- data/bin/statsd-to-stdout +15 -0
- data/lib/puma/plugin/statsd.rb +25 -31
- metadata +7 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ac5651e242dcf306ed0c5964de2c7178a142e9555333cfd203e043dada926a6
|
4
|
+
data.tar.gz: 9cc7a3b70cdcda54a824ca4d9b65714c16f7b20834bb348182eb787820b5e5e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1222d6580444972583bec535348958301a8c5aa4860d08e87bb1e735fc09d9b2764a38b4c3b9aa355878b9080ca30ef80b413c55c0f8f4b97edf750515162a89
|
7
|
+
data.tar.gz: 07e8987c8ce8f8f3db573241f824c80224aec9ffa2f5b1e8bbd474105981d6529c0c1a4a870995622f62c9edad1181aaced6c3382b8746aebf9149f51d0842c9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.0.0 2021-07-27
|
4
|
+
|
5
|
+
* Require puma 5 or better
|
6
|
+
* Split DD_TAGS environment variable by commas or spaces (PR #[31](https://github.com/yob/puma-plugin-statsd/pull/31))
|
7
|
+
* Gracefully handle unexpecte errors when submitting to statsd (like DNS resolution failures) (PR #[35](https://github.com/yob/puma-plugin-statsd/pull/35))
|
8
|
+
|
9
|
+
## 1.2.1 2021-01-11
|
10
|
+
|
11
|
+
* Remove json from the gemspec
|
12
|
+
|
13
|
+
## 1.2.0 2021-01-07
|
14
|
+
|
15
|
+
* 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))
|
16
|
+
* Require json at runtime to be extra sure we don't load the wrong version before bundler has initialised the LOAD_PATH
|
17
|
+
|
18
|
+
## 1.1.0 2021-01-03
|
19
|
+
|
20
|
+
* Assume localhost for statsd host (PR #[20](https://github.com/yob/puma-plugin-statsd/pull/20))
|
21
|
+
|
3
22
|
## 1.0.0 2020-11-03
|
4
23
|
|
5
24
|
* Added option to specify arbitrary datadog tags (PR #[18](https://github.com/yob/puma-plugin-statsd/pull/18))
|
data/README.md
CHANGED
@@ -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
|
@@ -37,12 +39,14 @@ plugin :statsd
|
|
37
39
|
|
38
40
|
## Usage
|
39
41
|
|
40
|
-
|
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:
|
41
43
|
|
42
44
|
```
|
43
|
-
|
45
|
+
bundle exec puma
|
44
46
|
```
|
45
47
|
|
48
|
+
If statsd isn't on 127.0.0.1 or the port is non-standard, you can configure them using optional environment variables:
|
49
|
+
|
46
50
|
```
|
47
51
|
STATSD_HOST=127.0.0.1 STATSD_PORT=9125 bundle exec puma
|
48
52
|
```
|
@@ -55,7 +59,6 @@ the datadog "dogstatsd" server.
|
|
55
59
|
Should you be reporting the puma metrics to a dogstatsd server, you can set
|
56
60
|
tags via the following three environment variables.
|
57
61
|
|
58
|
-
|
59
62
|
#### DD_TAGS
|
60
63
|
|
61
64
|
`DD_TAGS`: Set this to a space-separated list of tags, using the
|
@@ -107,9 +110,17 @@ https://github.com/yob/puma-plugin-statsd.
|
|
107
110
|
|
108
111
|
## Testing the data being sent to statsd
|
109
112
|
|
110
|
-
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.
|
114
|
+
|
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:
|
111
122
|
|
112
|
-
|
123
|
+
./bin/statsd-to-stdout
|
113
124
|
|
114
125
|
Start puma:
|
115
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
@@ -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'
|
@@ -12,14 +11,10 @@ class StatsdConnector
|
|
12
11
|
attr_reader :host, :port
|
13
12
|
|
14
13
|
def initialize
|
15
|
-
@host = ENV.fetch(ENV_NAME,
|
14
|
+
@host = ENV.fetch(ENV_NAME, "127.0.0.1")
|
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
|
-
|
92
|
-
@launcher.events.debug "statsd: enabled (host: #{@statsd.host})"
|
98
|
+
@launcher.events.debug "statsd: enabled (host: #{@statsd.host})"
|
93
99
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
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
|
@@ -109,17 +112,6 @@ Puma::Plugin.create do
|
|
109
112
|
in_background(&method(:stats_loop))
|
110
113
|
end
|
111
114
|
|
112
|
-
if Puma.respond_to?(:stats_hash)
|
113
|
-
def fetch_stats
|
114
|
-
Puma.stats_hash
|
115
|
-
end
|
116
|
-
else
|
117
|
-
def fetch_stats
|
118
|
-
stats = Puma.stats
|
119
|
-
JSON.parse(stats, symbolize_names: true)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
115
|
def environment_variable_tags
|
124
116
|
# Tags are separated by spaces, and while they are normally a tag and
|
125
117
|
# value separated by a ':', they can also just be tagged without any
|
@@ -143,7 +135,7 @@ Puma::Plugin.create do
|
|
143
135
|
# https://docs.datadoghq.com/agent/docker/?tab=standard#global-options
|
144
136
|
#
|
145
137
|
if ENV.has_key?("DD_TAGS")
|
146
|
-
ENV["DD_TAGS"].split(/\s
|
138
|
+
ENV["DD_TAGS"].split(/\s+|,/).each do |t|
|
147
139
|
tags << t
|
148
140
|
end
|
149
141
|
end
|
@@ -167,15 +159,17 @@ Puma::Plugin.create do
|
|
167
159
|
loop do
|
168
160
|
@launcher.events.debug "statsd: notify statsd"
|
169
161
|
begin
|
170
|
-
stats = ::PumaStats.new(
|
162
|
+
stats = ::PumaStats.new(Puma.stats_hash)
|
171
163
|
@statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
|
172
164
|
@statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers, type: :gauge, tags: tags)
|
165
|
+
@statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge, tags: tags)
|
173
166
|
@statsd.send(metric_name: prefixed_metric_name("puma.running"), value: stats.running, type: :gauge, tags: tags)
|
174
167
|
@statsd.send(metric_name: prefixed_metric_name("puma.backlog"), value: stats.backlog, type: :gauge, tags: tags)
|
175
168
|
@statsd.send(metric_name: prefixed_metric_name("puma.pool_capacity"), value: stats.pool_capacity, type: :gauge, tags: tags)
|
176
169
|
@statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge, tags: tags)
|
170
|
+
@statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count, type: :gauge, tags: tags)
|
177
171
|
rescue StandardError => e
|
178
|
-
@launcher.events.
|
172
|
+
@launcher.events.unknown_error e, nil, "! statsd: notify stats failed"
|
179
173
|
ensure
|
180
174
|
sleep 2
|
181
175
|
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.0.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: 2021-07-27 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,24 +26,10 @@ 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'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: json
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
33
|
- !ruby/object:Gem::Dependency
|
48
34
|
name: bundler
|
49
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,13 +102,15 @@ dependencies:
|
|
116
102
|
version: '0'
|
117
103
|
description:
|
118
104
|
email: james@yob.id.au
|
119
|
-
executables:
|
105
|
+
executables:
|
106
|
+
- statsd-to-stdout
|
120
107
|
extensions: []
|
121
108
|
extra_rdoc_files: []
|
122
109
|
files:
|
123
110
|
- CHANGELOG.md
|
124
111
|
- MIT-LICENSE
|
125
112
|
- README.md
|
113
|
+
- bin/statsd-to-stdout
|
126
114
|
- lib/puma/plugin/statsd.rb
|
127
115
|
homepage: https://github.com/yob/puma-plugin-statsd
|
128
116
|
licenses:
|