leafy-health 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +34 -4
  3. data/.travis.yml +19 -0
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +1 -5
  6. data/README.md +10 -116
  7. data/examples/datadog/.gitignore +2 -0
  8. data/examples/datadog/Gemfile +12 -0
  9. data/examples/datadog/Mavenfile +22 -0
  10. data/examples/datadog/README.md +16 -0
  11. data/examples/datadog/lib/java_gauge.rb +20 -0
  12. data/examples/datadog/lib/metrics.rb +18 -0
  13. data/examples/datadog/lib/ruby_gauge.rb +19 -0
  14. data/examples/hellowarld/.gitignore +3 -0
  15. data/examples/hellowarld/Gemfile +15 -0
  16. data/examples/hellowarld/Mavenfile +162 -0
  17. data/examples/hellowarld/README.md +44 -0
  18. data/examples/hellowarld/Rakefile +13 -0
  19. data/examples/hellowarld/WEB-INF/web.xml +31 -0
  20. data/examples/hellowarld/app/hellowarld.rb +55 -0
  21. data/examples/hellowarld/app/views/person.erb +52 -0
  22. data/examples/hellowarld/config.ru +12 -0
  23. data/leafy-complete.gemspec +22 -0
  24. data/leafy-health/.gitignore +4 -0
  25. data/leafy-health/Gemfile +7 -0
  26. data/leafy-health/LICENSE +22 -0
  27. data/leafy-health/README.md +123 -0
  28. data/{Rakefile → leafy-health/Rakefile} +0 -0
  29. data/{leafy-health.gemspec → leafy-health/leafy-health.gemspec} +0 -0
  30. data/{lib → leafy-health/lib}/leafy-health.rb +0 -0
  31. data/{lib → leafy-health/lib}/leafy-health_jars.rb +0 -0
  32. data/{lib → leafy-health/lib}/leafy/health.rb +0 -0
  33. data/{lib → leafy-health/lib}/leafy/health/health_check.rb +0 -0
  34. data/{lib → leafy-health/lib}/leafy/health/registry.rb +0 -0
  35. data/{lib → leafy-health/lib}/leafy/health/version.rb +1 -1
  36. data/{spec → leafy-health/spec}/registry_spec.rb +0 -0
  37. data/{spec → leafy-health/spec}/setup.rb +0 -0
  38. data/leafy-logger/.gitignore +5 -0
  39. data/leafy-logger/Gemfile +9 -0
  40. data/leafy-logger/LICENSE +22 -0
  41. data/leafy-logger/README.md +174 -0
  42. data/leafy-logger/Rakefile +14 -0
  43. data/leafy-logger/leafy-logger.gemspec +32 -0
  44. data/leafy-logger/lib/leafy-logger.rb +1 -0
  45. data/leafy-logger/lib/leafy-logger_jars.rb +33 -0
  46. data/leafy-logger/lib/leafy/logger.rb +1 -0
  47. data/leafy-logger/lib/leafy/logger/appender_factories.rb +89 -0
  48. data/leafy-logger/lib/leafy/logger/factory.rb +141 -0
  49. data/leafy-logger/lib/leafy/logger/version.rb +6 -0
  50. data/leafy-logger/spec/appender_factories_spec.rb +147 -0
  51. data/leafy-logger/spec/factory_spec.rb +176 -0
  52. data/leafy-logger/spec/logging.yml +16 -0
  53. data/leafy-logger/spec/setup.rb +2 -0
  54. data/leafy-metrics/.gitignore +5 -0
  55. data/leafy-metrics/Gemfile +7 -0
  56. data/leafy-metrics/LICENSE +22 -0
  57. data/leafy-metrics/README.md +221 -0
  58. data/leafy-metrics/Rakefile +14 -0
  59. data/leafy-metrics/leafy-metrics.gemspec +29 -0
  60. data/leafy-metrics/lib/leafy-metrics.rb +2 -0
  61. data/leafy-metrics/lib/leafy-metrics_jars.rb +5 -0
  62. data/leafy-metrics/lib/leafy/metrics.rb +2 -0
  63. data/leafy-metrics/lib/leafy/metrics/console_reporter.rb +32 -0
  64. data/leafy-metrics/lib/leafy/metrics/csv_reporter.rb +26 -0
  65. data/leafy-metrics/lib/leafy/metrics/graphite/graphite.rb +28 -0
  66. data/leafy-metrics/lib/leafy/metrics/graphite/graphite_reporter.rb +43 -0
  67. data/leafy-metrics/lib/leafy/metrics/registry.rb +108 -0
  68. data/leafy-metrics/lib/leafy/metrics/reporter.rb +51 -0
  69. data/leafy-metrics/lib/leafy/metrics/version.rb +6 -0
  70. data/leafy-metrics/spec/console_reporter_spec.rb +72 -0
  71. data/leafy-metrics/spec/csv_reporter_spec.rb +75 -0
  72. data/leafy-metrics/spec/graphite_reporter_spec.rb +72 -0
  73. data/leafy-metrics/spec/graphite_spec.rb +23 -0
  74. data/leafy-metrics/spec/registry_spec.rb +106 -0
  75. data/leafy-metrics/spec/setup.rb +10 -0
  76. data/leafy-rack/.gitignore +4 -0
  77. data/leafy-rack/Gemfile +10 -0
  78. data/leafy-rack/LICENSE +22 -0
  79. data/leafy-rack/README.md +155 -0
  80. data/leafy-rack/Rakefile +14 -0
  81. data/leafy-rack/leafy-rack.gemspec +29 -0
  82. data/leafy-rack/lib/leafy-rack.rb +1 -0
  83. data/leafy-rack/lib/leafy-rack_jars.rb +10 -0
  84. data/leafy-rack/lib/leafy/instrumented/basic_instrumented.rb +38 -0
  85. data/leafy-rack/lib/leafy/instrumented/instrumented.rb +27 -0
  86. data/leafy-rack/lib/leafy/json/health_writer.rb +15 -0
  87. data/leafy-rack/lib/leafy/json/json_writer.rb +33 -0
  88. data/leafy-rack/lib/leafy/json/metrics_writer.rb +22 -0
  89. data/leafy-rack/lib/leafy/rack.rb +1 -0
  90. data/leafy-rack/lib/leafy/rack/admin.rb +73 -0
  91. data/leafy-rack/lib/leafy/rack/health.rb +43 -0
  92. data/leafy-rack/lib/leafy/rack/instrumented.rb +20 -0
  93. data/leafy-rack/lib/leafy/rack/metrics.rb +35 -0
  94. data/leafy-rack/lib/leafy/rack/ping.rb +29 -0
  95. data/leafy-rack/lib/leafy/rack/thread_dump.rb +56 -0
  96. data/leafy-rack/lib/leafy/rack/version.rb +6 -0
  97. data/leafy-rack/spec/admin_rack_spec.rb +141 -0
  98. data/leafy-rack/spec/basic_instrumented_spec.rb +31 -0
  99. data/leafy-rack/spec/health_rack_spec.rb +136 -0
  100. data/leafy-rack/spec/health_writer_spec.rb +47 -0
  101. data/leafy-rack/spec/instrumented_rack_spec.rb +37 -0
  102. data/leafy-rack/spec/instrumented_spec.rb +36 -0
  103. data/leafy-rack/spec/metrics_rack_spec.rb +110 -0
  104. data/leafy-rack/spec/metrics_writer_spec.rb +55 -0
  105. data/leafy-rack/spec/ping_rack_spec.rb +63 -0
  106. data/leafy-rack/spec/setup.rb +3 -0
  107. data/leafy-rack/spec/thread_dump_spec.rb +59 -0
  108. metadata +106 -12
@@ -0,0 +1,6 @@
1
+ module Leafy
2
+ module Logger
3
+ VERSION = '0.3.1'.freeze
4
+ end
5
+ end
6
+
@@ -0,0 +1,147 @@
1
+ require_relative 'setup'
2
+ require 'leafy/metrics/registry'
3
+ require 'leafy/logger/factory'
4
+ require 'leafy/logger/appender_factories'
5
+ require 'fileutils'
6
+
7
+ describe Leafy::Logger do
8
+
9
+ let( :factory ) do
10
+ f = Leafy::Logger::Factory.new
11
+ f.level :debug
12
+ f.configure( Leafy::Metrics::Registry.new, 'tester' )
13
+ f
14
+ end
15
+
16
+ let( :logger ) { Leafy::Logger::Factory.get_logger 'ROOT' }
17
+
18
+ describe Leafy::Logger::ConsoleAppenderFactory do
19
+
20
+ subject do
21
+ Leafy::Logger::ConsoleAppenderFactory.new do
22
+ target 'STDOUT'
23
+ end
24
+ end
25
+
26
+ it 'can set the target' do
27
+ expect(subject.target).to eq 'STDOUT'
28
+
29
+ subject.target = 'STDERR'
30
+ expect(subject.target).to eq 'STDERR'
31
+ end
32
+ end
33
+
34
+ describe Leafy::Logger::SyslogAppenderFactory do
35
+
36
+ subject do
37
+ Leafy::Logger::SyslogAppenderFactory.new
38
+ end
39
+
40
+ it 'can use default configuration with syslog' do
41
+
42
+ factory.appenders subject
43
+
44
+ logger.debug( 'debug' )
45
+ logger.info( 'info' )
46
+
47
+ factory.stop
48
+
49
+ if not system("netstat -uln |grep :514")
50
+ last = File.read( '/var/log/syslog' ).split( /\n/ ).last
51
+ expect(last).to match /info$/
52
+ end
53
+ end
54
+
55
+ it 'can configure syslog' do
56
+ subject.port = 514
57
+ subject.include_stack_trace = false
58
+ subject.host = '127.0.0.1'
59
+ subject.facility = :auth
60
+ subject.stack_trace_prefix = '__'
61
+ subject.threshold = :debug
62
+
63
+ factory.appenders subject
64
+
65
+ logger.debug( 'debug' )
66
+ logger.info( 'info', java.lang.Exception.new( 'help me' ) )
67
+
68
+ factory.stop
69
+
70
+ if not system("netstat -uln |grep :514") and File.exist?( '/var/log/auth.log' )
71
+ last = File.read( '/var/log/auth.log' ).split( /\n/ ).last
72
+ expect(last).to match /info$/
73
+ end
74
+ end
75
+ end
76
+
77
+ describe Leafy::Logger::FileAppenderFactory do
78
+
79
+ subject do
80
+ Leafy::Logger::FileAppenderFactory.new
81
+ end
82
+
83
+ let( :log ) { File.join( File.dirname( __FILE__ ), 'test.log' ) }
84
+
85
+ before { FileUtils.rm_f log }
86
+ after { FileUtils.rm_f log }
87
+
88
+ it 'can be configured with single file' do
89
+ subject.current_log_filename = log
90
+ subject.archive = false
91
+ subject.threshold = 'INFO'
92
+ subject.log_format = "%-5p [%d{ISO8601,UTC}] %c: %m%n%ex"
93
+
94
+ factory.appenders subject
95
+ logger.debug( 'debug' )
96
+ logger.info( 'info', java.lang.Exception.new( 'help' ) )
97
+
98
+ factory.stop
99
+
100
+ lines = File.read( log ).split( /\n/ )
101
+ lines.each do |line|
102
+ expect( line ).to match /^INFO.*info|^!.*help|^!.*at/
103
+ end
104
+ end
105
+
106
+ it 'can be configured via block' do
107
+ l = log
108
+ s = subject.class.new do
109
+ self.current_log_filename = l
110
+ self.archive = false
111
+ self.threshold = 'DEBUG'
112
+ self.log_format = "%-5p [%d{ISO8601,UTC}] %c: %m%n%rEx"
113
+ end
114
+
115
+ factory.appenders s
116
+ logger.debug( 'debug' )
117
+ logger.info( 'info', java.lang.Exception.new( 'help' ) )
118
+
119
+ factory.stop
120
+
121
+ lines = File.read( log ).split( /\n/ )
122
+ lines.each do |line|
123
+ expect( line ).to match /^INFO.*info|^DEBUG.*debug|^!.*help|^!.*at/
124
+ end
125
+ end
126
+
127
+ it 'can be configured with archived files' do
128
+ subject.current_log_filename = log
129
+ subject.archived_log_filename_pattern = "#{log}-%d.gz"
130
+ subject.archived_file_count = 2
131
+ subject.threshold = 'DEBUG'
132
+ subject.log_format = "%-5p [%d{ISO8601,UTC}] %c: %m%n%rEx"
133
+
134
+ factory.appenders subject
135
+
136
+ logger.debug( 'debug' )
137
+ logger.info( 'info', java.lang.Exception.new( 'help' ) )
138
+
139
+ factory.stop
140
+
141
+ lines = File.read( log ).split( /\n/ )
142
+ lines.each do |line|
143
+ expect( line ).to match /^INFO.*info|^DEBUG.*debug|^!.*help|^!.*at/
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,176 @@
1
+ require_relative 'setup'
2
+ require 'leafy/metrics/registry'
3
+ require 'leafy/logger/factory'
4
+ require 'fileutils'
5
+
6
+ describe Leafy::Logger::Factory do
7
+
8
+ subject do
9
+ f = Leafy::Logger::Factory.new
10
+ f.appenders( Leafy::Logger::FileAppenderFactory.new( log ) )
11
+ f.configure( Leafy::Metrics::Registry.new, 'tester' )
12
+ f
13
+ end
14
+
15
+ let( :log ) { File.join( File.dirname( __FILE__ ), 'test.log' ) }
16
+ let( :yaml ) { File.join( File.dirname( __FILE__ ), 'logging.yml' ) }
17
+ let( :logger1 ) { Leafy::Logger::Factory.get_logger 'my.app' }
18
+ let( :logger2 ) { Leafy::Logger::Factory.get_logger 'my.db' }
19
+
20
+ let( :factory_yaml ) { Leafy::Logger::Factory.new_from_yaml( yaml ) }
21
+ let( :reconfigured_yaml ) do
22
+ subject.reconfigure_from_yaml( yaml )
23
+ subject
24
+ end
25
+
26
+ let( :options ) { YAML.load( File.read( yaml ) ) }
27
+ let( :factory_options ) { Leafy::Logger::Factory.new_from_options( options ) }
28
+ let( :reconfigured_options ) do
29
+ subject.reconfigure_from_options( options )
30
+ subject
31
+ end
32
+
33
+ before { FileUtils.rm_f log }
34
+ after { FileUtils.rm_f log }
35
+
36
+ it 'can set appenders' do
37
+ expect( subject.appenders.size ).to eq 1
38
+
39
+ subject.appenders Leafy::Logger::ConsoleAppenderFactory.new
40
+ expect( subject.appenders.size ).to eq 1
41
+
42
+ subject.appenders( Leafy::Logger::ConsoleAppenderFactory.new,
43
+ Leafy::Logger::FileAppenderFactory.new( log ) )
44
+ expect( subject.appenders.size ).to eq 2
45
+ end
46
+
47
+ it 'sets the default level' do
48
+ subject.level = 'INFO'
49
+ expect( subject.level ).to eq 'INFO'
50
+
51
+ subject.level 'DEBUG'
52
+ expect( subject.level ).to eq 'DEBUG'
53
+ end
54
+
55
+ it 'can set the default log level' do
56
+ subject.level = 'INFO'
57
+
58
+ logger1.debug 'debug1'
59
+ logger1.info 'good'
60
+ logger1.warn 'good'
61
+ logger2.debug 'debug2'
62
+ logger2.info 'good'
63
+ logger2.warn 'good'
64
+
65
+ subject.stop
66
+
67
+ lines = File.read( log ).split( /\n/ )
68
+
69
+ expect( lines.size ).to eq 4
70
+ lines.each do |line|
71
+ expect( line ).to match /INFO|WARN/
72
+ expect( line ).to match /good/
73
+ end
74
+ end
75
+
76
+ it 'can set a specific log level' do
77
+ expect( subject.loggers ).to eq Hash[]
78
+
79
+ subject[ 'my.app' ] = 'WARN'
80
+
81
+ expect( subject.loggers ).to eq Hash[ 'my.app' => 'WARN' ]
82
+
83
+ logger1.debug 'debug1'
84
+ logger1.info 'info1'
85
+ logger1.warn 'good'
86
+ logger2.debug 'debug2'
87
+ logger2.info 'good'
88
+ logger2.warn 'good'
89
+
90
+ subject.stop
91
+
92
+ lines = File.read( log ).split( /\n/ )
93
+
94
+ expect( lines.size ).to eq 3
95
+ lines.each do |line|
96
+ expect( line ).to match /INFO|WARN/
97
+ expect( line ).to match /good/
98
+ end
99
+ end
100
+
101
+ it 'can set a specific log level' do
102
+ expect( subject.loggers ).to eq Hash[]
103
+
104
+ subject.loggers( 'my' => 'WARN' )
105
+
106
+ expect( subject.loggers ).to eq Hash[ 'my' => 'WARN' ]
107
+
108
+ logger1.debug 'debug1'
109
+ logger1.info 'info1'
110
+ logger1.warn 'good'
111
+ logger2.debug 'debug2'
112
+ logger2.info 'info2'
113
+ logger2.warn 'good'
114
+
115
+ subject.stop
116
+
117
+ lines = File.read( log ).split( /\n/ )
118
+
119
+ expect( lines.size ).to eq 2
120
+ lines.each do |line|
121
+ expect( line ).to match /WARN/
122
+ expect( line ).to match /good/
123
+ end
124
+
125
+ end
126
+
127
+ it 'fails on missing yaml configuration' do
128
+ expect {Leafy::Logger::Factory.new_from_yaml( yaml + '.gone' ) }.to raise_error( Exception )
129
+ end
130
+
131
+ it 'fails reconfigure on missing yaml configuration' do
132
+ expect {subject.reconfigure_from_yaml( yaml + '.gone' ) }.to raise_error( Exception )
133
+ end
134
+
135
+ [ :factory_yaml, :reconfigured_yaml ].each do |method|
136
+ it "can use a yaml configuration - #{method}" do
137
+ f = send( method )
138
+ expect( f.level ).to eq 'ERROR'
139
+ expect( f.loggers ).to eq 'com.example.app' => 'DEBUG'
140
+ expect( f.appenders.size ).to eq 3
141
+ # console
142
+ expect( f.appenders[0].threshold ).to eq 'DEBUG'
143
+ expect( f.appenders[0].target ).to eq 'STDERR'
144
+ # file
145
+ expect( f.appenders[1].threshold ).to eq 'INFO'
146
+ expect( f.appenders[1].current_log_filename ).to eq './logs/example.log'
147
+ expect( f.appenders[1].archived_log_filename_pattern ).to eq './logs/example-%d.log.gz'
148
+ expect( f.appenders[1].archived_file_count ).to eq 12
149
+ # syslog
150
+ expect( f.appenders[2].host ).to eq '127.0.0.1'
151
+ expect( f.appenders[2].port ).to eq 123
152
+ expect( f.appenders[2].facility ).to eq 'KERN'
153
+ end
154
+ end
155
+
156
+ [ :factory_options, :reconfigured_options ].each do |method|
157
+ it 'can use a hash configuration' do
158
+ f = send( method )
159
+ expect( f.level ).to eq 'ERROR'
160
+ expect( f.loggers ).to eq 'com.example.app' => 'DEBUG'
161
+ expect( f.appenders.size ).to eq 3
162
+ # console
163
+ expect( f.appenders[0].threshold ).to eq 'DEBUG'
164
+ expect( f.appenders[0].target ).to eq 'STDERR'
165
+ # file
166
+ expect( f.appenders[1].threshold ).to eq 'INFO'
167
+ expect( f.appenders[1].current_log_filename ).to eq './logs/example.log'
168
+ expect( f.appenders[1].archived_log_filename_pattern ).to eq './logs/example-%d.log.gz'
169
+ expect( f.appenders[1].archived_file_count ).to eq 12
170
+ # syslog
171
+ expect( f.appenders[2].host ).to eq '127.0.0.1'
172
+ expect( f.appenders[2].port ).to eq 123
173
+ expect( f.appenders[2].facility ).to eq 'KERN'
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,16 @@
1
+ level: ERROR
2
+ loggers:
3
+ com.example.app: DEBUG
4
+ appenders:
5
+ - type: console
6
+ threshold: DEBUG
7
+ target: STDERR
8
+ - type: file
9
+ threshold: INFO
10
+ currentLogFilename: ./logs/example.log
11
+ archivedLogFilenamePattern: ./logs/example-%d.log.gz
12
+ archivedFileCount: 12
13
+ - type: syslog
14
+ host: 127.0.0.1
15
+ port: 123
16
+ facility: KERN
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path( '../../lib', __FILE__ )
2
+ require 'jar-dependencies'
@@ -0,0 +1,5 @@
1
+ .yardoc
2
+ doc
3
+ pkg
4
+ *.lock
5
+ *.jar
@@ -0,0 +1,7 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ # vim: syntax=Ruby
@@ -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,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