leafy-rack 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +34 -4
- data/.travis.yml +19 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -8
- data/README.md +10 -148
- data/examples/datadog/.gitignore +2 -0
- data/examples/datadog/Gemfile +12 -0
- data/examples/datadog/Mavenfile +22 -0
- data/examples/datadog/README.md +16 -0
- data/examples/datadog/lib/java_gauge.rb +20 -0
- data/examples/datadog/lib/metrics.rb +18 -0
- data/examples/datadog/lib/ruby_gauge.rb +19 -0
- data/examples/hellowarld/.gitignore +3 -0
- data/examples/hellowarld/Gemfile +15 -0
- data/examples/hellowarld/Mavenfile +162 -0
- data/examples/hellowarld/README.md +44 -0
- data/examples/hellowarld/Rakefile +13 -0
- data/examples/hellowarld/WEB-INF/web.xml +31 -0
- data/examples/hellowarld/app/hellowarld.rb +55 -0
- data/examples/hellowarld/app/views/person.erb +52 -0
- data/examples/hellowarld/config.ru +12 -0
- data/leafy-complete.gemspec +22 -0
- data/leafy-health/.gitignore +4 -0
- data/leafy-health/Gemfile +7 -0
- data/leafy-health/LICENSE +22 -0
- data/leafy-health/README.md +123 -0
- data/leafy-health/Rakefile +14 -0
- data/leafy-health/leafy-health.gemspec +27 -0
- data/leafy-health/lib/leafy-health.rb +2 -0
- data/leafy-health/lib/leafy-health_jars.rb +7 -0
- data/leafy-health/lib/leafy/health.rb +2 -0
- data/leafy-health/lib/leafy/health/health_check.rb +72 -0
- data/leafy-health/lib/leafy/health/registry.rb +55 -0
- data/leafy-health/lib/leafy/health/version.rb +6 -0
- data/leafy-health/spec/registry_spec.rb +164 -0
- data/leafy-health/spec/setup.rb +1 -0
- data/leafy-logger/.gitignore +5 -0
- data/leafy-logger/Gemfile +9 -0
- data/leafy-logger/LICENSE +22 -0
- data/leafy-logger/README.md +174 -0
- data/{Rakefile → leafy-logger/Rakefile} +0 -0
- data/leafy-logger/leafy-logger.gemspec +32 -0
- data/leafy-logger/lib/leafy-logger.rb +1 -0
- data/leafy-logger/lib/leafy-logger_jars.rb +33 -0
- data/leafy-logger/lib/leafy/logger.rb +1 -0
- data/leafy-logger/lib/leafy/logger/appender_factories.rb +89 -0
- data/leafy-logger/lib/leafy/logger/factory.rb +141 -0
- data/leafy-logger/lib/leafy/logger/version.rb +6 -0
- data/leafy-logger/spec/appender_factories_spec.rb +147 -0
- data/leafy-logger/spec/factory_spec.rb +176 -0
- data/leafy-logger/spec/logging.yml +16 -0
- data/leafy-logger/spec/setup.rb +2 -0
- data/leafy-metrics/.gitignore +5 -0
- data/leafy-metrics/Gemfile +7 -0
- data/leafy-metrics/LICENSE +22 -0
- data/leafy-metrics/README.md +221 -0
- data/leafy-metrics/Rakefile +14 -0
- data/leafy-metrics/leafy-metrics.gemspec +29 -0
- data/leafy-metrics/lib/leafy-metrics.rb +2 -0
- data/leafy-metrics/lib/leafy-metrics_jars.rb +5 -0
- data/leafy-metrics/lib/leafy/metrics.rb +2 -0
- data/leafy-metrics/lib/leafy/metrics/console_reporter.rb +32 -0
- data/leafy-metrics/lib/leafy/metrics/csv_reporter.rb +26 -0
- data/leafy-metrics/lib/leafy/metrics/graphite/graphite.rb +28 -0
- data/leafy-metrics/lib/leafy/metrics/graphite/graphite_reporter.rb +43 -0
- data/leafy-metrics/lib/leafy/metrics/registry.rb +108 -0
- data/leafy-metrics/lib/leafy/metrics/reporter.rb +51 -0
- data/leafy-metrics/lib/leafy/metrics/version.rb +6 -0
- data/leafy-metrics/spec/console_reporter_spec.rb +72 -0
- data/leafy-metrics/spec/csv_reporter_spec.rb +75 -0
- data/leafy-metrics/spec/graphite_reporter_spec.rb +72 -0
- data/leafy-metrics/spec/graphite_spec.rb +23 -0
- data/leafy-metrics/spec/registry_spec.rb +106 -0
- data/leafy-metrics/spec/setup.rb +10 -0
- data/leafy-rack/.gitignore +4 -0
- data/leafy-rack/Gemfile +10 -0
- data/leafy-rack/LICENSE +22 -0
- data/leafy-rack/README.md +155 -0
- data/leafy-rack/Rakefile +14 -0
- data/{leafy-rack.gemspec → leafy-rack/leafy-rack.gemspec} +2 -2
- data/{lib → leafy-rack/lib}/leafy-rack.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy-rack_jars.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/instrumented/basic_instrumented.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/instrumented/instrumented.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/json/health_writer.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/json/json_writer.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/json/metrics_writer.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/admin.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/health.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/instrumented.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/metrics.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/ping.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/thread_dump.rb +0 -0
- data/{lib → leafy-rack/lib}/leafy/rack/version.rb +1 -1
- data/{spec → leafy-rack/spec}/admin_rack_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/basic_instrumented_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/health_rack_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/health_writer_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/instrumented_rack_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/instrumented_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/metrics_rack_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/metrics_writer_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/ping_rack_spec.rb +0 -0
- data/{spec → leafy-rack/spec}/setup.rb +0 -0
- data/{spec → leafy-rack/spec}/thread_dump_spec.rb +0 -0
- metadata +110 -34
@@ -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,29 @@
|
|
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.license = 'MIT'
|
12
|
+
s.summary = %q(provide an API to register metrics)
|
13
|
+
s.homepage = 'https://github.com/lookout/leafy'
|
14
|
+
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)
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
|
18
|
+
METRICS_VERSION = '3.1.0'
|
19
|
+
s.requirements << "jar io.dropwizard.metrics:metrics-core, #{METRICS_VERSION}"
|
20
|
+
s.requirements << "jar io.dropwizard.metrics:metrics-graphite, #{METRICS_VERSION}"
|
21
|
+
s.requirements << "jar org.slf4j, slf4j-simple, 1.7.7, :scope => :test"
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
|
24
|
+
s.add_development_dependency 'rspec', '~> 3.1.0'
|
25
|
+
s.add_development_dependency 'yard', '~> 0.8.7'
|
26
|
+
s.add_development_dependency 'rake', '~> 10.2'
|
27
|
+
end
|
28
|
+
|
29
|
+
# vim: syntax=Ruby
|
@@ -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,108 @@
|
|
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 remove( name )
|
98
|
+
@metrics.remove( name )
|
99
|
+
end
|
100
|
+
|
101
|
+
def reporter_builder( clazz, &block )
|
102
|
+
r = clazz.for_registry( @metrics )
|
103
|
+
r.instance_eval( &block ) if block
|
104
|
+
r
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
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
|