Class: Fluent::GoogleSheetsOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_google_sheets.rb

Instance Method Summary collapse

Instance Method Details

#format(tag, time, record) ⇒ Object



14
15
16
# File 'lib/fluent/plugin/out_google_sheets.rb', line 14

def format(tag, time, record)
  [tag, Time.at(time).strftime('%F %T'), record].to_json + "\n"
end

#write(chunk) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/fluent/plugin/out_google_sheets.rb', line 18

def write(chunk)
  data = chunk.read.each_line.map {|line| JSON.parse(line) }.group_by {|tag, *| tag }

  data.each do |tag, xs|
    ws = worksheet(tag)
    ws.insert_rows(ws.num_rows + 1, xs.map {|_, time, record| [time] + record.values })
    ws.save
  end
end