Commits

Kaspar Schiess committed e78dc33

Statistics display on SIGINFO (Ctrl+T)

  • Participants
  • Parent commits 6b026b1

Comments (0)

Files changed (4)

File lib/event_shipper/proxy.rb

         host: redis_config['host'], 
         port: redis_config['port'])
 
+      trap('SIGINFO') { puts transport.stats }
+
       transport.dispatch { |queue, message| 
         # puts message }
         redis.lpush queue, message }

File lib/event_shipper/shipper.rb

         tailer
       end
 
+      trap('SIGINFO') { puts transport.stats }
+
       # Block until everyone exits.
       tailers.each do |tailer|
         tailer.join

File lib/event_shipper/udp.rb

 
 module EventShipper
   class UDP
+    attr_reader :stats
+
     def initialize host, port
       @host, @port = host, port
       @socket = UDPSocket.new

File lib/stats.rb

+
+module EventShipper
+  class Stats
+    def initialize
+      reset
+    end
+
+    def count_message
+      @messages += 1
+    end
+    def count_failure
+      @failures += 1
+    end
+
+    def reset
+      @period_start = Time.now
+      @messages = @failures = 0
+    end
+
+    def to_s
+      seconds = Time.now - @period_start 
+
+      mps = @messages / Float(seconds)
+      fps = @failures / Float(seconds)
+
+      "#{mps} messages/s, #{fps} failures/s"
+    end
+  end
+end