Class: Fluent::DeisGraphiteOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_deis-graphite.rb

Instance Method Summary collapse

Constructor Details

#initializeDeisGraphiteOutput

Returns a new instance of DeisGraphiteOutput.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fluent/plugin/out_deis-graphite.rb', line 17

def initialize

  #Get the cluster name from Google metadata service
  begin
    response = RestClient::Request.execute(method: :get, url: 'http://metadata.google.internal/computeMetadata/v1/instance/attributes/cluster-name',
                        timeout: 10, headers: { "Metadata-Flavor" => "Google"})
    if response.code == 200
      @cluster_name=response.body
    end
  rescue
    p "Couldn't determine cluster name."
  end

  super
end

Instance Method Details

#configure(conf) ⇒ Object



44
45
46
# File 'lib/fluent/plugin/out_deis-graphite.rb', line 44

def configure(conf)
  super
end

#emit(tag, es, chain) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/out_deis-graphite.rb', line 48

def emit(tag, es, chain)
  es.each do |time,record|
    if record.key? "kubernetes"
      if record["kubernetes"]["container_name"] == "deis-router"
        begin
          split_message = record["log"].split(" - ")
          app = split_message[1].strip
          status_code = split_message[4].strip
          #bytes_sent = split_message[6].strip.to_f
          #response_time = split_message[12].strip.to_f
          #request_time = split_message[13].strip.to_f

          Metriks.meter("response_rates.#{@cluster_name}.#{record["kubernetes"]["pod_name"]}.#{app}.#{status_code}").mark
        rescue Exception => e
          puts "Failed to parse: \'#{record}\'. Got exception #{e}"
        end
      end
     end
  end
  chain.next
end

#shutdownObject



40
41
42
# File 'lib/fluent/plugin/out_deis-graphite.rb', line 40

def shutdown
  super
end

#startObject



33
34
35
36
37
38
# File 'lib/fluent/plugin/out_deis-graphite.rb', line 33

def start
  super
  puts "Starting reporter: #{@graphite_url}:#{@graphite_port}/#{@graphite_interval}"
  @reporter = Metriks::Reporter::Graphite.new @graphite_url, @graphite_port,:interval => @graphite_interval
  @reporter.start
end