leafy-metrics 0.5.0-java → 0.6.0-java

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
  SHA1:
3
- metadata.gz: cc7199f0a916e6bbd6f9c83e6db586d44ef10292
4
- data.tar.gz: 691f3e9f8314da6285cb4be617b8a696df62d79f
3
+ metadata.gz: 3863c762a130ef84050427252457f9e7a6c95fa9
4
+ data.tar.gz: 224d4289ccc55cb27f71e8b3d13cae2d470f50b1
5
5
  SHA512:
6
- metadata.gz: f7b8fcf83804eb702902deb42a47373dc10ca3de765e5541da590c06939b9a64a6168ff9ed08b25e466419f4fc26d0993aebdc87f644eced2558f72871c989e0
7
- data.tar.gz: 29951bf246702948f03d2782e4c2f149435f2e56689f799488706e63dd5769e1b4aa2c2f209d1013d9ad9a74b600e7cec64608ad40969034c78923f0cf1f12a9
6
+ metadata.gz: 3aee82be95e4d9aa21622b864acd565743d2e567e9311837ff6486b154043484c5bbf1a92923877c1a29c1343fd339164a64a5b22e3adf1b41553822e453ecad
7
+ data.tar.gz: 3b8ce25fb48b3d7885e0a2ff531883c53a4d79a4bb997244da4500fdbf4dbb8c1c79eaf9f0d2343eae95b6806dc36e1f03362d81e52e2dca0f638ffa120e5282
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ doc
3
3
  pkg
4
4
  *.lock
5
5
  *.jar
6
+ pom.*.xml
@@ -0,0 +1,2 @@
1
+ gemspec
2
+ plugin :compiler, :source => '1.7', :target => '1.7', :fork => true
data/Rakefile CHANGED
@@ -1,5 +1,11 @@
1
1
  #-*- mode: ruby -*-
2
2
 
3
+ require 'ruby-maven'
4
+ desc "Pack leafy-metrics.jar with the compiled classes"
5
+ task :jar do
6
+ RubyMaven.exec('prepare-package', '-Dmaven.test.skip')
7
+ end
8
+
3
9
  require "rspec/core/rake_task"
4
10
  RSpec::Core::RakeTask.new
5
11
 
@@ -9,6 +15,12 @@ YARD::Rake::YardocTask.new do |t|
9
15
  t.options += ["--title", "Leafy Metrics API"]
10
16
  end
11
17
 
12
- task :default => [ :spec ]
18
+ task :default => [ :jar, :spec ]
19
+
20
+ require 'rubygems/package_task'
21
+ Gem::PackageTask.new( eval File.read( './leafy-metrics.gemspec' ) ) do
22
+ desc 'Pack leafy-metrics.gem'
23
+ task :package => [:jar]
24
+ end
13
25
 
14
26
  # vim: syntax=Ruby
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Leafy::Metrics::VERSION
8
8
  s.author = 'christian meier'
9
9
  s.email = [ 'christian.meier@lookout.com' ]
10
+ s.platform = 'java'
10
11
 
11
12
  s.platform = 'java'
12
13
  s.license = 'MIT'
@@ -21,10 +22,13 @@ Gem::Specification.new do |s|
21
22
  s.requirements << "jar io.dropwizard.metrics:metrics-graphite, #{METRICS_VERSION}"
22
23
  s.requirements << "jar io.dropwizard.metrics:metrics-jvm, #{METRICS_VERSION}"
23
24
  s.requirements << "jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test"
25
+ s.requirements << "jar org.jruby:jruby-core, 1.7.20, :scope => :provided"
26
+ s.requirements << "jar org.jruby:jruby-stdlib, 1.7.20, :scope => :provided"
24
27
 
25
- s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
28
+ s.add_runtime_dependency 'jar-dependencies', '~> 0.1'
29
+ s.add_development_dependency 'ruby-maven', '~> 3.3'
26
30
  s.add_development_dependency 'rspec', '~> 3.1'
27
- s.add_development_dependency 'yard', '~> 0.8.7'
31
+ s.add_development_dependency 'yard', '~> 0.8'
28
32
  s.add_development_dependency 'rake', '~> 10.2'
29
33
  end
30
34
 
@@ -1,4 +1,5 @@
1
1
  require 'leafy/metrics'
2
+ require 'leafy-metrics.jar'
2
3
 
3
4
  module Leafy
4
5
  module Metrics
@@ -21,6 +22,31 @@ module Leafy
21
22
  Thread.list.select { |t| t.status == 'sleep' }.size
22
23
  end
23
24
  end
25
+
26
+ def self.register_object_allocation_meters( registry, name )
27
+ r = JRuby.runtime
28
+ f = r.java_class.declared_field 'objectSpacer'
29
+ f.accessible = true
30
+ o = f.value( r )
31
+ metrics = com.lookout.leafy.metrics.AllocateMetricsObjectSpacer.new
32
+ f.set_value( r, metrics )
33
+ registry.register_meter( name + ".strings", metrics.string )
34
+ registry.register_meter( name + ".symbols", metrics.symbol )
35
+ registry.register_meter( name + ".fixnums", metrics.fixnum )
36
+ registry.register_meter( name + ".arrays", metrics.array )
37
+ registry.register_meter( name + ".hashes", metrics.hash )
38
+ registry.register_meter( name + ".total", metrics.total )
39
+ true
40
+ rescue => e
41
+ if JRUBY_VERSION.start_with?( '1.7.1' )
42
+ warn 'need jruby version 1.7.20 or newer'
43
+ else
44
+ puts e.message
45
+ puts e.backtrace
46
+ warn 'can not register object allocation meters'
47
+ end
48
+ false
49
+ end
24
50
  end
25
51
  end
26
52
  end
@@ -66,8 +66,12 @@ module Leafy
66
66
  #
67
67
  # @param [String] name
68
68
  # @return [Java::ComCodahaleMetrics::Meter] meter object which has a 'mark' method to mark the meter
69
- def register_meter( name )
70
- @metrics.meter( name )
69
+ def register_meter( name, meter = nil )
70
+ if meter
71
+ @metrics.register( name, meter )
72
+ else
73
+ @metrics.meter( name )
74
+ end
71
75
  end
72
76
 
73
77
  # register a counter under a given name
@@ -1,6 +1,6 @@
1
1
  module Leafy
2
2
  module Metrics
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  end
6
6
 
@@ -28,6 +28,7 @@ describe Leafy::Metrics::ConsoleReporter do
28
28
  end
29
29
 
30
30
  it 'run reporter via builder config' do
31
+ skip( "wierd error only on travis with jruby 9.0.0.0.pre2" ) if JRUBY_VERSION == '9.0.0.0.pre2'
31
32
  bytes = StringIO.new
32
33
  begin
33
34
  reporter = metrics.reporter_builder( subject )
@@ -7,14 +7,67 @@ describe Leafy::Metrics::JRubyMetrics do
7
7
  subject do
8
8
  r = Leafy::Metrics::Registry.new
9
9
  Leafy::Metrics::JRubyMetrics.register_ruby_thread_state_gauges( r, 'test' )
10
+ Leafy::Metrics::JRubyMetrics.register_object_allocation_meters( r, 'test' )
10
11
  r
11
12
  end
12
13
 
13
14
  it 'registers and unregister a meter' do
14
15
 
15
- expect( subject.metrics.gauges['test.total.count'].value ).to eq 1
16
- expect( subject.metrics.gauges['test.executing.count'].value ).to eq 1
16
+ expect( subject.metrics.gauges['test.total.count'].value ).to be > 0
17
+ expect( subject.metrics.gauges['test.executing.count'].value ).to be > 0
17
18
  expect( subject.metrics.gauges['test.sleeping.count'].value ).to eq 0
19
+ end
20
+
21
+ it 'registers object allocation meters' do
22
+ if JRUBY_VERSION < '1.7.20' or JRUBY_VERSION =~ /9.0.0.0.pre1/
23
+ skip( 'unsupported jruby version for object allocation meters' )
24
+ end
25
+
26
+ total = subject.metrics.meters[ 'test.total' ].count
27
+
28
+ # TODO these numbers make the whole thing unstable
29
+ hashes = 0
30
+ symbols = 0
31
+ arrays = 0
32
+ strings = 14
33
+
34
+ expect( subject.metrics.meters[ 'test.strings' ].count ).to eq strings
35
+ expect( subject.metrics.meters[ 'test.symbols' ].count ).to eq symbols
36
+ # TODO not sure why there is no fixnum increments
37
+ expect( subject.metrics.meters[ 'test.fixnums' ].count ).to eq 0
38
+ expect( subject.metrics.meters[ 'test.hashes' ].count ).to eq hashes
39
+ expect( subject.metrics.meters[ 'test.arrays' ].count ).to eq arrays
40
+
41
+ total1 = subject.metrics.meters[ 'test.total' ].count
42
+
43
+ h = { :asd => 123, :dsa => 321 }
44
+
45
+ expect( subject.metrics.meters[ 'test.strings' ].count ).to eq strings + 6
46
+ expect( subject.metrics.meters[ 'test.arrays' ].count ).to eq arrays
47
+ expect( subject.metrics.meters[ 'test.hashes' ].count ).to eq hashes + 1
48
+ expect( subject.metrics.meters[ 'test.symbols' ].count ).to eq symbols + 2
49
+
50
+ total2 = subject.metrics.meters[ 'test.total' ].count
51
+
52
+ h = [ :asd, :dsa ]
53
+
54
+ expect( subject.metrics.meters[ 'test.strings' ].count ).to eq strings + 11
55
+ expect( subject.metrics.meters[ 'test.hashes' ].count ).to eq hashes + 1
56
+ expect( subject.metrics.meters[ 'test.symbols' ].count).to eq symbols + 2
57
+ expect( subject.metrics.meters[ 'test.arrays' ].count ).to eq arrays + 1
58
+
59
+ s = subject.metrics.meters[ 'test.strings' ].count
60
+
61
+ h = 'aha'
62
+
63
+ # TODO not sure why there is an increment of 2 here
64
+ expect( subject.metrics.meters[ 'test.strings' ].count ).to eq s + 2
65
+ expect( subject.metrics.meters[ 'test.hashes' ].count ).to eq hashes + 1
66
+ expect( subject.metrics.meters[ 'test.symbols' ].count).to eq symbols + 2
67
+ expect( subject.metrics.meters[ 'test.arrays' ].count ).to eq arrays + 1
18
68
 
69
+ expect( total1 ).to be > total
70
+ expect( total2 ).to be > total1
71
+ expect( subject.metrics.meters[ 'test.total' ].count ).to be > total2
19
72
  end
20
73
  end
@@ -0,0 +1,30 @@
1
+ package com.lookout.leafy.metrics;
2
+
3
+ import org.jruby.runtime.builtin.IRubyObject;
4
+ import org.jruby.Ruby;
5
+ import org.jruby.RubyString;
6
+ import org.jruby.*;
7
+
8
+ import com.codahale.metrics.Meter;
9
+
10
+ public class AllocateMetricsObjectSpacer implements Ruby.ObjectSpacer {
11
+
12
+ public final Meter string = new Meter();
13
+ public final Meter symbol = new Meter();
14
+ public final Meter fixnum = new Meter();
15
+ public final Meter array = new Meter();
16
+ public final Meter hash = new Meter();
17
+ public final Meter total = new Meter();
18
+
19
+ public void addToObjectSpace(Ruby runtime, boolean useObjectSpace, IRubyObject object) {
20
+ switch(object.getClass().getSimpleName()) {
21
+ case "RubyString": string.mark();break;
22
+ case "RubySymbol": symbol.mark(); break;
23
+ case "RubyFixnum": fixnum.mark(); break;
24
+ case "RubyArray": array.mark(); break;
25
+ case "RubyHash": hash.mark(); break;
26
+ default:
27
+ }
28
+ total.mark();
29
+ }
30
+ }
metadata CHANGED
@@ -1,39 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leafy-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: java
6
6
  authors:
7
7
  - christian meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jar-dependencies
15
15
  version_requirements: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.8
19
+ version: '0.1'
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - ~>
22
+ - - "~>"
23
23
  - !ruby/object:Gem::Version
24
- version: 0.1.8
24
+ version: '0.1'
25
25
  prerelease: false
26
26
  type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-maven
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '3.3'
39
+ prerelease: false
40
+ type: :development
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  version_requirements: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ~>
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: '3.1'
34
48
  requirement: !ruby/object:Gem::Requirement
35
49
  requirements:
36
- - - ~>
50
+ - - "~>"
37
51
  - !ruby/object:Gem::Version
38
52
  version: '3.1'
39
53
  prerelease: false
@@ -42,26 +56,26 @@ dependencies:
42
56
  name: yard
43
57
  version_requirements: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.8.7
61
+ version: '0.8'
48
62
  requirement: !ruby/object:Gem::Requirement
49
63
  requirements:
50
- - - ~>
64
+ - - "~>"
51
65
  - !ruby/object:Gem::Version
52
- version: 0.8.7
66
+ version: '0.8'
53
67
  prerelease: false
54
68
  type: :development
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  version_requirements: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ~>
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
75
  version: '10.2'
62
76
  requirement: !ruby/object:Gem::Requirement
63
77
  requirements:
64
- - - ~>
78
+ - - "~>"
65
79
  - !ruby/object:Gem::Version
66
80
  version: '10.2'
67
81
  prerelease: false
@@ -75,9 +89,10 @@ executables: []
75
89
  extensions: []
76
90
  extra_rdoc_files: []
77
91
  files:
78
- - .gitignore
92
+ - ".gitignore"
79
93
  - Gemfile
80
94
  - LICENSE
95
+ - Mavenfile
81
96
  - README.md
82
97
  - Rakefile
83
98
  - leafy-metrics.gemspec
@@ -101,6 +116,7 @@ files:
101
116
  - spec/jvm_metrics_spec.rb
102
117
  - spec/registry_spec.rb
103
118
  - spec/setup.rb
119
+ - src/main/java/com/lookout/leafy/metrics/AllocateMetricsObjectSpacer.java
104
120
  homepage: https://github.com/lookout/leafy
105
121
  licenses:
106
122
  - MIT
@@ -111,12 +127,12 @@ require_paths:
111
127
  - lib
112
128
  required_ruby_version: !ruby/object:Gem::Requirement
113
129
  requirements:
114
- - - '>='
130
+ - - ">="
115
131
  - !ruby/object:Gem::Version
116
132
  version: '0'
117
133
  required_rubygems_version: !ruby/object:Gem::Requirement
118
134
  requirements:
119
- - - '>='
135
+ - - ">="
120
136
  - !ruby/object:Gem::Version
121
137
  version: '0'
122
138
  requirements:
@@ -124,6 +140,8 @@ requirements:
124
140
  - jar io.dropwizard.metrics:metrics-graphite, 3.1.0
125
141
  - jar io.dropwizard.metrics:metrics-jvm, 3.1.0
126
142
  - jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test
143
+ - jar org.jruby:jruby-core, 1.7.20, :scope => :provided
144
+ - jar org.jruby:jruby-stdlib, 1.7.20, :scope => :provided
127
145
  rubyforge_project:
128
146
  rubygems_version: 2.4.5
129
147
  signing_key: