puma-plugin-statsd 0.3.0 → 1.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 +4 -0
- data/README.md +23 -5
- data/lib/puma/plugin/statsd.rb +33 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61b91a8a6e85cc308cb83a047ddbf958a2529363433689f3b7a407658982c9aa
|
4
|
+
data.tar.gz: d62ab03d1fe3c20dc13a395ba84fa5fe035183f17dec401a85217a20221a43b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09e931680b3c4280e1764fc9738ab69e7b0af6c0705eb02d52edc6ba9df69d227293075d77abbedb8e794337e99ae3d048abe8f76413ec9ed02a7c526494fe3c'
|
7
|
+
data.tar.gz: 6eb107be17c9b457dc0c7bb900867dab42dcd50fd49e27df919e6268e648a6a0c858a422f9545d9280e001f825db0ceb0eae4a333b705adc5ccb5b3c25f4b0e8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -37,7 +37,7 @@ plugin :statsd
|
|
37
37
|
|
38
38
|
## Usage
|
39
39
|
|
40
|
-
Ensure you have an environment variable set that points to a statsd host, then boot your puma app as usual. Optionally you may specify a port (default is 8125).
|
40
|
+
Ensure you have an environment variable set that points to a statsd host, then boot your puma app as usual. Optionally you may specify a port (default is 8125).
|
41
41
|
|
42
42
|
```
|
43
43
|
STATSD_HOST=127.0.0.1 bundle exec puma
|
@@ -53,9 +53,25 @@ metric tags are a non-standard addition to the statsd protocol, supported by
|
|
53
53
|
the datadog "dogstatsd" server.
|
54
54
|
|
55
55
|
Should you be reporting the puma metrics to a dogstatsd server, you can set
|
56
|
-
tags via the following
|
56
|
+
tags via the following three environment variables.
|
57
57
|
|
58
|
-
|
58
|
+
|
59
|
+
#### DD_TAGS
|
60
|
+
|
61
|
+
`DD_TAGS`: Set this to a space-separated list of tags, using the
|
62
|
+
[datadog agent standard format](https://docs.datadoghq.com/agent/docker/?tab=standard#global-options).
|
63
|
+
|
64
|
+
For example, you could set this environment variable to set three datadog tags,
|
65
|
+
and then you can filter by in the datadog interface:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
export DD_TAGS="env:test simple-tag-0 tag-key-1:tag-value-1"
|
69
|
+
bundle exec rails server
|
70
|
+
```
|
71
|
+
|
72
|
+
#### MY_POD_NAME
|
73
|
+
|
74
|
+
`MY_POD_NAME`: Set a `pod_name` tag to the metrics. The `MY_POD_NAME`
|
59
75
|
environment variable is recommended in the datadog kubernetes setup
|
60
76
|
documentation, and for puma apps deployed to kubernetes it's very helpful to
|
61
77
|
have the option to report on specific pods.
|
@@ -70,7 +86,9 @@ env:
|
|
70
86
|
fieldPath: metadata.name
|
71
87
|
```
|
72
88
|
|
73
|
-
|
89
|
+
#### STATSD_GROUPING
|
90
|
+
|
91
|
+
`STATSD_GROUPING`: add a `grouping` tag to the metrics, with a value equal to
|
74
92
|
the environment variable value. This is particularly helpful in a kubernetes
|
75
93
|
deployment where each pod has a unique name but you want the option to group
|
76
94
|
metrics across all pods in a deployment. Setting this on the pods in a
|
@@ -100,7 +118,7 @@ Start puma:
|
|
100
118
|
Throw some traffic at it, either with curl or a tool like ab:
|
101
119
|
|
102
120
|
curl http://127.0.0.1:9292/
|
103
|
-
ab -n 10000 -c 20 http://127.0.0.1:9292/
|
121
|
+
ab -n 10000 -c 20 http://127.0.0.1:9292/
|
104
122
|
|
105
123
|
Watch the output of the UDP server process - you should see statsd data printed to stdout.
|
106
124
|
|
data/lib/puma/plugin/statsd.rb
CHANGED
@@ -20,12 +20,9 @@ class StatsdConnector
|
|
20
20
|
!!host
|
21
21
|
end
|
22
22
|
|
23
|
-
def send(metric_name:, value:, type:, tags:
|
23
|
+
def send(metric_name:, value:, type:, tags: nil)
|
24
24
|
data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}"
|
25
|
-
|
26
|
-
tag_str = tags.map { |k,v| "#{k}:#{v}" }.join(",")
|
27
|
-
data = "#{data}|##{tag_str}"
|
28
|
-
end
|
25
|
+
data = "#{data}|##{tags}" unless tags.nil?
|
29
26
|
|
30
27
|
socket = UDPSocket.new
|
31
28
|
socket.send(data, 0, host, port)
|
@@ -123,15 +120,39 @@ Puma::Plugin.create do
|
|
123
120
|
end
|
124
121
|
end
|
125
122
|
|
126
|
-
def
|
127
|
-
|
123
|
+
def environment_variable_tags
|
124
|
+
# Tags are separated by spaces, and while they are normally a tag and
|
125
|
+
# value separated by a ':', they can also just be tagged without any
|
126
|
+
# associated value.
|
127
|
+
#
|
128
|
+
# Examples: simple-tag-0 tag-key-1:tag-value-1
|
129
|
+
#
|
130
|
+
tags = []
|
131
|
+
|
128
132
|
if ENV.has_key?("MY_POD_NAME")
|
129
|
-
tags
|
133
|
+
tags << "pod_name:#{ENV['MY_POD_NAME']}"
|
130
134
|
end
|
135
|
+
|
131
136
|
if ENV.has_key?("STATSD_GROUPING")
|
132
|
-
tags
|
137
|
+
tags << "grouping:#{ENV['STATSD_GROUPING']}"
|
133
138
|
end
|
134
|
-
|
139
|
+
|
140
|
+
# Standardised datadog tag attributes, so that we can share the metric
|
141
|
+
# tags with the application running
|
142
|
+
#
|
143
|
+
# https://docs.datadoghq.com/agent/docker/?tab=standard#global-options
|
144
|
+
#
|
145
|
+
if ENV.has_key?("DD_TAGS")
|
146
|
+
ENV["DD_TAGS"].split(/\s+/).each do |t|
|
147
|
+
tags << t
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Return nil if we have no environment variable tags. This way we don't
|
152
|
+
# send an unnecessary '|' on the end of each stat
|
153
|
+
return nil if tags.empty?
|
154
|
+
|
155
|
+
tags.join(",")
|
135
156
|
end
|
136
157
|
|
137
158
|
def prefixed_metric_name(puma_metric)
|
@@ -140,6 +161,8 @@ Puma::Plugin.create do
|
|
140
161
|
|
141
162
|
# Send data to statsd every few seconds
|
142
163
|
def stats_loop
|
164
|
+
tags = environment_variable_tags
|
165
|
+
|
143
166
|
sleep 5
|
144
167
|
loop do
|
145
168
|
@launcher.events.debug "statsd: notify statsd"
|
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: 0.
|
4
|
+
version: 1.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: 2020-
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|