Class: Fluent::GangliaOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_ganglia.rb

Constant Summary collapse

HOSTNAME =
Socket.gethostname
HOSTADDR =
IPSocket.getaddress(HOSTNAME)

Instance Method Summary collapse

Constructor Details

#initializeGangliaOutput

Returns a new instance of GangliaOutput.



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

def initialize
  super
  require "gmetric"
  require "socket"
end

Instance Method Details

#configure(conf) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/out_ganglia.rb', line 33

def configure(conf)
  super

  if @name_keys.nil? and @name_key_pattern.nil?
    raise Fluent::ConfigError, "missing both of name_keys and name_key_pattern"
  end
  if not @name_keys.nil? and not @name_key_pattern.nil?
    raise Fluent::ConfigError, "cannot specify both of name_keys and name_key_pattern"
  end
  if @name_keys
    @name_keys = @name_keys.split(/ *, */)
  end
  if @name_key_pattern
    @name_key_pattern = Regexp.new(@name_key_pattern)
  end
end

#emit(tag, es, chain) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/out_ganglia.rb', line 91

def emit(tag, es, chain)
  if @name_keys
    es.each {|time,record|
      @name_keys.each {|name|
        if record[name]
          send(tag, name, record[name], time)
        end
      }
    }
  else # for name_key_pattern
    es.each {|time,record|
      record.keys.each {|key|
        if @name_key_pattern.match(key) and record[key]
          send(tag, key, record[key], time)
        end
      }
    }
  end
  chain.next
end

#send(tag, name, value, time) ⇒ 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
83
84
85
86
87
88
89
# File 'lib/fluent/plugin/out_ganglia.rb', line 58

def send(tag, name, value, time)
  if @add_key_prefix
    name = "#{@add_key_prefix} #{name}"
  end
  begin
    log.debug("ganglia: #{name}: #{value}, ts: #{time}")
    gmetric = Ganglia::GMetric.pack(
      :name     => name,
      :value    => value.to_s,
      :type     => @value_type,
      :units    => @units,
      :tmax     => @tmax,
      :dmax     => @dmax,
      :title    => @title,
      :group    => @group,
      :slope    => @slope,
      :spoof    => @spoof ? 1 : 0,
      :hostname => @spoof ? @spoof : HOSTNAME,
    )
    conn = UDPSocket.new
    conn.bind(HOSTADDR, 0) if @bind_hostname
    conn.send gmetric[0], 0, @host, @port
    conn.send gmetric[1], 0, @host, @port
    conn.close
    status = true
  rescue IOError, EOFError, SystemCallError
    log.warn "Ganglia::GMetric.send raises exception: #{$!.class}, '#{$!.message}'"
  end
  unless status
    log.warn "failed to send to ganglia: #{@host}:#{@port}, '#{name}': #{value}"
  end
end

#shutdownObject



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

def shutdown
  super
end

#startObject



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

def start
  super
end