Class: WarCorrespondent::Reporter
- Inherits:
-
Object
- Object
- WarCorrespondent::Reporter
- Defined in:
- lib/warcorrespondent/reporter.rb
Direct Known Subclasses
WarCorrespondent::Reporters::CPU, WarCorrespondent::Reporters::LoadAvg, WarCorrespondent::Reporters::Memory, WarCorrespondent::Reporters::Net, WarCorrespondent::Reporters::UsersReporter
Instance Attribute Summary collapse
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#options ⇒ Object
Returns the value of attribute options.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(args, &block) ⇒ Reporter
constructor
A new instance of Reporter.
- #run ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(args, &block) ⇒ Reporter
Returns a new instance of Reporter.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/warcorrespondent/reporter.rb', line 7 def initialize(args, &block) @timeout = 300 [:timeout, :identifier, :options].each do |key| if args[key] && self.respond_to?("#{key}=") self.send("#{key}=",args[key]) end end @block = block if block WarCorrespondent::register_reporter(self) end |
Instance Attribute Details
#identifier ⇒ Object
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/warcorrespondent/reporter.rb', line 4 def identifier @identifier end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/warcorrespondent/reporter.rb', line 5 def @options end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/warcorrespondent/reporter.rb', line 3 def timeout @timeout end |
Instance Method Details
#run ⇒ Object
34 35 36 37 38 39 |
# File 'lib/warcorrespondent/reporter.rb', line 34 def run loop do update sleep timeout end end |
#update ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/warcorrespondent/reporter.rb', line 18 def update Logging::logger.debug{"Updating #{@identifier}"} data = instance_eval(&@block) return if data == nil data = [data] if data.class == Hash data.map! do |e| e = {:timestamp => Time.now.to_i}.merge(e) e[:identifier] = identifier + (e[:identifier] ? (':' + e[:identifier]) : '') e[:identifier].gsub!(/:+/, ':') e end WarCorrespondent::update(data) rescue Exception => e Logging::logger.warn{e} end |