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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e195287b18055147b79b50cc78d44befa3c7b40ea72cc24cde2c69b9a67d546
4
- data.tar.gz: ccdcf8d5f9f7cadd582cf8890240ed9d4d6898847bcd7287f99161646f5b6fb8
3
+ metadata.gz: 86e38d20e90900400c14892d926996fc6aa4855a8c39873eb9e981cc2e6c8dba
4
+ data.tar.gz: a60b4374d783ad880dfa012d4745df4407ce0345fc3fdedc6677ca874fddc79b
5
5
  SHA512:
6
- metadata.gz: dfe22844effa9205d4e819d9b450cd35abdb57f7af1ee88a42fb04c1781f6b2b1554e19fc91b2019c192c439a1eae6bba056c69db20db6f19fc70a3fd18a6781
7
- data.tar.gz: 385b990229ef0eeb227fc0f32154af04a325c34dfff661ac94494306232c9ec8fbc2c8bfd9a5c989dcff6cefce9159627079f68f70ddb610d1c1c1ed1a0b4bdf
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 'newrelic'` to your puma.rb
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:
@@ -1,9 +1,8 @@
1
1
  require_relative "sampler"
2
- require "puma/plugin"
3
2
 
4
3
  module Puma
5
4
  module NewRelic
6
- class Plugin < Puma::Plugin
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.start
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", 15)
10
- @keys = config.fetch("keys", %w[backlog running pool_capacity max_threads]).map(&:to_s)
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 start
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
- if puma_stats.is_a?(Hash)
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 parse(stats)
38
+ def record_metrics(stats)
43
39
  metrics = Hash.new { |h, k| h[k] = 0 }
44
40
 
45
- if stats[:workers]
46
- metrics[:workers] = stats[:workers]
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.to_s] += value if @keys.include?(key.to_s) }
44
+ worker[:last_status].each { |key, value| metrics[key] += value if @keys.include?(key) }
49
45
  end
50
- else
51
- stats.each { |key, value| metrics[key.to_s] += value if @keys.include?(key.to_s) }
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)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Puma
4
4
  module NewRelic
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.9"
6
6
  end
7
7
  end
data/lib/puma/newrelic.rb CHANGED
@@ -1,12 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "newrelic/version"
4
-
5
- module Puma
6
- module NewRelic
7
- class Error < StandardError; end
8
- # Your code goes here...
9
- end
10
- end
11
-
12
- require_relative "newrelic/plugin"
@@ -0,0 +1,5 @@
1
+ require_relative "../newrelic/plugin"
2
+
3
+ Puma::Plugin.create do
4
+ include Puma::NewRelic::Plugin
5
+ end
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.7
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