Sha256: bba981ef3f39aeee3a16894f0f36ea1d2ae7b26b27d2385f3ba7b9e033ffebd4

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

module Monkeyshines
  module Monitor

    #
    # Emits a log line but only every +iter_interval+ calls or +time_interval+
    # lapse.
    #
    # Since the contents of the block aren't called until the criteria are met,
    # you can put relatively expensive operations in the log without killing
    # your iteration time.
    #
    class PeriodicLogger < PeriodicMonitor
      #
      # Call with a block that returns a string or array to log.
      # If you return
      #
      # Ex: log if it has been at least 5 minutes since last announcement:
      #
      #   periodic_logger = Monkeyshines::Monitor::PeriodicLogger.new(:time => 300)
      #   loop do
      #     # ... stuff ...
      #     periodic_logger.periodically{ [morbenfactor, crunkosity, exuberance] }
      #   end
      #
      def periodically &block
        super do
          now = Time.now.utc.to_f
          result = [ "%10d"%iter, "%7.1f"%since, "%7.1f"%inst_rate(now), (block ? block.call : nil) ].flatten.compact
          Log.info result.join("\t")
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
wukong-1.5.4 lib/wukong/monitor/periodic_logger.rb
wukong-1.5.3 lib/wukong/monitor/periodic_logger.rb
wukong-1.5.2 lib/wukong/monitor/periodic_logger.rb
wukong-1.5.1 lib/wukong/monitor/periodic_logger.rb
wukong-1.5.0 lib/wukong/monitor/periodic_logger.rb
wukong-1.4.12 lib/wukong/monitor/periodic_logger.rb
wukong-1.4.11 lib/wukong/monitor/periodic_logger.rb
monkeyshines-0.2.3 lib/monkeyshines/monitor/periodic_logger.rb
monkeyshines-0.2.2 lib/monkeyshines/monitor/periodic_logger.rb