nexus_semantic_logger 1.12 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexus_semantic_logger/version.rb +2 -2
- data/lib/puma/plugin/nexus_puma_statsd.rb +13 -61
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 903718bb8acb37308fee8d2b0739ae7a708538a6372029d50f198229646cca93
|
4
|
+
data.tar.gz: 4c40fdfa07c84b82938b4ca185aec63840d35f86222fdd3cdf058a0e4c453c27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d30a09cc0440a01ea89fc0cc48e04e883ec955e05749c5b7b406dd2b1013dc540f1e9a2e2a95befba6f8248b2f970440bdb53ab28dce572fb6f2c45794cd3d1
|
7
|
+
data.tar.gz: 15ae5d8e3bfad2eab8f81649a27b2755a302f04e00eea1248738edba543ab2824d56bd6298608c13a1a7eb8953eac6bf88183fe8530fa6eacb753a351a4583eb
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module NexusSemanticLogger
|
3
|
-
# Leave this as 1.12 in order for CI process to replace with the tagged version.
|
4
|
-
VERSION = '1.12'
|
3
|
+
# Leave this as 1.12.1 in order for CI process to replace with the tagged version.
|
4
|
+
VERSION = '1.12.1'
|
5
5
|
end
|
@@ -2,40 +2,12 @@
|
|
2
2
|
require 'puma'
|
3
3
|
require 'puma/plugin'
|
4
4
|
require 'socket'
|
5
|
-
require 'nexus_semantic_logger
|
5
|
+
require 'nexus_semantic_logger'
|
6
6
|
|
7
7
|
# Forked from puma-plugin-statsd.
|
8
8
|
# Uses the same datadog settings as nexus_semantic_logger.
|
9
9
|
# To use, add to puma.rb:
|
10
10
|
# plugin :nexus_puma_statsd
|
11
|
-
class StatsdConnector
|
12
|
-
STATSD_TYPES = { count: 'c', gauge: 'g' }
|
13
|
-
METRIC_DELIMETER = "."
|
14
|
-
|
15
|
-
attr_reader :host, :port
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@host = ENV.fetch('DD_AGENT_HOST', '127.0.0.1')
|
19
|
-
@port = ENV.fetch('DD_STATSD_PORT', 8125)
|
20
|
-
@socket_path = ENV.fetch('DD_STATSD_SOCKET_PATH', '')
|
21
|
-
end
|
22
|
-
|
23
|
-
def send(metric_name:, value:, type:, tags: nil)
|
24
|
-
data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}"
|
25
|
-
data = "#{data}|##{tags}" unless tags.nil?
|
26
|
-
|
27
|
-
if @socket_path.to_s.strip.empty?
|
28
|
-
socket = UDPSocket.new
|
29
|
-
socket.send(data, 0, host, port)
|
30
|
-
else
|
31
|
-
socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM)
|
32
|
-
socket.connect(Socket.pack_sockaddr_un(@socket_path))
|
33
|
-
socket.sendmsg_nonblock(data)
|
34
|
-
end
|
35
|
-
ensure
|
36
|
-
socket.close
|
37
|
-
end
|
38
|
-
end
|
39
11
|
|
40
12
|
# Wrap puma's stats in a safe API
|
41
13
|
class PumaStats
|
@@ -111,14 +83,7 @@ Puma::Plugin.create do
|
|
111
83
|
@launcher.events
|
112
84
|
end
|
113
85
|
|
114
|
-
@statsd
|
115
|
-
@log_writer.debug("statsd: enabled (host: #{@statsd.host})")
|
116
|
-
|
117
|
-
# Fetch global metric prefix from env variable
|
118
|
-
@metric_prefix = ENV.fetch('DD_STATSD_METRIC_PREFIX', nil)
|
119
|
-
if @metric_prefix && !@metric_prefix.end_with?(::StatsdConnector::METRIC_DELIMETER)
|
120
|
-
@metric_prefix += ::StatsdConnector::METRIC_DELIMETER
|
121
|
-
end
|
86
|
+
@log_writer.debug('statsd: enabled')
|
122
87
|
|
123
88
|
register_hooks
|
124
89
|
end
|
@@ -137,8 +102,6 @@ Puma::Plugin.create do
|
|
137
102
|
# Examples: simple-tag-0 tag-key-1:tag-value-1
|
138
103
|
#
|
139
104
|
tags = []
|
140
|
-
global_tags = NexusSemanticLogger::DatadogSingleton.instance.global_tags
|
141
|
-
tags += global_tags unless global_tags.nil?
|
142
105
|
|
143
106
|
if ENV.key?('HOSTNAME')
|
144
107
|
tags << "pod_name:#{ENV['HOSTNAME']}"
|
@@ -179,15 +142,9 @@ Puma::Plugin.create do
|
|
179
142
|
tags << "dd.internal.entity_id:#{ENV['DD_ENTITY_ID']}"
|
180
143
|
end
|
181
144
|
|
182
|
-
# Return nil if we have no environment variable tags. This way we don't
|
183
|
-
# send an unnecessary '|' on the end of each stat
|
184
145
|
return nil if tags.empty?
|
185
146
|
|
186
|
-
tags
|
187
|
-
end
|
188
|
-
|
189
|
-
def prefixed_metric_name(puma_metric)
|
190
|
-
"#{@metric_prefix}#{puma_metric}"
|
147
|
+
tags
|
191
148
|
end
|
192
149
|
|
193
150
|
# Send data to statsd every few seconds
|
@@ -196,24 +153,19 @@ Puma::Plugin.create do
|
|
196
153
|
|
197
154
|
sleep(5)
|
198
155
|
loop do
|
199
|
-
@log_writer.debug(
|
156
|
+
@log_writer.debug('statsd: notify statsd')
|
200
157
|
begin
|
201
158
|
stats = ::PumaStats.new(Puma.stats_hash)
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
tags: tags)
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
tags: tags)
|
211
|
-
@statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge,
|
212
|
-
tags: tags)
|
213
|
-
@statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count,
|
214
|
-
type: :gauge, tags: tags)
|
159
|
+
NexusSemanticLogger.metrics.gauge('puma.workers', stats.workers, tags: tags)
|
160
|
+
NexusSemanticLogger.metrics.gauge('puma.booted_workers', stats.booted_workers, tags: tags)
|
161
|
+
NexusSemanticLogger.metrics.gauge('puma.old_workers', stats.old_workers, tags: tags)
|
162
|
+
NexusSemanticLogger.metrics.gauge('puma.running', stats.running, tags: tags)
|
163
|
+
NexusSemanticLogger.metrics.gauge('puma.backlog', stats.backlog, tags: tags)
|
164
|
+
NexusSemanticLogger.metrics.gauge('puma.pool_capacity', stats.pool_capacity, tags: tags)
|
165
|
+
NexusSemanticLogger.metrics.gauge('puma.max_threads', stats.max_threads, tags: tags)
|
166
|
+
NexusSemanticLogger.metrics.gauge('puma.requests_count', stats.requests_count, tags: tags)
|
215
167
|
rescue StandardError => e
|
216
|
-
@log_writer.unknown_error(e, nil,
|
168
|
+
@log_writer.unknown_error(e, nil, '! statsd: notify stats failed')
|
217
169
|
ensure
|
218
170
|
sleep(2)
|
219
171
|
end
|