Class: Ganymed::Collector::Plugin
- Inherits:
-
Object
- Object
- Ganymed::Collector::Plugin
- Defined in:
- lib/ganymed/collector.rb
Overview
Base class and DSL for Ganymed::Collector plugins.
Instance Attribute Summary collapse
-
#config ⇒ Section
The configuration object.
-
#interval ⇒ Fixnum, Float
Plugin interval.
-
#splay ⇒ Fixnum
readonly
Plugin splay.
Instance Method Summary collapse
-
#collect(interval = nil, &block) ⇒ void
Set the block used to collect metrics with this plugin.
-
#from_file(filename) ⇒ Plugin
Loads a given ruby file, and runs instance_eval against it in the context of the current object.
-
#initialize(config) ⇒ Plugin
constructor
Create a new plugin instance.
-
#run ⇒ void
Start the EventMachine timer to collect metrics at the specified interval.
Constructor Details
#initialize(config) ⇒ Plugin
Create a new plugin instance.
101 102 103 |
# File 'lib/ganymed/collector.rb', line 101 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Section
The configuration object.
88 89 90 |
# File 'lib/ganymed/collector.rb', line 88 def config @config end |
#interval ⇒ Fixnum, Float
Plugin interval
92 93 94 |
# File 'lib/ganymed/collector.rb', line 92 def interval @interval end |
#splay ⇒ Fixnum (readonly)
Plugin splay
96 97 98 |
# File 'lib/ganymed/collector.rb', line 96 def splay @splay end |
Instance Method Details
#collect(interval = nil, &block) ⇒ void
This method returns an undefined value.
Set the block used to collect metrics with this plugin.
109 110 111 112 113 |
# File 'lib/ganymed/collector.rb', line 109 def collect(interval=nil, &block) @interval = interval || config.interval.tap{} || 1 @splay = 0 @collector = Proc.new(&block) end |
#from_file(filename) ⇒ Plugin
Loads a given ruby file, and runs instance_eval against it in the context of the current object.
142 143 144 145 146 147 148 149 |
# File 'lib/ganymed/collector.rb', line 142 def from_file(filename) if File.exists?(filename) && File.readable?(filename) self.instance_eval(IO.read(filename), filename, 1) else raise IOError, "Cannot open or read #{filename}!" end self end |
#run ⇒ void
This method returns an undefined value.
Start the EventMachine timer to collect metrics at the specified interval.
118 119 120 121 122 123 124 125 |
# File 'lib/ganymed/collector.rb', line 118 def run # we do not use a periodic timer here so that we can simply increase # the splay to slow down the collector in case it throws lots of # exceptions EM.add_timer(interval * (2 ** splay)) do EM.defer { collect!; run } end end |