class Fluent::Plugin::DstatInput::DstatCSVWatcher

Constants

INTERVAL

Attributes

cur[RW]
previous[RW]

Public Class Methods

new(path, &receive_lines) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_dstat.rb, line 152
def initialize(path, &receive_lines)
  super path, INTERVAL
  @path = path
  @io = File.open(path, File::NONBLOCK | File::TRUNC)
  @receive_lines = receive_lines
  @partial = ""
end

Public Instance Methods

on_change(prev, cur) click to toggle source
# File lib/fluent/plugin/in_dstat.rb, line 160
def on_change(prev, cur)
  buffer = @io.read_nonblock(65536)
  lines = buffer.split("\n").map(&:chomp)
  return if lines.empty?
  lines[0] = @partial + lines.first unless @partial.empty?
  @partial = buffer.end_with?("\n") ? "" : lines.pop
  @receive_lines.call(lines)
rescue IO::WaitReadable
  # will be readable on next event
end