puma-newrelic-codeur 0.1.8 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/puma/newrelic/plugin.rb +1 -1
- data/lib/puma/newrelic/sampler.rb +15 -25
- data/lib/puma/newrelic/version.rb +1 -1
- 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: 4cdfae9d5d6d6cf2b3815c9f5a29eb6fed99a2281e3b82892124c18d42bb4ea9
|
4
|
+
data.tar.gz: afc6ed3b9a9d4f5d36549759f02044e76a837e3c1d4ed4a184c5e27c43ab1370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b28d5e8296a5588db4a7abd4f5d5072283a0cd44770043566e4a14c0675aabc0adcf1d71a0c11178d4ab0ec1af53076091389b1ea6e9133b21c9530c6d2b2b5
|
7
|
+
data.tar.gz: 6ad9f1b689e46d269249e8f8beea0d1477da24b702931a856011f8774291fcde5918670b3c3576b681c27a4f092d176908f07e72736f4df1cfa94929b206970e
|
data/README.md
CHANGED
data/lib/puma/newrelic/plugin.rb
CHANGED
@@ -6,27 +6,19 @@ module Puma
|
|
6
6
|
def initialize(launcher)
|
7
7
|
config = ::NewRelic::Agent.config[:puma] || {}
|
8
8
|
@launcher = launcher
|
9
|
-
@sample_rate = config.fetch("sample_rate",
|
10
|
-
@keys = config.fetch("keys", %
|
9
|
+
@sample_rate = config.fetch("sample_rate", 23)
|
10
|
+
@keys = config.fetch("keys", %i[backlog running pool_capacity max_threads requests_count]).map(&:to_sym)
|
11
11
|
@last_sample_at = Time.now
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def collect
|
15
15
|
@running = true
|
16
16
|
while @running
|
17
17
|
sleep 1
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if puma_stats.is_a?(Hash)
|
23
|
-
parse puma_stats
|
24
|
-
else
|
25
|
-
parse JSON.parse(puma_stats, symbolize_names: true)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
rescue Exception => e # rubocop:disable Lint/RescueException
|
29
|
-
::NewRelic::Agent.logger.error(e.message)
|
18
|
+
|
19
|
+
if should_sample?
|
20
|
+
record_metrics(@launcher.stats)
|
21
|
+
@last_sample_at = Time.now
|
30
22
|
end
|
31
23
|
end
|
32
24
|
end
|
@@ -39,23 +31,21 @@ module Puma
|
|
39
31
|
@running = false
|
40
32
|
end
|
41
33
|
|
42
|
-
def
|
34
|
+
def record_metrics(stats)
|
43
35
|
metrics = Hash.new { |h, k| h[k] = 0 }
|
44
36
|
|
45
|
-
if stats[:
|
46
|
-
metrics[:
|
37
|
+
if stats[:worker_status] # Cluster mode
|
38
|
+
metrics[:workers_count] = stats[:workers]
|
47
39
|
stats[:worker_status].each do |worker|
|
48
|
-
worker[:last_status].each { |key, value| metrics[key
|
40
|
+
worker[:last_status].each { |key, value| metrics[key] += value if @keys.include?(key) }
|
49
41
|
end
|
50
|
-
else
|
51
|
-
|
42
|
+
else # Single mode
|
43
|
+
metrics[:workers_count] = 1
|
44
|
+
stats.each { |key, value| metrics[key] += value if @keys.include?(key) }
|
52
45
|
end
|
53
|
-
report_metrics(metrics)
|
54
|
-
end
|
55
46
|
|
56
|
-
def report_metrics(metrics)
|
57
47
|
metrics.each do |key, value|
|
58
|
-
::NewRelic::Agent.logger.
|
48
|
+
::NewRelic::Agent.logger.info("Recorded metric: Custom/Puma/#{key}=#{value}")
|
59
49
|
::NewRelic::Agent.record_metric("Custom/Puma/#{key}", value)
|
60
50
|
end
|
61
51
|
end
|