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.



172
173
174
175
176
177
178
# File 'lib/fluent/plugin/in_dstat.rb', line 172

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.



170
171
172
# File 'lib/fluent/plugin/in_dstat.rb', line 170

def cur
  @cur
end

#previousObject

Returns the value of attribute previous.



170
171
172
# File 'lib/fluent/plugin/in_dstat.rb', line 170

def previous
  @previous
end

Instance Method Details

#on_change(prev, cur) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/fluent/plugin/in_dstat.rb', line 180

def on_change(prev, cur)
  return if cur.size < @pos

  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