Class: Fluent::GangliaOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::GangliaOutput
- Defined in:
- lib/fluent/plugin/out_ganglia.rb
Constant Summary collapse
- HOSTNAME =
Socket.gethostname
- HOSTADDR =
IPSocket.getaddress(HOSTNAME)
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ GangliaOutput
constructor
A new instance of GangliaOutput.
- #send(tag, name, value, time) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ GangliaOutput
Returns a new instance of GangliaOutput.
7 8 9 10 11 |
# File 'lib/fluent/plugin/out_ganglia.rb', line 7 def initialize super require "gmetric" require "socket" end |
Instance Method Details
#configure(conf) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fluent/plugin/out_ganglia.rb', line 28 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fluent/plugin/out_ganglia.rb', line 86 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
53 54 55 56 57 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 |
# File 'lib/fluent/plugin/out_ganglia.rb', line 53 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}, '#{$!.}'" end unless status $log.warn "failed to send to ganglia: #{@host}:#{@port}, '#{name}': #{value}" end end |
#shutdown ⇒ Object
49 50 51 |
# File 'lib/fluent/plugin/out_ganglia.rb', line 49 def shutdown super end |
#start ⇒ Object
45 46 47 |
# File 'lib/fluent/plugin/out_ganglia.rb', line 45 def start super end |