Module: Yabeda
- Extended by:
- Forwardable
- Includes:
- DSL
- Defined in:
- lib/yabeda.rb,
lib/yabeda/dsl.rb,
lib/yabeda/tags.rb,
lib/yabeda/gauge.rb,
lib/yabeda/group.rb,
lib/yabeda/rspec.rb,
lib/yabeda/config.rb,
lib/yabeda/errors.rb,
lib/yabeda/metric.rb,
lib/yabeda/counter.rb,
lib/yabeda/railtie.rb,
lib/yabeda/version.rb,
lib/yabeda/histogram.rb,
lib/yabeda/base_adapter.rb,
lib/yabeda/global_group.rb,
lib/yabeda/test_adapter.rb,
lib/yabeda/dsl/class_methods.rb,
lib/yabeda/dsl/metric_builder.rb,
lib/yabeda/dsl/option_builder.rb,
lib/yabeda/rspec/base_matcher.rb,
lib/yabeda/rspec/update_yabeda_gauge.rb,
lib/yabeda/rspec/increment_yabeda_counter.rb,
lib/yabeda/rspec/measure_yabeda_histogram.rb
Overview
Extendable framework for collecting and exporting metrics from Ruby apps
Defined Under Namespace
Modules: DSL, RSpec, Rails Classes: AlreadyConfiguredError, BaseAdapter, Config, ConfigurationError, Counter, Gauge, GlobalGroup, Group, Histogram, Metric, Tags, TestAdapter
Constant Summary collapse
- VERSION =
"0.11.0"
Class Method Summary collapse
-
.adapters ⇒ Hash<String, Yabeda::BaseAdapter>
All loaded adapters.
-
.collect! ⇒ Object
Execute all collector blocks for periodical retrieval of metrics.
-
.collectors ⇒ Array<Proc>
All collectors for periodical retrieving of metrics.
- .config ⇒ Object
-
.configurators ⇒ Array<Proc>
All configuration blocks for postponed setup.
-
.configure! ⇒ void
Perform configuration: registration of metrics and collector blocks rubocop: disable Metrics/MethodLength, Metrics/AbcSize.
-
.configured? ⇒ Boolean
(also: already_configured?)
Whether
Yabeda.configure!
has been already called. -
.debug! ⇒ Object
Enable and setup service metrics to monitor yabeda performance.
-
.default_tags ⇒ Hash<Symbol, Symbol>
All added global default tags.
-
.groups ⇒ Hash<String, Yabeda::Group>
All registered metrics.
-
.metrics ⇒ Hash<String, Yabeda::Metric>
All registered metrics.
- .register_adapter(name, instance) ⇒ Object
-
.reset! ⇒ Object
private
Forget all the configuration.
Methods included from DSL
Class Method Details
.adapters ⇒ Hash<String, Yabeda::BaseAdapter>
Returns All loaded adapters.
33 34 35 |
# File 'lib/yabeda.rb', line 33 def adapters @adapters ||= Concurrent::Hash.new end |
.collect! ⇒ Object
Execute all collector blocks for periodical retrieval of metrics
This method is intended to be used by monitoring systems adapters
51 52 53 54 55 56 57 58 59 |
# File 'lib/yabeda.rb', line 51 def collect! collectors.each do |collector| if config.debug? yabeda.collect_duration.measure({ location: collector.source_location.join(":") }, &collector) else collector.call end end end |
.collectors ⇒ Array<Proc>
Returns All collectors for periodical retrieving of metrics.
38 39 40 |
# File 'lib/yabeda.rb', line 38 def collectors @collectors ||= Concurrent::Array.new end |
.config ⇒ Object
42 43 44 |
# File 'lib/yabeda.rb', line 42 def config @config ||= Config.new end |
.configurators ⇒ Array<Proc>
Returns All configuration blocks for postponed setup.
77 78 79 |
# File 'lib/yabeda.rb', line 77 def configurators @configurators ||= Concurrent::Array.new end |
.configure! ⇒ void
This method returns an undefined value.
Perform configuration: registration of metrics and collector blocks rubocop: disable Metrics/MethodLength, Metrics/AbcSize
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/yabeda.rb', line 90 def configure! raise(AlreadyConfiguredError, @configured_by) if already_configured? debug! if config.debug? configurators.each do |(group, block)| group group class_eval(&block) group nil end # Register metrics in adapters after evaluating all configuration blocks # to ensure that all global settings (like default tags) will be applied. adapters.each_value do |adapter| metrics.each_value do |metric| adapter.register!(metric) end end @configured_by = caller_locations(1, 1)[0].to_s end |
.configured? ⇒ Boolean Also known as: already_configured?
Returns Whether Yabeda.configure!
has been already called.
82 83 84 |
# File 'lib/yabeda.rb', line 82 def configured? !@configured_by.nil? end |
.debug! ⇒ Object
Enable and setup service metrics to monitor yabeda performance
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/yabeda.rb', line 113 def debug! return false if @debug_was_enabled_by # Prevent multiple calls config.debug ||= true # Enable debug mode in config if it wasn't enabled from other sources @debug_was_enabled_by = caller_locations(1, 1)[0].to_s configure do group :yabeda histogram :collect_duration, tags: %i[location], unit: :seconds, buckets: [0.0001, 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60].freeze, comment: "A histogram for the time required to evaluate collect blocks" end adapters.each_value(&:debug!) true end |
.default_tags ⇒ Hash<Symbol, Symbol>
Returns All added global default tags.
62 63 64 |
# File 'lib/yabeda.rb', line 62 def @default_tags ||= Concurrent::Hash.new end |
.groups ⇒ Hash<String, Yabeda::Group>
Returns All registered metrics.
26 27 28 29 30 |
# File 'lib/yabeda.rb', line 26 def groups @groups ||= Concurrent::Hash.new.tap do |hash| hash[nil] = Yabeda::GlobalGroup.new(nil) end end |
.metrics ⇒ Hash<String, Yabeda::Metric>
Returns All registered metrics.
21 22 23 |
# File 'lib/yabeda.rb', line 21 def metrics @metrics ||= Concurrent::Hash.new end |
.register_adapter(name, instance) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/yabeda.rb', line 68 def register_adapter(name, instance) adapters[name] = instance # NOTE: Pretty sure there is race condition metrics.each do |_, metric| instance.register!(metric) end end |
.reset! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Forget all the configuration. For testing purposes as it doesn’t rollback changes in adapters. rubocop: disable Metrics/AbcSize
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/yabeda.rb', line 138 def reset! .clear adapters.clear groups.each_key { |group| singleton_class.send(:remove_method, group) if group && respond_to?(group) } @groups = nil metrics.each_key { |metric| singleton_class.send(:remove_method, metric) if respond_to?(metric) } @metrics = nil collectors.clear configurators.clear instance_variable_set(:@configured_by, nil) instance_variable_set(:@debug_was_enabled_by, nil) end |