leafy-metrics 0.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +221 -0
- data/Rakefile +14 -0
- data/leafy-metrics.gemspec +31 -0
- data/lib/leafy-metrics.rb +1 -0
- data/lib/leafy-metrics_jars.rb +7 -0
- data/lib/leafy/metrics.rb +2 -0
- data/lib/leafy/metrics/console_reporter.rb +32 -0
- data/lib/leafy/metrics/csv_reporter.rb +26 -0
- data/lib/leafy/metrics/graphite/graphite.rb +28 -0
- data/lib/leafy/metrics/graphite/graphite_reporter.rb +43 -0
- data/lib/leafy/metrics/jruby_metrics.rb +26 -0
- data/lib/leafy/metrics/jvm_metrics.rb +43 -0
- data/lib/leafy/metrics/registry.rb +112 -0
- data/lib/leafy/metrics/reporter.rb +51 -0
- data/lib/leafy/metrics/version.rb +6 -0
- data/spec/console_reporter_spec.rb +72 -0
- data/spec/csv_reporter_spec.rb +75 -0
- data/spec/graphite_reporter_spec.rb +72 -0
- data/spec/graphite_spec.rb +23 -0
- data/spec/jruby_metrics_spec.rb +20 -0
- data/spec/jvm_metrics_spec.rb +79 -0
- data/spec/registry_spec.rb +106 -0
- data/spec/setup.rb +10 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a8092d5e138c5aad7a59e2e1bc4f9704f437b90
|
4
|
+
data.tar.gz: 7320c95178976b70d9d7996262c092ca4755d1d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ad6f08dc5230ddd5747ca5b773f8fc500340335727d8504cab2ba64cedbd382c310b81828c3c2ef0c6f2b9b2872518320a5463bb23416b587885345ddb6ce60
|
7
|
+
data.tar.gz: c5090ecf465ee518cde818c2497b9acda135a0153caeee2b7a6c3d9e6630c8a8f5f74087d8e66c3e28a78c79d60849a149525274b182ce11e44b450afeada8b5
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Lookout
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
# Leafy-Metrics
|
2
|
+
|
3
|
+
## installation
|
4
|
+
|
5
|
+
via rubygems
|
6
|
+
```
|
7
|
+
gem install leafy-metrics
|
8
|
+
```
|
9
|
+
or add to your Gemfile
|
10
|
+
```
|
11
|
+
gem 'leafy-metrics'
|
12
|
+
```
|
13
|
+
|
14
|
+
installing the gem also takes care of the jar dependencies with jruby-1.7.16+
|
15
|
+
|
16
|
+
## usage
|
17
|
+
|
18
|
+
an instance of the registry ```Leafy::Metrics::Registry``` can register various metrics like gauge, timer, meter, counter and histogram and remove them again.
|
19
|
+
|
20
|
+
registry = Leafy::Metrics::Registry.new
|
21
|
+
|
22
|
+
### gauge
|
23
|
+
|
24
|
+
it can be other a given block or any object with a #call method returning the gauge - a number
|
25
|
+
|
26
|
+
registry.register_gauge( 'app.uptime') do
|
27
|
+
App.uptime
|
28
|
+
end
|
29
|
+
|
30
|
+
or with an object
|
31
|
+
|
32
|
+
class UptimeGauge
|
33
|
+
def call
|
34
|
+
App.uptime
|
35
|
+
enf
|
36
|
+
end
|
37
|
+
registry.register_gauge( 'app.uptime', UptimeGauge.new )
|
38
|
+
|
39
|
+
### timer
|
40
|
+
|
41
|
+
a timer can measure the time an block needs to execute:
|
42
|
+
|
43
|
+
timer = registry.register_timer( 'app.timer' )
|
44
|
+
timer.time do
|
45
|
+
App.update_data
|
46
|
+
end
|
47
|
+
|
48
|
+
### counter
|
49
|
+
|
50
|
+
a counter simply counts i.e. can be incremented or decremented
|
51
|
+
|
52
|
+
counter = registry.register_counter( 'active.users.counter' )
|
53
|
+
|
54
|
+
# one new user logged on
|
55
|
+
counter.inc
|
56
|
+
|
57
|
+
# three new users logged on
|
58
|
+
counter.inc 3
|
59
|
+
|
60
|
+
# one user logged off
|
61
|
+
counter.dec
|
62
|
+
|
63
|
+
# two users logged off
|
64
|
+
counter.dec 2
|
65
|
+
|
66
|
+
### meter
|
67
|
+
|
68
|
+
used = registry.register_meter( 'app.used' )
|
69
|
+
|
70
|
+
mark the occurrence of an event
|
71
|
+
|
72
|
+
used.mark
|
73
|
+
|
74
|
+
mark the occurrence of 'n' events
|
75
|
+
|
76
|
+
used.mark n
|
77
|
+
|
78
|
+
|
79
|
+
### histogram
|
80
|
+
|
81
|
+
measures the distribution of values in a stream of data using an exponentially decaying reservoir
|
82
|
+
|
83
|
+
histogram = registry.register_histogram( 'search.results' )
|
84
|
+
histogram.update( Search.last_result.size )
|
85
|
+
|
86
|
+
### remove any metrics
|
87
|
+
|
88
|
+
registry.unregister( 'app.uptime )
|
89
|
+
|
90
|
+
### note
|
91
|
+
|
92
|
+
currently there is not further introspection on the registry and its health-check. with the ```Leafy::Json::MetricsWriter``` (from leafy-rack) you can get a json representation of the current **metrics report**
|
93
|
+
|
94
|
+
Leafy::Json::MetricsWriter.to_json( registry.metrics )
|
95
|
+
|
96
|
+
## reporters
|
97
|
+
|
98
|
+
all reporters use a builder pattern. there are following timeunits for
|
99
|
+
configuration:
|
100
|
+
|
101
|
+
* ```Leafy::Metrics::Reporter::DAYS```
|
102
|
+
* ```Leafy::Metrics::Reporter::HOURS```
|
103
|
+
* ```Leafy::Metrics::Reporter::MINUTES```
|
104
|
+
* ```Leafy::Metrics::Reporter::SECONDS```
|
105
|
+
* ```Leafy::Metrics::Reporter::MILLISECONDS```
|
106
|
+
* ```Leafy::Metrics::Reporter::MICROSECONDS```
|
107
|
+
* ```Leafy::Metrics::Reporter::NANOSECONDS```
|
108
|
+
|
109
|
+
in all examples below ```metrics = Leafy::Metrics::Registry.new```
|
110
|
+
|
111
|
+
### console reporter
|
112
|
+
|
113
|
+
require 'leafy/metrics/console_reporter'
|
114
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::ConsoleReporter ).build
|
115
|
+
reporter.start( 1, Leafy::Metrics::Reporter::SECONDS )
|
116
|
+
....
|
117
|
+
reporter.stop
|
118
|
+
|
119
|
+
or with all the possible configuration
|
120
|
+
|
121
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::ConsoleReporter )
|
122
|
+
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
123
|
+
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
124
|
+
.output_to( STDERR )
|
125
|
+
.build
|
126
|
+
|
127
|
+
or the config via a block
|
128
|
+
|
129
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::ConsoleReporter ) do
|
130
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
131
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
132
|
+
output_to( STDERR )
|
133
|
+
end.build
|
134
|
+
|
135
|
+
### csv reporter
|
136
|
+
|
137
|
+
for each metric there will be a CSV file inside a given directory
|
138
|
+
|
139
|
+
require 'leafy/metrics/csv_reporter'
|
140
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::CSVReporter )
|
141
|
+
.build( 'metrics/directory' )
|
142
|
+
reporter.start( 1, Leafy::Metrics::Reporter::SECONDS )
|
143
|
+
....
|
144
|
+
reporter.stop
|
145
|
+
|
146
|
+
or with all possible configuration
|
147
|
+
|
148
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::CSVReporter )
|
149
|
+
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
150
|
+
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
151
|
+
.build( 'metrics/directory' )
|
152
|
+
|
153
|
+
or configuration via block
|
154
|
+
|
155
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::CSVReporter ) do
|
156
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
157
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
158
|
+
end.build( 'metrics/directory' )
|
159
|
+
|
160
|
+
### graphite reporter
|
161
|
+
|
162
|
+
there are three targets where to send the data
|
163
|
+
|
164
|
+
* ```Leafy::Metrics::Graphite.new_tcp( hostname, port )```
|
165
|
+
* ```Leafy::Metrics::Graphite.new_udp( hostname, port )```
|
166
|
+
* ```Leafy::Metrics::Graphite.new_pickled( hostname, port, batchsize )```
|
167
|
+
|
168
|
+
the latter is collecting a few report event and sends them as batch. the ```sender``` is one of the above targets.
|
169
|
+
|
170
|
+
require 'leafy/metrics/graphite_reporter'
|
171
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::GraphiteReporter )
|
172
|
+
.build_tcp( hostname, port )
|
173
|
+
reporter.start( 1, Leafy::Metrics::Reporter::SECONDS )
|
174
|
+
....
|
175
|
+
reporter.stop
|
176
|
+
|
177
|
+
or with full configuration
|
178
|
+
|
179
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::GraphiteReporter )
|
180
|
+
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
181
|
+
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
182
|
+
.prefixed_with( 'myapp' )
|
183
|
+
.build( sender )
|
184
|
+
|
185
|
+
or with block configuration
|
186
|
+
|
187
|
+
reporter = metrics.reporter_builder( Leafy::Metrics::GraphiteReporter ) do
|
188
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
189
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
190
|
+
prefixed_with( 'myapp' )
|
191
|
+
end.build_udp( host, port )
|
192
|
+
|
193
|
+
### any third party reporter
|
194
|
+
|
195
|
+
reporter = metrics.reporter_builder( com.readytalk.metrics.StatsDReporter ) do
|
196
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
197
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
198
|
+
end.build( host, port )
|
199
|
+
|
200
|
+
or using the Java module reference
|
201
|
+
|
202
|
+
reporter = metrics.reporter_builder( Java::ComReadytalkMetrics::StatsDReporter ) do
|
203
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
204
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
205
|
+
prefixed_with( 'app' )
|
206
|
+
end.build( host, port )
|
207
|
+
|
208
|
+
## developement
|
209
|
+
|
210
|
+
get all the gems and jars in place
|
211
|
+
|
212
|
+
gem install jar-dependencies --development
|
213
|
+
bundle install
|
214
|
+
|
215
|
+
for running all specs
|
216
|
+
|
217
|
+
rake
|
218
|
+
|
219
|
+
or
|
220
|
+
|
221
|
+
rspec spec/reporter_spec.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#-*- mode: ruby -*-
|
2
|
+
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
RSpec::Core::RakeTask.new
|
5
|
+
|
6
|
+
require "yard"
|
7
|
+
YARD::Rake::YardocTask.new do |t|
|
8
|
+
t.files = ['lib/**/*.rb']
|
9
|
+
t.options += ["--title", "Leafy Metrics API"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [ :spec ]
|
13
|
+
|
14
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#-*- mode: ruby -*-
|
2
|
+
|
3
|
+
require File.expand_path( '../lib/leafy/metrics/version', __FILE__ )
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'leafy-metrics'
|
7
|
+
s.version = Leafy::Metrics::VERSION
|
8
|
+
s.author = 'christian meier'
|
9
|
+
s.email = [ 'christian.meier@lookout.com' ]
|
10
|
+
|
11
|
+
s.platform = 'java'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.summary = %q(provide an API to register metrics)
|
14
|
+
s.homepage = 'https://github.com/lookout/leafy'
|
15
|
+
s.description = %q(provides an API to register metrics like meters, timers, gauge, counter using dropwizard-metrics. it also allows to setup reporters: console-reporter, csv-reporter and graphite-reporter)
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
|
19
|
+
METRICS_VERSION = '3.1.0'
|
20
|
+
s.requirements << "jar io.dropwizard.metrics:metrics-core, #{METRICS_VERSION}"
|
21
|
+
s.requirements << "jar io.dropwizard.metrics:metrics-graphite, #{METRICS_VERSION}"
|
22
|
+
s.requirements << "jar io.dropwizard.metrics:metrics-jvm, #{METRICS_VERSION}"
|
23
|
+
s.requirements << "jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test"
|
24
|
+
|
25
|
+
s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
|
26
|
+
s.add_development_dependency 'rspec', '~> 3.1'
|
27
|
+
s.add_development_dependency 'yard', '~> 0.8.7'
|
28
|
+
s.add_development_dependency 'rake', '~> 10.2'
|
29
|
+
end
|
30
|
+
|
31
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'leafy/metrics'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# this is a generated file, to avoid over-writing it just delete this comment
|
2
|
+
require 'jar_dependencies'
|
3
|
+
|
4
|
+
require_jar( 'org.slf4j', 'slf4j-api', '1.7.7' )
|
5
|
+
require_jar( 'io.dropwizard.metrics', 'metrics-graphite', '3.1.0' )
|
6
|
+
require_jar( 'io.dropwizard.metrics', 'metrics-jvm', '3.1.0' )
|
7
|
+
require_jar( 'io.dropwizard.metrics', 'metrics-core', '3.1.0' )
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'leafy/metrics/reporter'
|
2
|
+
|
3
|
+
java_import com.codahale.metrics.ConsoleReporter
|
4
|
+
|
5
|
+
module Leafy
|
6
|
+
module Metrics
|
7
|
+
class ConsoleReporter < Reporter
|
8
|
+
|
9
|
+
class Builder < Reporter::Builder
|
10
|
+
def initialize( metrics )
|
11
|
+
super( ::ConsoleReporter, metrics )
|
12
|
+
end
|
13
|
+
|
14
|
+
def output_to( io )
|
15
|
+
# IO objects in jruby do have a to_outputstream method
|
16
|
+
@io = java.io.PrintStream.new( io.to_outputstream )
|
17
|
+
@builder.output_to( @io )
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
Reporter.new( @builder.build )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.for_registry( metrics )
|
27
|
+
Builder.new( metrics )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'leafy/metrics/reporter'
|
2
|
+
|
3
|
+
java_import com.codahale.metrics.CsvReporter
|
4
|
+
|
5
|
+
module Leafy
|
6
|
+
module Metrics
|
7
|
+
class CSVReporter < Reporter
|
8
|
+
|
9
|
+
class Builder < Reporter::Builder
|
10
|
+
def initialize( metrics )
|
11
|
+
super( ::CsvReporter, metrics )
|
12
|
+
end
|
13
|
+
|
14
|
+
def build( directory )
|
15
|
+
directory = java.io.File.new( directory )
|
16
|
+
Reporter.new( @builder.build( directory ) )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.for_registry( metrics )
|
21
|
+
Builder.new( metrics )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Leafy
|
2
|
+
module Metrics
|
3
|
+
class Graphite
|
4
|
+
|
5
|
+
attr_reader :sender
|
6
|
+
|
7
|
+
def initialize( sender )
|
8
|
+
unless sender.java_kind_of? Java::ComCodahaleMetricsGraphite::GraphiteSender
|
9
|
+
raise "not instance of 'Java::ComCodahaleMetricsGraphite::Graphite'"
|
10
|
+
end
|
11
|
+
@sender = sender
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.new_tcp( hostname, port )
|
15
|
+
new com.codahale.metrics.graphite.Graphite.new( hostname, port )
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.new_udp( hostname, port )
|
19
|
+
new com.codahale.metrics.graphite.GraphiteUDP.new( hostname, port )
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.new_pickled( hostname, port, batchsize )
|
23
|
+
new com.codahale.metrics.graphite.PickledGraphite.new( hostname, port, batchsize )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'leafy/metrics/reporter'
|
2
|
+
require 'leafy/metrics/graphite/graphite'
|
3
|
+
|
4
|
+
java_import com.codahale.metrics.graphite.GraphiteReporter
|
5
|
+
|
6
|
+
module Leafy
|
7
|
+
module Metrics
|
8
|
+
class GraphiteReporter < Reporter
|
9
|
+
|
10
|
+
class Builder < Reporter::Builder
|
11
|
+
def initialize( metrics )
|
12
|
+
super( ::GraphiteReporter, metrics )
|
13
|
+
end
|
14
|
+
|
15
|
+
def prefixed_with( prefix )
|
16
|
+
@builder.prefixed_with( prefix )
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def build( graphite )
|
21
|
+
Reporter.new( @builder.build( graphite.sender ) )
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_tcp( host, port )
|
25
|
+
build( Leafy::Metrics::Graphite.new_tcp( host, port ) )
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_udp( host, port )
|
29
|
+
build( Leafy::Metrics::Graphite.new_udp( host, port ) )
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_pickled( host, port )
|
33
|
+
build( Leafy::Metrics::Graphite.new_pickled( host, port ) )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.for_registry( metrics )
|
38
|
+
Builder.new( metrics )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'leafy/metrics'
|
2
|
+
|
3
|
+
module Leafy
|
4
|
+
module Metrics
|
5
|
+
module JRubyMetrics
|
6
|
+
|
7
|
+
# registers a few thread gauges under the given basename: total.com, executing.count and sleeping.count
|
8
|
+
#
|
9
|
+
# @param [Leafy::Metrics::Registry] where to register the metrics
|
10
|
+
# @param [String] basename
|
11
|
+
def self.register_ruby_thread_state_gauges( registry, name )
|
12
|
+
registry.register_gauge( name + '.total.count' ) do
|
13
|
+
Thread.list.size
|
14
|
+
end
|
15
|
+
|
16
|
+
registry.register_gauge( name + '.executing.count' ) do
|
17
|
+
Thread.list.select { |t| t.status == 'run' }.size
|
18
|
+
end
|
19
|
+
|
20
|
+
registry.register_gauge( name + '.sleeping.count' ) do
|
21
|
+
Thread.list.select { |t| t.status == 'sleep' }.size
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'leafy/metrics'
|
2
|
+
|
3
|
+
module Leafy
|
4
|
+
module Metrics
|
5
|
+
module JvmMetrics
|
6
|
+
|
7
|
+
# registers some buffer pool metrics. more details see https://github.com/dropwizard/metrics/blob/master/metrics-jvm/src/main/java/com/codahale/metrics/jvm/BufferPoolMetricSet.java#L19
|
8
|
+
#
|
9
|
+
# @param [Leafy::Metrics::Registry] where to register the metrics
|
10
|
+
# @param [String] basename
|
11
|
+
def self.register_buffer_pool_metrics( registry, name )
|
12
|
+
# use the same MBenServer as JRuby does
|
13
|
+
registry.register_metric( name, com.codahale.metrics.jvm.BufferPoolMetricSet.new( java.lang.management.ManagementFactory.getPlatformMBeanServer ) )
|
14
|
+
end
|
15
|
+
|
16
|
+
# registers some memory usage gauges. more details see https://github.com/dropwizard/metrics/blob/master/metrics-jvm/src/main/java/com/codahale/metrics/jvm/MemoryUsageGaugeSet.java#L18
|
17
|
+
#
|
18
|
+
# @param [Leafy::Metrics::Registry] where to register the metrics
|
19
|
+
# @param [String] basename
|
20
|
+
def self.register_memory_usage_gauges( registry, name )
|
21
|
+
registry.register_metric( name, com.codahale.metrics.jvm.MemoryUsageGaugeSet.new )
|
22
|
+
end
|
23
|
+
|
24
|
+
# registers some garbage collection metrics. more details see https://github.com/dropwizard/metrics/blob/master/metrics-jvm/src/main/java/com/codahale/metrics/jvm/GarbageCollectorMetricSet.java#L15
|
25
|
+
#
|
26
|
+
# @param [Leafy::Metrics::Registry] where to register the metrics
|
27
|
+
# @param [String] basename
|
28
|
+
def self.register_garbage_collector_metrics( registry, name )
|
29
|
+
registry.register_metric( name, com.codahale.metrics.jvm.GarbageCollectorMetricSet.new )
|
30
|
+
end
|
31
|
+
|
32
|
+
# registers some (java) thread state gauges. more details see https://github.com/dropwizard/metrics/blob/master/metrics-jvm/src/main/java/com/codahale/metrics/jvm/ThreadStatesGaugeSet.java#L18
|
33
|
+
#
|
34
|
+
# @param [Leafy::Metrics::Registry] where to register the metrics
|
35
|
+
# @param [String] basename
|
36
|
+
def self.register_thread_state_gauges( registry, name )
|
37
|
+
registry.register_metric( name, com.codahale.metrics.jvm.ThreadStatesGaugeSet.new )
|
38
|
+
end
|
39
|
+
|
40
|
+
# TODO not sure about the FileDescriptorRatioGauge and ClassLoadingGaugeSet
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'leafy/metrics'
|
2
|
+
module Leafy
|
3
|
+
module Metrics
|
4
|
+
|
5
|
+
class Gauge
|
6
|
+
include com.codahale.metrics.Gauge
|
7
|
+
end
|
8
|
+
|
9
|
+
class Registry
|
10
|
+
|
11
|
+
class Timer
|
12
|
+
|
13
|
+
attr_reader :timer
|
14
|
+
|
15
|
+
def initialize( timer )
|
16
|
+
@timer = timer
|
17
|
+
end
|
18
|
+
|
19
|
+
def time( &block )
|
20
|
+
context = @timer.time
|
21
|
+
|
22
|
+
yield
|
23
|
+
|
24
|
+
ensure
|
25
|
+
context.stop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class GaugeWrapper < Leafy::Metrics::Gauge
|
30
|
+
|
31
|
+
def initialize( block )
|
32
|
+
@block = block
|
33
|
+
end
|
34
|
+
|
35
|
+
def value
|
36
|
+
@block.call
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# state ofthe registry
|
41
|
+
attr_reader :metrics
|
42
|
+
|
43
|
+
def initialize
|
44
|
+
@metrics = com.codahale.metrics.MetricRegistry.new
|
45
|
+
end
|
46
|
+
|
47
|
+
# register a gauge under a given name
|
48
|
+
#
|
49
|
+
# @param [String] name
|
50
|
+
# @param [String] instead of block any gauge object which responds to 'call'
|
51
|
+
# @yieldreturn [Object] can be any object like Fixnum, String, Float
|
52
|
+
# @return [MetricsRegistry::Gauge] gauge object which has a 'value' method to retrieve the current value
|
53
|
+
def register_gauge( name, gauge = nil, &block )
|
54
|
+
if gauge and not block_given? and gauge.respond_to? :call
|
55
|
+
@metrics.register( name, GaugeWrapper.new( gauge ) )
|
56
|
+
elsif gauge and not block_given? and gauge.kind_of? com.codahale.metrics.Gauge
|
57
|
+
@metrics.register( name, gauge )
|
58
|
+
elsif gauge.nil? and block_given?
|
59
|
+
@metrics.register( name, GaugeWrapper.new( block ) )
|
60
|
+
else
|
61
|
+
raise 'needs either a block and object with call method'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# register a meter under a given name
|
66
|
+
#
|
67
|
+
# @param [String] name
|
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 )
|
71
|
+
end
|
72
|
+
|
73
|
+
# register a counter under a given name
|
74
|
+
#
|
75
|
+
# @param [String] name
|
76
|
+
# @return [Java::ComCodahaleMetrics::Counter] counter object which has an 'inc' and 'dec' method
|
77
|
+
def register_counter( name )
|
78
|
+
@metrics.counter( name )
|
79
|
+
end
|
80
|
+
|
81
|
+
# register a timer under a given name
|
82
|
+
#
|
83
|
+
# @param [String] name
|
84
|
+
# @return [Java::ComCodahaleMetrics::Timer] timer object which has an 'context' method which starts the timer. the context has a 'stop' method to stop it.
|
85
|
+
def register_timer( name )
|
86
|
+
Timer.new( @metrics.timer( name ) )
|
87
|
+
end
|
88
|
+
|
89
|
+
# register a histogram under a given name
|
90
|
+
#
|
91
|
+
# @param [String] name
|
92
|
+
# @return [Java::ComCodahaleMetrics::Counter] histogram object which has an 'update' method
|
93
|
+
def register_histogram( name )
|
94
|
+
@metrics.histogram( name )
|
95
|
+
end
|
96
|
+
|
97
|
+
def register_metric( name, metric )
|
98
|
+
@metrics.register( name, metric )
|
99
|
+
end
|
100
|
+
|
101
|
+
def remove( name )
|
102
|
+
@metrics.remove( name )
|
103
|
+
end
|
104
|
+
|
105
|
+
def reporter_builder( clazz, &block )
|
106
|
+
r = clazz.for_registry( @metrics )
|
107
|
+
r.instance_eval( &block ) if block
|
108
|
+
r
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'leafy/metrics/registry'
|
2
|
+
|
3
|
+
java_import java.util.concurrent.TimeUnit;
|
4
|
+
|
5
|
+
module Leafy
|
6
|
+
module Metrics
|
7
|
+
class Reporter
|
8
|
+
# copy the TimeUnit constants
|
9
|
+
TimeUnit.constants.each do |c|
|
10
|
+
const_set( c, TimeUnit.const_get( c ) )
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize( reporter )
|
14
|
+
@reporter = reporter
|
15
|
+
end
|
16
|
+
|
17
|
+
def start( period, time_unit )
|
18
|
+
@reporter.start( period, time_unit )
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop
|
22
|
+
@reporter.stop
|
23
|
+
end
|
24
|
+
|
25
|
+
def report
|
26
|
+
@reporter.report
|
27
|
+
end
|
28
|
+
|
29
|
+
class Builder
|
30
|
+
def initialize( reporter_class, metrics )
|
31
|
+
# stay backward compatible
|
32
|
+
# FIXME remove for first proper release
|
33
|
+
metrics = metrics.metrics if metrics.is_a?( Leafy::Metrics::Registry )
|
34
|
+
@builder = reporter_class.for_registry( metrics )
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def convert_rates_to( time_unit )
|
39
|
+
@builder.convert_rates_to( time_unit )
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def convert_durations_to( time_unit )
|
44
|
+
@builder.convert_durations_to( time_unit )
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/console_reporter'
|
3
|
+
|
4
|
+
describe Leafy::Metrics::ConsoleReporter do
|
5
|
+
|
6
|
+
subject { Leafy::Metrics::ConsoleReporter }
|
7
|
+
|
8
|
+
let( :metrics ) { Leafy::Metrics::Registry.new }
|
9
|
+
let( :requests ) { metrics.register_meter( "requests" ) }
|
10
|
+
|
11
|
+
it 'run reporter with defaults' do
|
12
|
+
old_out = java.lang.System.out
|
13
|
+
bytes = StringIO.new
|
14
|
+
java.lang.System.out = java.io.PrintStream.new( bytes.to_outputstream )
|
15
|
+
begin
|
16
|
+
reporter = metrics.reporter_builder( subject ).build
|
17
|
+
requests.mark
|
18
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
19
|
+
sleep 0.02
|
20
|
+
reporter.stop
|
21
|
+
result = bytes.string.gsub( /\n/m, '')
|
22
|
+
expect( result ).to match /count = 1/
|
23
|
+
expect( result ).to match /second/
|
24
|
+
ensure
|
25
|
+
java.lang.System.out = old_out
|
26
|
+
reporter.stop if reporter
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'run reporter via builder config' do
|
31
|
+
bytes = StringIO.new
|
32
|
+
begin
|
33
|
+
reporter = metrics.reporter_builder( subject )
|
34
|
+
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
35
|
+
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
36
|
+
.output_to( bytes )
|
37
|
+
.build
|
38
|
+
|
39
|
+
requests.mark
|
40
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
41
|
+
sleep 0.02
|
42
|
+
reporter.stop
|
43
|
+
result = bytes.string.gsub( /\n/m, '')
|
44
|
+
expect( result ).to match /count = 1/
|
45
|
+
expect( result ).to match /millisecond/
|
46
|
+
ensure
|
47
|
+
reporter.stop if reporter
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'run reporter via block config' do
|
52
|
+
bytes = StringIO.new
|
53
|
+
begin
|
54
|
+
reporter = metrics.reporter_builder( subject ) do
|
55
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
56
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
57
|
+
output_to( bytes )
|
58
|
+
end.build
|
59
|
+
|
60
|
+
requests.mark
|
61
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
62
|
+
sleep 0.02
|
63
|
+
reporter.stop
|
64
|
+
result = bytes.string.gsub( /\n/m, '')
|
65
|
+
expect( result ).to match /count = 1/
|
66
|
+
expect( result ).to match /millisecond/
|
67
|
+
ensure
|
68
|
+
reporter.stop if reporter
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/csv_reporter'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe Leafy::Metrics::CSVReporter do
|
6
|
+
|
7
|
+
subject { Leafy::Metrics::CSVReporter }
|
8
|
+
|
9
|
+
let( :metrics ) { Leafy::Metrics::Registry.new }
|
10
|
+
let( :requests ) { metrics.register_meter( "requests" ) }
|
11
|
+
let( :csvfile ) { File.expand_path( File.dirname( __FILE__ ) ) + "/tmp/requests.csv" }
|
12
|
+
let( :tmpdir ) do
|
13
|
+
dir = File.expand_path( File.dirname( csvfile ) )
|
14
|
+
FileUtils.mkdir_p( dir )
|
15
|
+
FileUtils.rm_f( csvfile )
|
16
|
+
dir
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'run reporter with defaults' do
|
20
|
+
begin
|
21
|
+
reporter = metrics.reporter_builder( subject ).build( tmpdir )
|
22
|
+
requests.mark
|
23
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
24
|
+
sleep 0.02
|
25
|
+
reporter.stop
|
26
|
+
result = File.read( csvfile )
|
27
|
+
expect( result ).to match /t,count,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit/
|
28
|
+
expect( result ).to match /second/
|
29
|
+
ensure
|
30
|
+
FileUtils.rm_rf( tmpdir )
|
31
|
+
reporter.stop if reporter
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'run reporter via builder config' do
|
36
|
+
begin
|
37
|
+
reporter = metrics.reporter_builder( subject )
|
38
|
+
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
39
|
+
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
40
|
+
.build( tmpdir )
|
41
|
+
|
42
|
+
requests.mark
|
43
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
44
|
+
sleep 0.02
|
45
|
+
reporter.stop
|
46
|
+
result = File.read( csvfile )
|
47
|
+
expect( result ).to match /t,count,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit/
|
48
|
+
expect( result ).to match /second/
|
49
|
+
ensure
|
50
|
+
FileUtils.rm_rf( tmpdir )
|
51
|
+
reporter.stop if reporter
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'run reporter via block config' do
|
56
|
+
begin
|
57
|
+
reporter = metrics.reporter_builder( subject ) do
|
58
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
59
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
60
|
+
end.build( tmpdir )
|
61
|
+
|
62
|
+
requests.mark
|
63
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
64
|
+
sleep 0.02
|
65
|
+
reporter.stop
|
66
|
+
result = File.read( csvfile )
|
67
|
+
expect( result ).to match /t,count,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit/
|
68
|
+
expect( result ).to match /second/
|
69
|
+
ensure
|
70
|
+
FileUtils.rm_rf( tmpdir )
|
71
|
+
reporter.stop if reporter
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/graphite/graphite_reporter'
|
3
|
+
|
4
|
+
describe Leafy::Metrics::GraphiteReporter do
|
5
|
+
|
6
|
+
subject { Leafy::Metrics::GraphiteReporter }
|
7
|
+
|
8
|
+
let( :metrics ) { Leafy::Metrics::Registry.new }
|
9
|
+
let( :requests ) { metrics.register_meter( "requests" ) }
|
10
|
+
let( :logfile ) { LOG_FILE }
|
11
|
+
|
12
|
+
graphites = [ Leafy::Metrics::Graphite.new_tcp( 'localhost', 12345 ),
|
13
|
+
Leafy::Metrics::Graphite.new_pickled( 'localhost', 12345, 1 ) ]
|
14
|
+
graphites.each_with_index do |graphite, index|
|
15
|
+
describe graphite.sender.class do
|
16
|
+
it 'run reporter with defaults' do
|
17
|
+
log = File.read( logfile )
|
18
|
+
begin
|
19
|
+
reporter = metrics.reporter_builder( subject ).build( graphite )
|
20
|
+
requests.mark
|
21
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
22
|
+
sleep 0.02
|
23
|
+
reporter.stop
|
24
|
+
result = File.read( logfile )[ (log.size)..-1 ]
|
25
|
+
expect( result ).to match /metrics-graphite-reporter-.+-thread-1] WARN com.codahale.metrics.graphite.GraphiteReporter/
|
26
|
+
ensure
|
27
|
+
reporter.stop if reporter
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'run reporter via builder config' do
|
32
|
+
log = File.read( logfile )
|
33
|
+
begin
|
34
|
+
reporter = metrics.reporter_builder( subject )
|
35
|
+
.convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
36
|
+
.convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
37
|
+
.prefixed_with( 'myapp' )
|
38
|
+
.build( graphite )
|
39
|
+
|
40
|
+
requests.mark
|
41
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
42
|
+
sleep 0.02
|
43
|
+
reporter.stop
|
44
|
+
result = File.read( logfile )[ (log.size)..-1 ]
|
45
|
+
expect( result ).to match /metrics-graphite-reporter-.+-thread-1] WARN com.codahale.metrics.graphite.GraphiteReporter/
|
46
|
+
ensure
|
47
|
+
reporter.stop if reporter
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'run reporter via block config' do
|
52
|
+
log = File.read( logfile )
|
53
|
+
begin
|
54
|
+
reporter = metrics.reporter_builder( subject ) do
|
55
|
+
convert_rates_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
56
|
+
convert_durations_to( Leafy::Metrics::Reporter::MILLISECONDS )
|
57
|
+
prefixed_with( 'myapp' )
|
58
|
+
end.build( graphite )
|
59
|
+
|
60
|
+
requests.mark
|
61
|
+
reporter.start( 10, Leafy::Metrics::Reporter::MILLISECONDS )
|
62
|
+
sleep 0.02
|
63
|
+
reporter.stop
|
64
|
+
result = File.read( logfile )[ (log.size)..-1 ]
|
65
|
+
expect( result ).to match /metrics-graphite-reporter-.+-thread-1] WARN com.codahale.metrics.graphite.GraphiteReporter/
|
66
|
+
ensure
|
67
|
+
reporter.stop if reporter
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/graphite/graphite'
|
3
|
+
|
4
|
+
describe Leafy::Metrics::Graphite do
|
5
|
+
|
6
|
+
subject { Leafy::Metrics::Graphite }
|
7
|
+
|
8
|
+
it 'fails to create an instance without proper sender' do
|
9
|
+
expect { subject.new Object.new }.to raise_error RuntimeError
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates tcp graphite' do
|
13
|
+
expect( subject.new_tcp( 'localhost', 123 ) ).not_to be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'creates udp graphite' do
|
17
|
+
expect( subject.new_udp( 'localhost', 123 ) ).not_to be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'creates pickled graphite' do
|
21
|
+
expect( subject.new_pickled( 'localhost', 123, 456 ) ).not_to be_nil
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/registry'
|
3
|
+
require 'leafy/metrics/jruby_metrics'
|
4
|
+
|
5
|
+
describe Leafy::Metrics::JRubyMetrics do
|
6
|
+
|
7
|
+
subject do
|
8
|
+
r = Leafy::Metrics::Registry.new
|
9
|
+
Leafy::Metrics::JRubyMetrics.register_ruby_thread_state_gauges( r, 'test' )
|
10
|
+
r
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'registers and unregister a meter' do
|
14
|
+
|
15
|
+
expect( subject.metrics.gauges['test.total.count'].value ).to eq 1
|
16
|
+
expect( subject.metrics.gauges['test.executing.count'].value ).to eq 1
|
17
|
+
expect( subject.metrics.gauges['test.sleeping.count'].value ).to eq 0
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/registry'
|
3
|
+
require 'leafy/metrics/jvm_metrics'
|
4
|
+
|
5
|
+
describe Leafy::Metrics::JvmMetrics do
|
6
|
+
|
7
|
+
let(:registry) { Leafy::Metrics::Registry.new }
|
8
|
+
|
9
|
+
describe "register_thread_state_gauges" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
Leafy::Metrics::JvmMetrics.register_thread_state_gauges( registry, 'test' )
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'registers gauges' do
|
16
|
+
|
17
|
+
expect( registry.metrics.names.to_a ).to include( *["test.blocked.count", "test.count", "test.daemon.count", "test.deadlock.count", "test.deadlocks", "test.new.count", "test.runnable.count", "test.terminated.count", "test.timed_waiting.count", "test.waiting.count"] )
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'follows changes in thread counts' do
|
21
|
+
|
22
|
+
total = registry.metrics.gauges['test.count'].value
|
23
|
+
|
24
|
+
t = Thread.new do
|
25
|
+
Thread.current[:running] = true
|
26
|
+
while( Thread.current[:running] ) do
|
27
|
+
sleep 0.1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
expect( registry.metrics.gauges['test.count'].value ).to eq total + 1
|
32
|
+
|
33
|
+
t[:running] = false
|
34
|
+
sleep 0.1
|
35
|
+
t.join
|
36
|
+
|
37
|
+
expect( registry.metrics.gauges['test.count'].value ).to eq total
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "register_memory_usage_gauges" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
Leafy::Metrics::JvmMetrics.register_memory_usage_gauges( registry, 'test' )
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'registers gauges' do
|
48
|
+
|
49
|
+
expect( registry.metrics.names.to_a ).to include( *["test.heap.committed", "test.heap.init", "test.heap.max", "test.heap.usage", "test.heap.used", "test.non-heap.committed", "test.non-heap.init", "test.non-heap.max", "test.non-heap.usage", "test.non-heap.used", "test.total.committed", "test.total.init", "test.total.max", "test.total.used"] )
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "register_buffer_pool_metrics" do
|
55
|
+
|
56
|
+
before do
|
57
|
+
Leafy::Metrics::JvmMetrics.register_buffer_pool_metrics( registry, 'test' )
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'registers metrics' do
|
61
|
+
|
62
|
+
expect( registry.metrics.names.to_a ).to include( *["test.direct.capacity", "test.direct.count", "test.direct.used", "test.mapped.capacity", "test.mapped.count", "test.mapped.used"] )
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "register_garbage_collector_metrics" do
|
68
|
+
|
69
|
+
before do
|
70
|
+
Leafy::Metrics::JvmMetrics.register_garbage_collector_metrics( registry, 'test' )
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'registers metrics' do
|
74
|
+
|
75
|
+
expect( registry.metrics.names.to_a ).to include( *["test.PS-MarkSweep.count", "test.PS-MarkSweep.time", "test.PS-Scavenge.count", "test.PS-Scavenge.time"] )
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
require 'leafy/metrics/registry'
|
3
|
+
|
4
|
+
describe Leafy::Metrics::Registry do
|
5
|
+
|
6
|
+
subject { Leafy::Metrics::Registry.new }
|
7
|
+
|
8
|
+
it 'registers and unregister a meter' do
|
9
|
+
obj = subject.register_meter('me')
|
10
|
+
expect(obj).to be_a(Java::ComCodahaleMetrics::Meter)
|
11
|
+
expect(subject.metrics.meters['me']).to be obj
|
12
|
+
expect(obj.respond_to? :mark).to be true
|
13
|
+
|
14
|
+
subject.remove('me')
|
15
|
+
expect(subject.metrics.meters).to be_empty
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'registers and unregister a counter' do
|
19
|
+
obj = subject.register_counter('me')
|
20
|
+
expect(obj).to be_a(Java::ComCodahaleMetrics::Counter)
|
21
|
+
expect(subject.metrics.counters['me']).to be obj
|
22
|
+
expect(obj.respond_to? :inc).to be true
|
23
|
+
expect(obj.respond_to? :dec).to be true
|
24
|
+
|
25
|
+
subject.remove('me')
|
26
|
+
expect(subject.metrics.counters).to be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'registers and unregister a histogram' do
|
30
|
+
obj = subject.register_histogram('me')
|
31
|
+
expect(obj).to be_a(Java::ComCodahaleMetrics::Histogram)
|
32
|
+
expect(subject.metrics.histograms['me']).to be obj
|
33
|
+
expect(obj.respond_to? :update).to be true
|
34
|
+
|
35
|
+
subject.remove('me')
|
36
|
+
expect(subject.metrics.histograms).to be_empty
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'registers and unregister a timer' do
|
40
|
+
obj = subject.register_timer('me')
|
41
|
+
expect(obj).to be_a(Leafy::Metrics::Registry::Timer)
|
42
|
+
expect(subject.metrics.timers['me']).to be obj.timer
|
43
|
+
expect(obj.timer.respond_to? :time).to be true
|
44
|
+
|
45
|
+
subject.remove('me')
|
46
|
+
expect(subject.metrics.timers).to be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'registers and unregister gauge as block' do
|
50
|
+
obj = subject.register_gauge('me') do
|
51
|
+
123
|
52
|
+
end
|
53
|
+
expect(obj).to be_a(Leafy::Metrics::Gauge)
|
54
|
+
expect(subject.metrics.gauges['me']).to be obj
|
55
|
+
expect(obj.value).to eq 123
|
56
|
+
|
57
|
+
subject.remove('me')
|
58
|
+
expect(subject.metrics.gauges).to be_empty
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'registers and unregister gauge as object with call method' do
|
62
|
+
obj = subject.register_gauge('me', Proc.new do
|
63
|
+
123
|
64
|
+
end )
|
65
|
+
expect(obj).to be_a(Leafy::Metrics::Gauge)
|
66
|
+
expect(subject.metrics.gauges['me']).to be obj
|
67
|
+
expect(obj.value).to eq 123
|
68
|
+
|
69
|
+
subject.remove('me')
|
70
|
+
expect(subject.metrics.gauges).to be_empty
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'registers and unregister com.codahale.metrics.Gauge' do
|
74
|
+
g = Leafy::Metrics::Gauge.new
|
75
|
+
def g.value
|
76
|
+
123
|
77
|
+
end
|
78
|
+
obj = subject.register_gauge('me', g)
|
79
|
+
expect(obj).to be_a(Leafy::Metrics::Gauge)
|
80
|
+
expect(subject.metrics.gauges['me']).to be obj
|
81
|
+
expect(obj.value).to eq 123
|
82
|
+
|
83
|
+
subject.remove('me')
|
84
|
+
expect(subject.metrics.gauges).to be_empty
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'fails register gauge as object without call method' do
|
88
|
+
expect { subject.register_gauge('me', Object.new ) }.to raise_error
|
89
|
+
end
|
90
|
+
|
91
|
+
describe Leafy::Metrics::Registry::Timer do
|
92
|
+
|
93
|
+
it 'can messure duration' do
|
94
|
+
obj = subject.register_timer('me')
|
95
|
+
expect(obj.timer.mean_rate).to eq 0.0
|
96
|
+
|
97
|
+
obj.time do
|
98
|
+
sleep 0.1
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(obj.timer.mean_rate).to be > 0.0
|
102
|
+
|
103
|
+
subject.remove('me')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/spec/setup.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path( '../../lib', __FILE__ )
|
2
|
+
require 'jar-dependencies'
|
3
|
+
|
4
|
+
# setup logging
|
5
|
+
LOG_FILE = File.expand_path( '../../pkg/log', __FILE__ )
|
6
|
+
require 'fileutils'
|
7
|
+
FileUtils.mkdir_p File.dirname( LOG_FILE )
|
8
|
+
FileUtils.rm_f( LOG_FILE )
|
9
|
+
java.lang.System.set_property( 'org.slf4j.simpleLogger.logFile', LOG_FILE )
|
10
|
+
require_jar( 'org.slf4j', 'slf4j-simple', '1.7.7' )
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leafy-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- christian meier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.1.8
|
19
|
+
name: jar-dependencies
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.1'
|
33
|
+
name: rspec
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.7
|
47
|
+
name: yard
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.2'
|
61
|
+
name: rake
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.2'
|
69
|
+
description: 'provides an API to register metrics like meters, timers, gauge, counter
|
70
|
+
using dropwizard-metrics. it also allows to setup reporters: console-reporter, csv-reporter
|
71
|
+
and graphite-reporter'
|
72
|
+
email:
|
73
|
+
- christian.meier@lookout.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- leafy-metrics.gemspec
|
84
|
+
- lib/leafy-metrics.rb
|
85
|
+
- lib/leafy-metrics_jars.rb
|
86
|
+
- lib/leafy/metrics.rb
|
87
|
+
- lib/leafy/metrics/console_reporter.rb
|
88
|
+
- lib/leafy/metrics/csv_reporter.rb
|
89
|
+
- lib/leafy/metrics/graphite/graphite.rb
|
90
|
+
- lib/leafy/metrics/graphite/graphite_reporter.rb
|
91
|
+
- lib/leafy/metrics/jruby_metrics.rb
|
92
|
+
- lib/leafy/metrics/jvm_metrics.rb
|
93
|
+
- lib/leafy/metrics/registry.rb
|
94
|
+
- lib/leafy/metrics/reporter.rb
|
95
|
+
- lib/leafy/metrics/version.rb
|
96
|
+
- spec/console_reporter_spec.rb
|
97
|
+
- spec/csv_reporter_spec.rb
|
98
|
+
- spec/graphite_reporter_spec.rb
|
99
|
+
- spec/graphite_spec.rb
|
100
|
+
- spec/jruby_metrics_spec.rb
|
101
|
+
- spec/jvm_metrics_spec.rb
|
102
|
+
- spec/registry_spec.rb
|
103
|
+
- spec/setup.rb
|
104
|
+
homepage: https://github.com/lookout/leafy
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements:
|
123
|
+
- jar io.dropwizard.metrics:metrics-core, 3.1.0
|
124
|
+
- jar io.dropwizard.metrics:metrics-graphite, 3.1.0
|
125
|
+
- jar io.dropwizard.metrics:metrics-jvm, 3.1.0
|
126
|
+
- jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.5
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: provide an API to register metrics
|
132
|
+
test_files: []
|
133
|
+
has_rdoc:
|