Class: Bipbip::Plugin
- Inherits:
-
Object
- Object
- Bipbip::Plugin
- Includes:
- InterruptibleSleep
- Defined in:
- lib/bipbip/plugin.rb
Direct Known Subclasses
Apache2, Command, Elasticsearch, FastcgiPhpApc, FastcgiPhpFpm, FastcgiPhpOpcache, Gearman, LogParser, Memcached, Mongodb, Monit, Mysql, Network, Nginx, PhpApc, Postfix, Puppet, Redis, Resque, SocketRedis
Defined Under Namespace
Classes: Apache2, Command, Elasticsearch, FastcgiPhpApc, FastcgiPhpFpm, FastcgiPhpOpcache, Gearman, LogParser, MeasurementTimeout, Memcached, Mongodb, Monit, Mysql, Network, Nginx, PhpApc, Postfix, Puppet, Redis, Resque, SocketRedis
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#metric_group ⇒ Object
Returns the value of attribute metric_group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tags ⇒ Object
Returns the value of attribute tags.
Class Method Summary collapse
- .factory(name, config, frequency, tags, metric_group = nil) ⇒ Object
- .factory_from_plugin(plugin) ⇒ Bipbip::Plugin
Instance Method Summary collapse
-
#initialize(name, config, frequency, tags = nil, metric_group = nil) ⇒ Plugin
constructor
A new instance of Plugin.
- #metrics_names ⇒ Object
- #metrics_schema ⇒ Object
- #monitor ⇒ Object
- #run(storages) ⇒ Object
- #source_identifier ⇒ Object
Methods included from InterruptibleSleep
#interrupt_sleep, #interruptible_sleep
Constructor Details
#initialize(name, config, frequency, tags = nil, metric_group = nil) ⇒ Plugin
Returns a new instance of Plugin.
25 26 27 28 29 30 31 |
# File 'lib/bipbip/plugin.rb', line 25 def initialize(name, config, frequency, = nil, metric_group = nil) @name = name.to_s @config = config.to_hash @frequency = frequency.to_f @tags = .to_a @metric_group = (metric_group || name).to_s end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/bipbip/plugin.rb', line 9 def config @config end |
#frequency ⇒ Object
Returns the value of attribute frequency.
10 11 12 |
# File 'lib/bipbip/plugin.rb', line 10 def frequency @frequency end |
#metric_group ⇒ Object
Returns the value of attribute metric_group.
12 13 14 |
# File 'lib/bipbip/plugin.rb', line 12 def metric_group @metric_group end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/bipbip/plugin.rb', line 8 def name @name end |
#tags ⇒ Object
Returns the value of attribute tags.
11 12 13 |
# File 'lib/bipbip/plugin.rb', line 11 def @tags end |
Class Method Details
.factory(name, config, frequency, tags, metric_group = nil) ⇒ Object
14 15 16 17 |
# File 'lib/bipbip/plugin.rb', line 14 def self.factory(name, config, frequency, , metric_group = nil) require "bipbip/plugin/#{Bipbip::Helper.name_to_filename(name)}" Plugin.const_get(Bipbip::Helper.name_to_classname(name)).new(name, config, frequency, , metric_group) end |
.factory_from_plugin(plugin) ⇒ Bipbip::Plugin
21 22 23 |
# File 'lib/bipbip/plugin.rb', line 21 def self.factory_from_plugin(plugin) plugin.class.new(plugin.name, plugin.config, plugin.frequency, plugin., plugin.metric_group) end |
Instance Method Details
#metrics_names ⇒ Object
65 66 67 |
# File 'lib/bipbip/plugin.rb', line 65 def metrics_names metrics_schema.map { |metric| metric[:name] } end |
#metrics_schema ⇒ Object
69 70 71 |
# File 'lib/bipbip/plugin.rb', line 69 def metrics_schema fail 'Missing method metrics_schema' end |
#monitor ⇒ Object
73 74 75 |
# File 'lib/bipbip/plugin.rb', line 73 def monitor fail 'Missing method monitor' end |
#run(storages) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bipbip/plugin.rb', line 34 def run(storages) timeout = frequency * 2 loop do time = Time.now Timeout.timeout(timeout, MeasurementTimeout) do run_measurement(time, storages) end interruptible_sleep (frequency - (Time.now - time)) end rescue MeasurementTimeout => e log(Logger::ERROR, "Measurement timeout of #{timeout} seconds reached.") retry rescue StandardError => e log_exception(Logger::ERROR, e) interruptible_sleep frequency retry rescue Exception => e log_exception(Logger::FATAL, e) raise e end |