leafy-rack 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,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,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
|
|
@@ -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' )
|
data/leafy-rack/Gemfile
ADDED
data/leafy-rack/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
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Leafy-Rack
|
|
2
|
+
|
|
3
|
+
## installation
|
|
4
|
+
|
|
5
|
+
via rubygems
|
|
6
|
+
```
|
|
7
|
+
gem install leafy-rack
|
|
8
|
+
```
|
|
9
|
+
or add to your Gemfile
|
|
10
|
+
```
|
|
11
|
+
gem 'leafy-rack
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
installing the gem also takes care of the jar dependencies with jruby-1.7.16+
|
|
15
|
+
|
|
16
|
+
## intro
|
|
17
|
+
|
|
18
|
+
there actually three parts to this gem
|
|
19
|
+
|
|
20
|
+
* serializers to write out json data from the collected data of ```Leafy::Health::Registry``` and ```Leafy::Metrics::Registry```
|
|
21
|
+
|
|
22
|
+
* instrumented class which is almost like a rack middleware but is threadsafe and is meant to be shared with **ALL** requests. with this sharing in can count the number of active requests.
|
|
23
|
+
|
|
24
|
+
* a collection of middleware
|
|
25
|
+
|
|
26
|
+
## serializers for health and metrics data
|
|
27
|
+
|
|
28
|
+
are using the internal API of ```Leafy::Health::Registry``` or ```Leafy::Metrics::Registry``` to ```run_health_checks``` or retrieve the collect metrics and produces the json representation of these data.
|
|
29
|
+
|
|
30
|
+
registry = Leafy::Health::Registry.new
|
|
31
|
+
json_writer = Leafy::Json::HealthWriter.new
|
|
32
|
+
json_writer.to_json( registry.health.run_health_checks )
|
|
33
|
+
|
|
34
|
+
or
|
|
35
|
+
|
|
36
|
+
registry = Leafy::Metrics::Registry.new
|
|
37
|
+
json_writer = Leafy::Json::MetricsWriter.new
|
|
38
|
+
json_writer.to_json( registry.metrics )
|
|
39
|
+
|
|
40
|
+
both json writers can take a second argument to generate pretty prints:
|
|
41
|
+
|
|
42
|
+
json_writer.to_json( registry.health.run_health_checks, true )
|
|
43
|
+
json_writer.to_json( registry.metrics, true )
|
|
44
|
+
|
|
45
|
+
## instrumented http response
|
|
46
|
+
|
|
47
|
+
the class ```Leafy::Instrumented::Instrumented``` has a call method which expect a block. the block needs to return the usual rack middleware result ```[status, headers, body]```.
|
|
48
|
+
|
|
49
|
+
typical usage of this inside a rack-middleware
|
|
50
|
+
|
|
51
|
+
metrics = Leafy::Metrics::Registry.new
|
|
52
|
+
instrumented = Leafy::Instrumented::Instrumented.new( metrics, 'myapp' )
|
|
53
|
+
instrumented.call do
|
|
54
|
+
@app.call( env )
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
see the ```Leafy::Rack::Instrumented``` for an example.
|
|
58
|
+
|
|
59
|
+
## rack middleware
|
|
60
|
+
|
|
61
|
+
* instrumented middleware collecting metrics on response status, response time, and active requests
|
|
62
|
+
* json data of metrics snapshot
|
|
63
|
+
* json data of current health
|
|
64
|
+
* ping
|
|
65
|
+
* java thread-dump
|
|
66
|
+
* admin page with links to metrics, health, ping and thread-dump data
|
|
67
|
+
|
|
68
|
+
### instrumented middleware
|
|
69
|
+
|
|
70
|
+
metrics = Leafy::Metrics::Registry.new
|
|
71
|
+
use Leafy::Rack::Instrumented, Leafy::Instrumented::Instrumented.new( metrics, 'webapp' )
|
|
72
|
+
|
|
73
|
+
note: when this instrumented middleware gets configured **after** any of the admin middleware (see below) then those admin requests are not going into the instrumented metrics.
|
|
74
|
+
|
|
75
|
+
### metrics middleware
|
|
76
|
+
|
|
77
|
+
json data of a snapshot of metrics are under the path **/metrics**
|
|
78
|
+
|
|
79
|
+
metrics = Leafy::Metrics::Registry.new
|
|
80
|
+
use Leafy::Rack::Metrics, metrics
|
|
81
|
+
|
|
82
|
+
or with custom path
|
|
83
|
+
|
|
84
|
+
metrics = Leafy::Metrics::Registry.new
|
|
85
|
+
use Leafy::Rack::Metrics, metrics, '/admin/metrics'
|
|
86
|
+
|
|
87
|
+
### health-checks middleware
|
|
88
|
+
|
|
89
|
+
json data of current health are under the path **/health**
|
|
90
|
+
|
|
91
|
+
health = Leafy::Health::Registry.new
|
|
92
|
+
use Leafy::Rack::Health, health
|
|
93
|
+
|
|
94
|
+
or with custom path
|
|
95
|
+
|
|
96
|
+
health = Leafy::Health::Registry.new
|
|
97
|
+
use Leafy::Rack::Health, health, '/admin/health'
|
|
98
|
+
|
|
99
|
+
### ping middleware
|
|
100
|
+
|
|
101
|
+
under the path **/ping**
|
|
102
|
+
|
|
103
|
+
use Leafy::Rack::Ping
|
|
104
|
+
|
|
105
|
+
or with custom path
|
|
106
|
+
|
|
107
|
+
use Leafy::Rack::Ping, '/admin/ping'
|
|
108
|
+
|
|
109
|
+
### java thread-dump middleware
|
|
110
|
+
|
|
111
|
+
under the path **/threads**
|
|
112
|
+
|
|
113
|
+
use Leafy::Rack::ThreadDump
|
|
114
|
+
|
|
115
|
+
or with custom path
|
|
116
|
+
|
|
117
|
+
use Leafy::Rack::ThreadDump, '/admin/threads'
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### admin page middleware
|
|
121
|
+
|
|
122
|
+
a simple page with links to metrics, health, ping and thread-dump data under the path **/admin**
|
|
123
|
+
|
|
124
|
+
metrics = Leafy::Metrics::Registry.new
|
|
125
|
+
health = Leafy::Health::Registry.new
|
|
126
|
+
|
|
127
|
+
use Leafy::Rack::Admin, metrics, health
|
|
128
|
+
|
|
129
|
+
or with custom path
|
|
130
|
+
|
|
131
|
+
metrics = Leafy::Metrics::Registry.new
|
|
132
|
+
health = Leafy::Health::Registry.new
|
|
133
|
+
|
|
134
|
+
use Leafy::Rack::Admin, metrics, health, '/hidden/admin'
|
|
135
|
+
|
|
136
|
+
## example sinatra app
|
|
137
|
+
|
|
138
|
+
there is an [example sinatra application](https://github.com/lookout/leafy/tree/master/examples/hellowarld) which uses admin and instrumented middleware and adds some extra metrics inside the application.
|
|
139
|
+
|
|
140
|
+
## developement
|
|
141
|
+
|
|
142
|
+
get all the gems and jars in place
|
|
143
|
+
|
|
144
|
+
gem install jar-dependencies --development
|
|
145
|
+
bundle install
|
|
146
|
+
|
|
147
|
+
please make sure you are using jar-dependencies > 0.1.8 !
|
|
148
|
+
|
|
149
|
+
for running all specs
|
|
150
|
+
|
|
151
|
+
rake
|
|
152
|
+
|
|
153
|
+
or
|
|
154
|
+
|
|
155
|
+
rspec spec/reporter_spec.rb
|
data/leafy-rack/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 Rack Middleware"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task :default => [ :spec ]
|
|
13
|
+
|
|
14
|
+
# vim: syntax=Ruby
|
|
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
|
19
19
|
s.requirements << 'jar io.dropwizard.metrics:metrics-jvm, 3.1.0'
|
|
20
20
|
|
|
21
21
|
s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
|
|
22
|
-
s.add_runtime_dependency 'leafy-metrics',
|
|
23
|
-
s.add_runtime_dependency 'leafy-health',
|
|
22
|
+
s.add_runtime_dependency 'leafy-metrics', "~> #{Leafy::Rack::VERSION}"
|
|
23
|
+
s.add_runtime_dependency 'leafy-health', "~> #{Leafy::Rack::VERSION}"
|
|
24
24
|
s.add_development_dependency 'rspec', '~> 3.1.0'
|
|
25
25
|
s.add_development_dependency 'yard', '~> 0.8.7'
|
|
26
26
|
s.add_development_dependency 'rake', '~> 10.2'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|