Commit f59825c 1 parent 5b4b559 commit f59825c Copy full SHA for f59825c
File tree 9 files changed +36
-11
lines changed
9 files changed +36
-11
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ Metrics/BlockLength:
10
10
- " Gemfile"
11
11
- " spec/**/*"
12
12
13
+ Metrics/LineLength :
14
+ Max : 120
15
+
13
16
Style/BracesAroundHashParameters :
14
17
EnforcedStyle : context_dependent
15
18
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ sudo: false
3
3
language : ruby
4
4
cache : bundler
5
5
rvm :
6
- - 2.5.1
7
- - 2.4.4
8
- - 2.3.7
9
- before_install : gem install bundler -v 1.16.5
6
+ - 2.5.3
7
+ - 2.4.5
8
+ - 2.3.8
9
+ before_install : gem install bundler -v 1.17.0
Original file line number Diff line number Diff line change 2
2
3
3
require "bundler/gem_tasks"
4
4
require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RuboCop ::RakeTask . new
5
8
6
9
RSpec ::Core ::RakeTask . new ( :spec )
7
10
8
- task default : : spec
11
+ task default : %i[ rubocop spec ]
Original file line number Diff line number Diff line change 5
5
require "yabeda/version"
6
6
require "yabeda/dsl"
7
7
8
+ # Extendable framework for collecting and exporting metrics from Ruby apps
8
9
module Yabeda
9
10
include DSL
10
11
11
12
class << self
13
+ # @return [Hash<String, Yabeda::Metric>] All registered metrics
12
14
def metrics
13
15
@metrics ||= Concurrent ::Hash . new
14
16
end
15
17
18
+ # @return [Hash<String, Yabeda::BaseAdapter>] All loaded adapters
16
19
def adapters
17
20
@adapters ||= Concurrent ::Hash . new
18
21
end
19
22
23
+ # @return [Array<Proc>] All collectors for periodical retrieving of metrics
20
24
def collectors
21
25
@collectors ||= Concurrent ::Array . new
22
26
end
23
-
27
+
24
28
# @param [Symbol] name
25
29
# @param [BaseAdapter] instance
26
30
def register_adapter ( name , instance )
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module Yabeda
4
+ # Base class for adapters to particular monitoring systems
4
5
class BaseAdapter
5
6
def register! ( metric )
6
7
case metric
Original file line number Diff line number Diff line change 6
6
require "yabeda/histogram"
7
7
8
8
module Yabeda
9
+ # DSL for ease of work with Yabeda
9
10
module DSL
10
11
def self . included ( base )
11
12
base . extend ClassMethods
12
13
end
13
14
15
+ # rubocop: disable Style/Documentation
14
16
module ClassMethods
17
+ # Block for grouping and simplifying configuration of related metrics
15
18
def configure ( &block )
16
19
class_exec ( &block )
17
20
@group = nil
18
21
end
19
22
23
+ # Define the actions that should be performed
20
24
def collect ( &block )
21
25
::Yabeda . collectors . push ( block )
22
26
end
23
27
28
+ # Specify metric category or group for all consecutive metrics in this
29
+ # +configure+ block.
30
+ # On most adapters it is only adds prefix to the metric name but on some
31
+ # (like NewRelic) it is treated individually and have special meaning.
24
32
def group ( group_name )
25
33
@group = group_name
26
34
end
27
35
36
+ # Register a growing-only counter
28
37
def counter ( *args , **kwargs )
29
38
register ( Counter . new ( *args , **kwargs , group : @group ) )
30
39
end
31
40
41
+ # Register a gauge
32
42
def gauge ( *args , **kwargs )
33
43
register ( Gauge . new ( *args , **kwargs , group : @group ) )
34
44
end
35
45
46
+ # Register an histogram
36
47
def histogram ( *args , **kwargs )
37
48
register ( Histogram . new ( *args , **kwargs , group : @group ) )
38
49
end
@@ -49,5 +60,6 @@ def register(metric)
49
60
metric
50
61
end
51
62
end
63
+ # rubocop: enable Style/Documentation
52
64
end
53
65
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module Yabeda
4
- # Arbitrary value
4
+ # Arbitrary value, can be changed in both sides
5
5
class Gauge < Metric
6
6
def set ( tags , value )
7
7
values [ tags ] = value
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module Yabeda
4
+ # Base class for complex metric for measuring time values that allow to
5
+ # calculate averages, percentiles, and so on.
4
6
class Histogram < Metric
5
7
option :buckets
6
8
Original file line number Diff line number Diff line change 5
5
expect ( Yabeda ::VERSION ) . not_to be nil
6
6
end
7
7
8
- it ' exposes the public api' do
9
- expect ( Yabeda . metrics ) . to eq ( { } )
10
- expect ( Yabeda . adapters ) . to eq ( { } )
11
- expect ( Yabeda . collectors ) . to eq ( [ ] )
8
+ it " exposes the public api" do
9
+ expect ( described_class . metrics ) . to eq ( { } )
10
+ expect ( described_class . adapters ) . to eq ( { } )
11
+ expect ( described_class . collectors ) . to eq ( [ ] )
12
12
end
13
13
end
You can’t perform that action at this time.
0 commit comments