Class: Daikon::Monitor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#queueObject

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

#rotateObject



23
24
25
# File 'lib/daikon/monitor.rb', line 23

def rotate
  @queue.shift(@queue.size)
end

#startObject



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