class Fluent::StathatOutput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_stathat.rb, line 10
def initialize
  require 'net/https'
  require 'uri'
  require 'json'

  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_stathat.rb, line 18
def configure(conf)
  super

  if (@count.nil? && @value.nil?) || (@count && @value)
    raise ConfigError, "stathat_out requires either 'count' or 'value', but not both"
  end

  @uri = URI.parse("https://api.stathat.com/ez")

  @https = Net::HTTP.new(@uri.host, @uri.port)
  @https.use_ssl = true
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_stathat.rb, line 39
def format(tag, time, record)
  [tag, time, record].to_msgpack
end
post(data) click to toggle source
# File lib/fluent/plugin/out_stathat.rb, line 57
def post(data)
  req = Net::HTTP::Post.new(@uri.request_uri)
  req.content_type = 'application/json'
  req.body = data.to_json

  @https.request(req)
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_stathat.rb, line 35
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_stathat.rb, line 31
def start
  super
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_stathat.rb, line 43
def write(chunk)
  data = []
  chunk.msgpack_each do |tag, time, record|
    stat = (@stat || tag)

    if record.has_key? @count
      data << {stat: stat, t: time, count: record[@count]}
    elsif record.has_key? @value
      data << {stat: stat, t: time, value: record[@value]}
    end
  end
  post(ezkey: @ezkey, data: data) if data.length > 0
end