Class: WarCorrespondent::Reporter
- Inherits:
-
Object
- Object
- WarCorrespondent::Reporter
- Defined in:
- lib/warcorrespondent/reporter.rb
Direct Known Subclasses
WarCorrespondent::Reporters::Linux::CPU, WarCorrespondent::Reporters::Linux::LoadAvg, WarCorrespondent::Reporters::Linux::Memory, WarCorrespondent::Reporters::Linux::Net, WarCorrespondent::Reporters::UsersReporter
Instance Attribute Summary collapse
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#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.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/warcorrespondent/reporter.rb', line 5 def initialize(args, &block) @timeout = 300 [:timeout, :identifier].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 |
#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
28 29 30 31 32 33 |
# File 'lib/warcorrespondent/reporter.rb', line 28 def run loop do update sleep timeout end end |
#update ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/warcorrespondent/reporter.rb', line 16 def update data = @block.call 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) end |