Class: Fluent::FinagleInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_finagle.rb

Instance Method Summary collapse

Constructor Details

#initializeFinagleInput

Returns a new instance of FinagleInput.



16
17
18
# File 'lib/fluent/plugin/in_finagle.rb', line 16

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



20
21
22
# File 'lib/fluent/plugin/in_finagle.rb', line 20

def configure(conf)
  super
end

#run_periodicObject

Main loop



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fluent/plugin/in_finagle.rb', line 44

def run_periodic
  until @finished
    sleep @run_interval

    begin
      response = @conn.get '/admin/metrics.json'
      json_response = JSON.parse(response.body)

      @metrics.split(",").each do |metric|
        router.emit(
          "#{@tag}.#{metric.gsub("/", "_")}",
          Engine.now.to_i,
          {"value" => json_response[metric]}
        )
      end
    rescue => e
      $log.warn "Failed to get Finagle metrics, but ignored: #{e.message}"
    end

  end
end

#shutdownObject



35
36
37
38
39
# File 'lib/fluent/plugin/in_finagle.rb', line 35

def shutdown
  @finished = true
  @thread.join
  super
end

#startObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/fluent/plugin/in_finagle.rb', line 24

def start
  super
  @finished = false
  @thread = Thread.new(&method(:run_periodic))
  @conn = Faraday.new(:url => "http://#{@finagle_host}:#{@finagle_port}") do |faraday|
    faraday.request  :url_encoded             # form-encode POST params
    faraday.response :logger                  # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end
end