Class: Fluent::DstatInput::DstatCSVWatcher

Inherits:
Cool.io::StatWatcher
  • Object
show all
Defined in:
lib/fluent/plugin/in_dstat.rb

Constant Summary collapse

INTERVAL =
0.500

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, &receive_lines) ⇒ DstatCSVWatcher

Returns a new instance of DstatCSVWatcher.



150
151
152
153
154
155
156
# File 'lib/fluent/plugin/in_dstat.rb', line 150

def initialize(path, &receive_lines)
  super path, INTERVAL
  @path = path
  @io = File.open(path)
  @pos = 0
  @receive_lines = receive_lines
end

Instance Attribute Details

#curObject

Returns the value of attribute cur.



148
149
150
# File 'lib/fluent/plugin/in_dstat.rb', line 148

def cur
  @cur
end

#previousObject

Returns the value of attribute previous.



148
149
150
# File 'lib/fluent/plugin/in_dstat.rb', line 148

def previous
  @previous
end

Instance Method Details

#on_change(prev, cur) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/fluent/plugin/in_dstat.rb', line 158

def on_change(prev, cur)
  buffer = @io.read(cur.size - @pos)
  @pos = cur.size
  lines = []
  while line = buffer.slice!(/.*?\n/m)
    lines << line.chomp
  end
  @receive_lines.call(lines)
end