Class: Daikon::Monitor
- Inherits:
-
Object
- Object
- Daikon::Monitor
- Defined in:
- lib/daikon/monitor.rb
Constant Summary collapse
- NEW_FORMAT =
/^\+?(\d+\.\d+)( "[A-Z]+".*)/i
- OLD_SINGLE_FORMAT =
/^(QUIT|RANDOMKEY|DBSIZE|EXPIRE|TTL|SAVE|BGSAVE|SHUTDOWN|BGREWRITEAOF|INFO|MONITOR|SLAVEOF)$/i
- OLD_MORE_FORMAT =
/^[A-Z]+ .*$/i
Instance Attribute Summary collapse
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(redis = nil, logger = nil) ⇒ Monitor
constructor
A new instance of Monitor.
- #parse(line) ⇒ Object
- #push(at, command) ⇒ Object
- #rotate ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(redis = nil, logger = nil) ⇒ Monitor
Returns a new instance of Monitor.
9 10 11 12 13 |
# File 'lib/daikon/monitor.rb', line 9 def initialize(redis = nil, logger = nil) @queue = [] @redis = redis @logger = logger end |
Instance Attribute Details
#queue ⇒ Object
Returns the value of attribute queue.
3 4 5 |
# File 'lib/daikon/monitor.rb', line 3 def queue @queue end |
Instance Method Details
#parse(line) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/daikon/monitor.rb', line 27 def parse(line) if line =~ NEW_FORMAT push(Float($1), $2) elsif line =~ OLD_SINGLE_FORMAT || line =~ OLD_MORE_FORMAT push(Time.now.to_f, line) end end |
#push(at, command) ⇒ Object
35 36 37 |
# File 'lib/daikon/monitor.rb', line 35 def push(at, command) @queue.push({:at => at, :command => command.strip}) end |
#rotate ⇒ Object
23 24 25 |
# File 'lib/daikon/monitor.rb', line 23 def rotate @queue.shift(@queue.size) end |
#start ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/daikon/monitor.rb', line 15 def start Thread.new do @redis.monitor do |line| parse(line) end end end |