barnes 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19c9b546f067ae2704fa77ae6d9427ec127066297e5b764946eee6182ecbee10
4
- data.tar.gz: '01368678dd52fde279caaa874e961fbd804083818d77f0d35ceb1c0a7fe3a676'
3
+ metadata.gz: 6bd0eb8994398ca8d7e23bed22c364de8a37d55d4d2b4ee2208303a1f7133c3b
4
+ data.tar.gz: f5e7e42b14b1a408840b1be9982113016c97bad1a18a84c2d3d4d6c7ca45dd7d
5
5
  SHA512:
6
- metadata.gz: ca830409f6dc45d30e14bb69c1593724ed9a563eaf2082588225f46fffe189c0a1363d445cc499b7b96cf648a1ffaf80267a668ec5a4b15fef2af915bd7765b8
7
- data.tar.gz: e73a76762d62b85007edce9bd6fdc7a21ffff41115dcf284587f74787b740de303c44592be65ff720cbda9310ac7dfec43db7f6d349dc4fc085eef3daca0a8c0
6
+ metadata.gz: 706f4a6711a6acc7e5afdc6c327a3056aece3a729d1b15dd2bbc359d2e1784e47a56a3ac7dd8deb05776be74e749bb1972b072b4f317eab04a9b2274da5fa922
7
+ data.tar.gz: 8e9721b3cf2fdc10a0c70a04fadbe961a481804b16a76d6e769ed514a47960dd8dd39859e709240cefa38be9bbc4016b31586fa144d81ca730253689ec9adf06
@@ -1,3 +1,7 @@
1
+ ## 0.0.5
2
+
3
+ - Support Puma pool capacity value #15
4
+
1
5
  ## 0.0.4
2
6
 
3
7
  - Support Puma backlog #14
data/Rakefile CHANGED
@@ -29,7 +29,8 @@ task :default => :test
29
29
 
30
30
  desc 'Run tests'
31
31
  Rake::TestTask.new :test do |t|
32
- t.libs << 'test/lib'
33
- t.pattern = 'test/*_test.rb'
32
+ t.libs << 'test'
33
+ t.libs << 'lib'
34
+ t.pattern = 'test/**/*_test.rb'
34
35
  t.verbose = true
35
36
  end
@@ -3,7 +3,52 @@
3
3
  module Barnes
4
4
  module Instruments
5
5
  class PumaBacklog
6
+ # This class is responsible for consuming a puma
7
+ # generated stats hash that can come in two "flavors"
8
+ # one is a "single process" server which will look like this:
9
+ #
10
+ # { "backlog": 0, "running": 0, "pool_capacity": 16 }
11
+ #
12
+ # The other is a multiple cluster server that will look like this:
13
+ #
14
+ # {"workers"=>2, "phase"=>0, "booted_workers"=>2, "old_workers"=>0, "worker_status"=>[{"pid"=>35020, "index"=>0, "phase"=>0, "booted"=>true, "last_checkin"=>"2018-05-21T19:53:18Z", "last_status"=>{"backlog"=>0, "running"=>5, "pool_capacity"=>5}}, {"pid"=>35021, "index"=>1, "phase"=>0, "booted"=>true, "last_checkin"=>"2018-05-21T19:53:18Z", "last_status"=>{"backlog"=>0, "running"=>5, "pool_capacity"=>5}}]}
15
+ #
16
+ class StatValue
17
+ attr_reader :stats, :key
18
+
19
+ def initialize(stats, key)
20
+ @stats = stats
21
+ @key = key
22
+ @cluster = stats.key?("worker_status")
23
+ end
24
+
25
+ def single?
26
+ !cluster?
27
+ end
28
+
29
+ def cluster?
30
+ @cluster
31
+ end
32
+
33
+ # For single worker process use value directly
34
+ # for multiple workers use the sum.
35
+ #
36
+ # https://github.com/puma/puma/pull/1532
37
+ def value
38
+ return stats[key] if single?
39
+ first_worker = stats["worker_status"].first
40
+ return nil unless first_worker && first_worker["last_status"].key?(key)
41
+
42
+ value = 0
43
+ stats["worker_status"].each do |worker_status|
44
+ value += worker_status["last_status"][key] || 0
45
+ end
46
+ return value
47
+ end
48
+ end
49
+
6
50
  def initialize(sample_rate=nil)
51
+ @debug = ENV["BARNES_DEBUG_PUMA_STATS"]
7
52
  end
8
53
 
9
54
  def valid?
@@ -26,22 +71,17 @@ module Barnes
26
71
  return {}
27
72
  end
28
73
 
29
- # For single worker process use backlog directly
30
- # for multiple workers sum backlog.
31
- #
32
- # https://github.com/puma/puma/pull/1532
33
74
  def instrument!(state, counters, gauges)
34
- stats = self.json_stats
75
+ stats = json_stats
35
76
  return if stats.empty?
36
77
 
37
- backlog = stats["backlog"]
38
- if backlog.nil?
39
- backlog = stats["worker_status"].map do |worker_status|
40
- worker_status["last_status"]["backlog"]
41
- end.reduce(0, :+)
42
- end
78
+ puts "Puma debug stats from barnes: #{stats}" if @debug
79
+
80
+ pool_capacity = StatValue.new(stats, "pool_capacity").value
81
+ backlog = StatValue.new(stats, "backlog").value
43
82
 
44
- gauges[:'backlog.requests'] = backlog
83
+ gauges[:'pool.capacity'] = pool_capacity if pool_capacity
84
+ gauges[:'backlog.requests'] = backlog if backlog
45
85
  end
46
86
  end
47
87
  end
@@ -22,5 +22,5 @@
22
22
  #
23
23
 
24
24
  module Barnes
25
- VERSION = "0.0.4"
25
+ VERSION = "0.0.5"
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - schneems
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: statsd-ruby