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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 155fc63d4aeb44adff94d1aecceee4458c4829d68ad0da1a7db10566e9c8d646
4
- data.tar.gz: fdea125242151b6abf868cd74f163f84560d10d8825356f8ce718d7d5582967c
3
+ metadata.gz: 61b91a8a6e85cc308cb83a047ddbf958a2529363433689f3b7a407658982c9aa
4
+ data.tar.gz: d62ab03d1fe3c20dc13a395ba84fa5fe035183f17dec401a85217a20221a43b5
5
5
  SHA512:
6
- metadata.gz: c8b63db9c3d6b63fa40c0709712e1cd4c1aa028d662976428089eefee6c48c597a1e84d602dce442e0899c6796cec21e2c179d1eec1331b4b3012b7c4036dbdc
7
- data.tar.gz: cab4e1f32c8db8a434beeac2a0e83c66d385ebd2e85d1dde1cdfeb7ee93392d51791d41bc790f9df84c36f041c1879e74607122c0d9d2a1072dfa1cf80596ee3
6
+ metadata.gz: '09e931680b3c4280e1764fc9738ab69e7b0af6c0705eb02d52edc6ba9df69d227293075d77abbedb8e794337e99ae3d048abe8f76413ec9ed02a7c526494fe3c'
7
+ data.tar.gz: 6eb107be17c9b457dc0c7bb900867dab42dcd50fd49e27df919e6268e648a6a0c858a422f9545d9280e001f825db0ceb0eae4a333b705adc5ccb5b3c25f4b0e8
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.0 2020-11-03
4
+
5
+ * Added option to specify arbitrary datadog tags (PR #[18](https://github.com/yob/puma-plugin-statsd/pull/18))
6
+
3
7
  ## 0.3.0 2020-09-24
4
8
 
5
9
  * Support puma 5.x
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 two environment variables.
56
+ tags via the following three environment variables.
57
57
 
58
- `MY_POD_NAME` adds a `pod_name` tag to the metrics. The `MY_POD_NAME`
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
- `STATSD_GROUPING` adds a `grouping` tag to the metrics, with a value equal to
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
 
@@ -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
- if tags.any?
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 tags
127
- tags = {}
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[:pod_name] = ENV.fetch("MY_POD_NAME", "no_pod")
133
+ tags << "pod_name:#{ENV['MY_POD_NAME']}"
130
134
  end
135
+
131
136
  if ENV.has_key?("STATSD_GROUPING")
132
- tags[:grouping] = ENV.fetch("STATSD_GROUPING", "no-group")
137
+ tags << "grouping:#{ENV['STATSD_GROUPING']}"
133
138
  end
134
- tags
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.3.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-09-24 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma