barnes 0.0.6 → 0.0.7

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: 97d3166a629fda777aec68bbbd69e7dbe1c1581c248a2f3c27a1b5922c63855a
4
- data.tar.gz: cf23e7b64ea04b8d25122af694c58abf4abe3b9eefb6f8bbaf577ed5501bba2b
3
+ metadata.gz: 5820735340defe1a371f183f8e27c8e76bc786752f32d885a9baf0736934d9c2
4
+ data.tar.gz: 64e44eb27bc4c0a9f47995381a7650243dda46ad0e55e7716dc277ff559167bc
5
5
  SHA512:
6
- metadata.gz: cefef5780b12f194ac337af6bee8d0311cd421329dc4e87cef21dc9676505db9aaed83c72d8fde2f7c98efb54a4587c8ab6accf155d4f9aadf88e4d4c8fb1627
7
- data.tar.gz: c561c88b5a6a88b2c64ae1240ac1e93918097c58f3f831aa001d26cb1c5843114ccb900028ecf425c5dea306f9e5d408a80ba37a8a6a2cdeb072e5bc5e25745d
6
+ metadata.gz: a9c3188e1d211ad6354c6ae859bcaa84b80fd1e762a7ea7f1306687d55e445dea3cb5294302e10b266b07091f7cb1d63792a0f7f910fb390cd9dc7e486d23bc3
7
+ data.tar.gz: 34ba9586503d1741adde49361dcbb9f2acd02358aca4e1ca67b1c5d7f1d627047d5f880e15b3d5cd4391873978d02a20d734db1b36b50fb7d38b3cb0110620b9
@@ -1,3 +1,7 @@
1
+ ## 0.0.7
2
+
3
+ - Report when an app is using Puma
4
+
1
5
  ## 0.0.6
2
6
 
3
7
  - Support Puma max threads, support Puma spawned threads
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_runtime_dependency 'multi_json', '~> 1'
28
28
 
29
+ spec.add_development_dependency 'rack', '~> 2'
29
30
  spec.add_development_dependency 'rake', '~> 10'
30
31
  spec.add_development_dependency 'minitest', '~> 5.3'
31
32
  spec.add_development_dependency "bundler", '~> 1.15'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'barnes/instruments/puma_stats_value'
4
+ module Barnes
5
+ module Instruments
6
+ class PumaInstrument
7
+ def initialize(sample_rate=nil)
8
+ @debug = ENV["BARNES_DEBUG_PUMA_STATS"]
9
+ @puma_has_stats = (defined?(::Puma) && ::Puma.respond_to?(:stats))
10
+ end
11
+
12
+ def valid?
13
+ return false unless defined?(Puma)
14
+ return false unless ENV["DYNO"] && ENV["DYNO"].start_with?("web")
15
+ true
16
+ end
17
+
18
+ def start!(state)
19
+ require 'multi_json'
20
+ end
21
+
22
+ def json_stats
23
+ return {} unless @puma_has_stats
24
+ MultiJson.load(::Puma.stats || "{}")
25
+
26
+ # Puma loader has not been initialized yet
27
+ rescue NoMethodError => e
28
+ raise e unless e.message =~ /nil/
29
+ raise e unless e.message =~ /stats/
30
+ return {}
31
+ end
32
+
33
+ def instrument!(state, counters, gauges)
34
+ gauges['using.puma'] = 1
35
+
36
+ stats = json_stats
37
+ return if stats.empty?
38
+
39
+ puts "Puma debug stats from barnes: #{stats}" if @debug
40
+
41
+ pool_capacity = StatValue.new(stats, "pool_capacity").value
42
+ max_threads = StatValue.new(stats, "max_threads").value
43
+ spawned = StatValue.new(stats, "running").value
44
+
45
+ gauges[:'pool.capacity'] = pool_capacity if pool_capacity
46
+ gauges[:'threads.max'] = max_threads if max_threads
47
+ gauges[:'threads.spawned'] = spawned if spawned
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Barnes
4
2
  module Instruments
5
- class PumaBacklog
3
+ class PumaInstrument
6
4
  # This class is responsible for consuming a puma
7
5
  # generated stats hash that can come in two "flavors"
8
6
  # one is a "single process" server which will look like this:
@@ -46,45 +44,6 @@ module Barnes
46
44
  return value
47
45
  end
48
46
  end
49
-
50
- def initialize(sample_rate=nil)
51
- @debug = ENV["BARNES_DEBUG_PUMA_STATS"]
52
- end
53
-
54
- def valid?
55
- defined?(Puma) &&
56
- Puma.respond_to?(:stats) &&
57
- ENV["DYNO"] && ENV["DYNO"].start_with?("web")
58
- end
59
-
60
- def start!(state)
61
- require 'multi_json'
62
- end
63
-
64
- def json_stats
65
- MultiJson.load(Puma.stats || "{}")
66
-
67
- # Puma loader has not been initialized yet
68
- rescue NoMethodError => e
69
- raise e unless e.message =~ /nil/
70
- raise e unless e.message =~ /stats/
71
- return {}
72
- end
73
-
74
- def instrument!(state, counters, gauges)
75
- stats = json_stats
76
- return if stats.empty?
77
-
78
- puts "Puma debug stats from barnes: #{stats}" if @debug
79
-
80
- pool_capacity = StatValue.new(stats, "pool_capacity").value
81
- max_threads = StatValue.new(stats, "max_threads").value
82
- spawned = StatValue.new(stats, "running").value
83
-
84
- gauges[:'pool.capacity'] = pool_capacity if pool_capacity
85
- gauges[:'threads.max'] = max_threads if max_threads
86
- gauges[:'threads.spawned'] = spawned if spawned
87
- end
88
47
  end
89
48
  end
90
- end
49
+ end
@@ -28,11 +28,11 @@ module Barnes
28
28
  def initialize(sample_rate)
29
29
  super()
30
30
 
31
- require 'barnes/instruments/puma_backlog'
32
- backlog_reporter = Barnes::Instruments::PumaBacklog.new
31
+ require 'barnes/instruments/puma_instrument'
32
+ puma_instrument = Barnes::Instruments::PumaInstrument.new
33
33
 
34
- if backlog_reporter.valid?
35
- instrument backlog_reporter
34
+ if puma_instrument.valid?
35
+ instrument puma_instrument
36
36
  end
37
37
 
38
38
  require 'barnes/instruments/stopwatch'
@@ -22,5 +22,5 @@
22
22
  #
23
23
 
24
24
  module Barnes
25
- VERSION = "0.0.6"
25
+ VERSION = "0.0.7"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barnes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - schneems
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: statsd-ruby
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +147,8 @@ files:
133
147
  - lib/barnes/consts.rb
134
148
  - lib/barnes/instruments/gctools_oobgc.rb
135
149
  - lib/barnes/instruments/object_space_counter.rb
136
- - lib/barnes/instruments/puma_backlog.rb
150
+ - lib/barnes/instruments/puma_instrument.rb
151
+ - lib/barnes/instruments/puma_stats_value.rb
137
152
  - lib/barnes/instruments/ree_gc.rb
138
153
  - lib/barnes/instruments/ruby_gc.rb
139
154
  - lib/barnes/instruments/stopwatch.rb