Class: Fluent::LeftronicOutput

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

Instance Method Summary collapse

Constructor Details

#initializeLeftronicOutput

Returns a new instance of LeftronicOutput.



12
13
14
15
16
17
18
# File 'lib/fluent/plugin/out_leftronic.rb', line 12

def initialize
  Encoding.default_internal = "UTF-8"
  require 'uri'
  require 'json'
  require 'leftronic'
  super
end

Instance Method Details

#configure(conf) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent/plugin/out_leftronic.rb', line 20

def configure(conf)
  super
  if @access_key.nil? || @access_key.empty?
    raise ConfigError, "leftronic configure requires 'access_key'"
  end

  if @stream_name.nil? || @stream_name.empty?
    raise ConfigError, "leftronic configure requires 'stream_name'"
  end

  if @graph_type == 'number' or @graph_type == 'line'
    if @value.nil? || @value.size == 0
      raise ConfigError, "leftronic configure requires 'value'"
    end
  end
  
  unless @display_keys.nil?
    @default_key = false
    @leftronic_display_hash = eval(@display_keys)
    $log.info @leftronic_display_hash
  else 
    @default_key = true
  end
  @leftronic = Leftronic.new @access_key
end

#format(tag, time, record) ⇒ Object



54
55
56
# File 'lib/fluent/plugin/out_leftronic.rb', line 54

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#shutdownObject



50
51
52
# File 'lib/fluent/plugin/out_leftronic.rb', line 50

def shutdown
  super
end

#startObject



46
47
48
# File 'lib/fluent/plugin/out_leftronic.rb', line 46

def start
  super
end

#write(chunk) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/out_leftronic.rb', line 58

def write(chunk)
  chunk.msgpack_each do |tag, time, record|
    next if record.nil? || record.empty?
    if @graph_type == 'number' or @graph_type == 'line'
      next unless record.has_key? @value
      @leftronic.number(@stream_name ,record[@value].to_i)
    elsif @graph_type == 'leaderboard' or @graph_type == 'bar' or @graph_type == 'pie'
      result = Hash.new
      record.each {|key,value|
        unless name_key_pattern.nil?
          next if key !~ /#{@name_key_pattern}/
        end

        unless @default_key
          display_key = @leftronic_display_hash.has_key?(key) ? @leftronic_display_hash[key] : key
        else
          display_key = key
        end
        result[display_key] = value.to_i
      }
      $log.info result
      @leftronic.leaderboard(@stream_name,[result])
    end
  end
end