Class: Bipbip::Config
- Inherits:
-
Object
- Object
- Bipbip::Config
- Defined in:
- lib/bipbip/config.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#storages ⇒ Object
readonly
Returns the value of attribute storages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(plugins = nil, storages = nil, logger = nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(plugins = nil, storages = nil, logger = nil) ⇒ Config
Returns a new instance of Config.
53 54 55 56 57 |
# File 'lib/bipbip/config.rb', line 53 def initialize(plugins = nil, storages = nil, logger = nil) @plugins = plugins || [] @storages = storages || [] @logger = logger || Logger.new(STDOUT) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/bipbip/config.rb', line 5 def logger @logger end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/bipbip/config.rb', line 3 def plugins @plugins end |
#storages ⇒ Object (readonly)
Returns the value of attribute storages.
4 5 6 |
# File 'lib/bipbip/config.rb', line 4 def storages @storages end |
Class Method Details
.factory_from_file(file_path) ⇒ Bipbip::Config
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bipbip/config.rb', line 9 def self.factory_from_file(file_path) config = YAML.load(File.open(file_path)) config = { 'logfile' => STDOUT, 'loglevel' => 'INFO', 'frequency' => 60, 'include' => nil, 'services' => [], 'tags' => [] }.merge(config) logger = Logger.new(config['logfile']) logger.level = Logger.const_get(config['loglevel']) plugins_config = config['services'].to_a if config['include'] include_path = File.(config['include'].to_s, File.dirname(file_path)) files = Dir[include_path + '/**/*.yaml', include_path + '/**/*.yml'] plugins_config += files.map { |file| YAML.load(File.open(file)) } end plugins = plugins_config.map do |service| plugin_name = service['plugin'] metric_group = service['metric_group'] frequency = service['frequency'].nil? ? config['frequency'] : service['frequency'] = config['tags'].to_a + service['tags'].to_a plugin_config = service.reject { |key, _value| %w(plugin frequency tags metric_group).include?(key) } Bipbip::Plugin.factory(plugin_name, plugin_config, frequency, , metric_group) end storages_config = config['storages'].to_a storages = storages_config.map do |storage| storage_name = storage['name'].to_s storage_config = storage.reject { |key, _value| ['name'].include?(key) } Bipbip::Storage.factory(storage_name, storage_config) end Bipbip::Config.new(plugins, storages, logger) end |