puma-newrelic-codeur 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/puma/newrelic/plugin.rb +2 -5
- data/lib/puma/newrelic/sampler.rb +11 -17
- data/lib/puma/newrelic/version.rb +1 -1
- data/lib/puma/newrelic.rb +0 -9
- data/lib/puma/plugin/newrelic.rb +5 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86e38d20e90900400c14892d926996fc6aa4855a8c39873eb9e981cc2e6c8dba
|
4
|
+
data.tar.gz: a60b4374d783ad880dfa012d4745df4407ce0345fc3fdedc6677ca874fddc79b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a96d262daf04a941d94b01d768015c257d63e54deacd387a88cf8a18cedd4563485ebb5af69f64a419a18c99eccea4cb637a411a9fb1895ac2817b89f87084d
|
7
|
+
data.tar.gz: 15f0686657a50b46794fe6dafbf991a344a6d6f7a46f796325aee511ecede1e419276b8da8623e8cd12c30cf6dfaa872c7cefbaa1437ff4d7b9b6e391b1f9051
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ You can view the information in the NewRelic insights or in NewRelic One.
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'puma-newrelic'
|
12
|
+
gem 'puma-newrelic-codeur'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -18,12 +18,12 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install puma-newrelic
|
21
|
+
$ gem install puma-newrelic-codeur
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
- Install the gem
|
26
|
-
- Add `plugin
|
26
|
+
- Add `plugin :newrelic` to your puma.rb
|
27
27
|
- Create a dashboard on the NewRelic insights or NewRelic One
|
28
28
|
|
29
29
|
NQRL example:
|
data/lib/puma/newrelic/plugin.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require_relative "sampler"
|
2
|
-
require "puma/plugin"
|
3
2
|
|
4
3
|
module Puma
|
5
4
|
module NewRelic
|
6
|
-
|
5
|
+
module Plugin
|
7
6
|
def start(launcher)
|
8
7
|
sampler = Puma::NewRelic::Sampler.new(launcher)
|
9
8
|
launcher.events.register(:state) do |state|
|
@@ -13,11 +12,9 @@ module Puma
|
|
13
12
|
end
|
14
13
|
|
15
14
|
in_background do
|
16
|
-
sampler.
|
15
|
+
sampler.collect
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
|
-
Puma::Plugins.register "newrelic", Plugin
|
22
19
|
end
|
23
20
|
end
|
@@ -6,12 +6,12 @@ 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
|
@@ -19,11 +19,7 @@ module Puma
|
|
19
19
|
if should_sample?
|
20
20
|
@last_sample_at = Time.now
|
21
21
|
puma_stats = @launcher.stats
|
22
|
-
|
23
|
-
parse puma_stats
|
24
|
-
else
|
25
|
-
parse JSON.parse(puma_stats, symbolize_names: true)
|
26
|
-
end
|
22
|
+
record_metrics(puma_stats)
|
27
23
|
end
|
28
24
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
29
25
|
::NewRelic::Agent.logger.error(e.message)
|
@@ -39,21 +35,19 @@ module Puma
|
|
39
35
|
@running = false
|
40
36
|
end
|
41
37
|
|
42
|
-
def
|
38
|
+
def record_metrics(stats)
|
43
39
|
metrics = Hash.new { |h, k| h[k] = 0 }
|
44
40
|
|
45
|
-
if stats[:
|
46
|
-
metrics[:
|
41
|
+
if stats[:worker_status] # Cluster mode
|
42
|
+
metrics[:workers_count] = stats[:workers]
|
47
43
|
stats[:worker_status].each do |worker|
|
48
|
-
worker[:last_status].each { |key, value| metrics[key
|
44
|
+
worker[:last_status].each { |key, value| metrics[key] += value if @keys.include?(key) }
|
49
45
|
end
|
50
|
-
else
|
51
|
-
|
46
|
+
else # Single mode
|
47
|
+
metrics[:workers_count] = 1
|
48
|
+
stats.each { |key, value| metrics[key] += value if @keys.include?(key) }
|
52
49
|
end
|
53
|
-
report_metrics(metrics)
|
54
|
-
end
|
55
50
|
|
56
|
-
def report_metrics(metrics)
|
57
51
|
metrics.each do |key, value|
|
58
52
|
::NewRelic::Agent.logger.debug("Recorded metric: Custom/Puma/#{key}=#{value}")
|
59
53
|
::NewRelic::Agent.record_metric("Custom/Puma/#{key}", value)
|
data/lib/puma/newrelic.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-newrelic-codeur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoist Claassen
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/puma/newrelic/plugin.rb
|
58
58
|
- lib/puma/newrelic/sampler.rb
|
59
59
|
- lib/puma/newrelic/version.rb
|
60
|
+
- lib/puma/plugin/newrelic.rb
|
60
61
|
homepage: https://github.com/codeur/puma-newrelic
|
61
62
|
licenses:
|
62
63
|
- MIT
|