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/summary.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/observe_yabeda_summary.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, Summary, Tags, TestAdapter
Constant Summary collapse
- EMPTY_TAGS =
{}.freeze
- VERSION =
"0.13.1"
Class Method Summary collapse
-
.adapters ⇒ Hash<Symbol, 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.
-
.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<Symbol, Yabeda::BaseAdapter>
Returns All loaded adapters.
34 35 36 |
# File 'lib/yabeda.rb', line 34 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
52 53 54 55 56 57 58 59 60 |
# File 'lib/yabeda.rb', line 52 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.
39 40 41 |
# File 'lib/yabeda.rb', line 39 def collectors @collectors ||= Concurrent::Array.new end |
.config ⇒ Object
43 44 45 |
# File 'lib/yabeda.rb', line 43 def config @config ||= Config.new end |
.configurators ⇒ Array<Proc>
Returns All configuration blocks for postponed setup.
80 81 82 |
# File 'lib/yabeda.rb', line 80 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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/yabeda.rb', line 93 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. metrics.each_value do |metric| metric.adapters.each_value do |adapter| 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.
85 86 87 |
# File 'lib/yabeda.rb', line 85 def configured? !@configured_by.nil? end |
.debug! ⇒ Object
Enable and setup service metrics to monitor yabeda performance
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/yabeda.rb', line 116 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.
63 64 65 |
# File 'lib/yabeda.rb', line 63 def @default_tags ||= Concurrent::Hash.new end |
.groups ⇒ Hash<String, Yabeda::Group>
Returns All registered metrics.
27 28 29 30 31 |
# File 'lib/yabeda.rb', line 27 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.
22 23 24 |
# File 'lib/yabeda.rb', line 22 def metrics @metrics ||= Concurrent::Hash.new end |
.register_adapter(name, instance) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/yabeda.rb', line 69 def register_adapter(name, instance) adapters[name] = instance # NOTE: Pretty sure there is race condition metrics.each_value do |metric| next unless metric.adapters.key?(name) 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.
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/yabeda.rb', line 139 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 @config = Config.new instance_variable_set(:@configured_by, nil) instance_variable_set(:@debug_was_enabled_by, nil) end |