barnes 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/barnes.gemspec +1 -0
- data/lib/barnes/instruments/puma_instrument.rb +51 -0
- data/lib/barnes/instruments/{puma_backlog.rb → puma_stats_value.rb} +2 -43
- data/lib/barnes/resource_usage.rb +4 -4
- data/lib/barnes/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5820735340defe1a371f183f8e27c8e76bc786752f32d885a9baf0736934d9c2
|
4
|
+
data.tar.gz: 64e44eb27bc4c0a9f47995381a7650243dda46ad0e55e7716dc277ff559167bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9c3188e1d211ad6354c6ae859bcaa84b80fd1e762a7ea7f1306687d55e445dea3cb5294302e10b266b07091f7cb1d63792a0f7f910fb390cd9dc7e486d23bc3
|
7
|
+
data.tar.gz: 34ba9586503d1741adde49361dcbb9f2acd02358aca4e1ca67b1c5d7f1d627047d5f880e15b3d5cd4391873978d02a20d734db1b36b50fb7d38b3cb0110620b9
|
data/CHANGELOG.md
CHANGED
data/barnes.gemspec
CHANGED
@@ -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
|
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/
|
32
|
-
|
31
|
+
require 'barnes/instruments/puma_instrument'
|
32
|
+
puma_instrument = Barnes::Instruments::PumaInstrument.new
|
33
33
|
|
34
|
-
if
|
35
|
-
instrument
|
34
|
+
if puma_instrument.valid?
|
35
|
+
instrument puma_instrument
|
36
36
|
end
|
37
37
|
|
38
38
|
require 'barnes/instruments/stopwatch'
|
data/lib/barnes/version.rb
CHANGED
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.
|
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-
|
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/
|
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
|