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/null_adapter.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, NullAdapter, Summary, Tags, TestAdapter
Constant Summary collapse
- EMPTY_TAGS =
{}.freeze
- VERSION =
"0.16.0"
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.
35 36 37 38 39 |
# File 'lib/yabeda.rb', line 35 def adapters @adapters ||= Concurrent::Hash.new.tap do |hash| hash[:null_adapter] = Yabeda::NullAdapter.new end end |
.collect! ⇒ Object
Execute all collector blocks for periodical retrieval of metrics
This method is intended to be used by monitoring systems adapters
55 56 57 58 59 60 61 62 63 |
# File 'lib/yabeda.rb', line 55 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.
42 43 44 |
# File 'lib/yabeda.rb', line 42 def collectors @collectors ||= Concurrent::Array.new end |
.config ⇒ Object
46 47 48 |
# File 'lib/yabeda.rb', line 46 def config @config ||= Config.new end |
.configurators ⇒ Array<Proc>
Returns All configuration blocks for postponed setup.
83 84 85 |
# File 'lib/yabeda.rb', line 83 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
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/yabeda.rb', line 96 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.
88 89 90 |
# File 'lib/yabeda.rb', line 88 def configured? !@configured_by.nil? end |
.debug! ⇒ Object
Enable and setup service metrics to monitor yabeda performance
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/yabeda.rb', line 119 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.
66 67 68 |
# File 'lib/yabeda.rb', line 66 def @default_tags ||= Concurrent::Hash.new end |
.groups ⇒ Hash<String, Yabeda::Group>
Returns All registered metrics.
28 29 30 31 32 |
# File 'lib/yabeda.rb', line 28 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.
23 24 25 |
# File 'lib/yabeda.rb', line 23 def metrics @metrics ||= Concurrent::Hash.new end |
.register_adapter(name, instance) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/yabeda.rb', line 72 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.
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/yabeda.rb', line 142 def reset! .clear @adapters = nil 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 |