Class: Fluent::Plugin::JfrogSendMetricsOutput

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

‘configure` is called before `start`. ’conf’ is a ‘Hash` that includes the configuration parameters. If the configuration is invalid, raise `Fluent::ConfigError`.

Raises:

  • (Fluent::ConfigError)


41
42
43
44
45
46
47
# File 'lib/fluent/plugin/out_jfrog_send_metrics.rb', line 41

def configure(conf)
  super
  
  raise Fluent::ConfigError, 'Must define the target_platform to be one of the following (DATADOG, NEWRELIC).' if @target_platform == '' || !(['DATADOG', 'NEWRELIC'].include?(@target_platform))

  raise Fluent::ConfigError, 'Must define the apikey to use for authentication.' if @apikey == ''
end

#process(tag, es) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/out_jfrog_send_metrics.rb', line 49

def process(tag, es)
  logger = log
  es.each do |time, record|
    begin
      logger.info("Sending metrics to target platform: #{@target_platform} started")
      if @target_platform == 'NEWRELIC'
        vendor = NewRelicMetrics.new(@apikey, @url)
        vendor.send_metrics(record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression, logger)
      elsif @target_platform == 'DATADOG'
        vendor = DatadogMetrics.new(@apikey, @url)
        vendor.send_metrics(@ddtags, record, @http_proxy, @verify_ssl, @request_timeout, @gzip_compression, logger)
      end
      logger.info("Sending metrics to target platform: #{@target_platform} finished")
    rescue RestClient::Exceptions::OpenTimeout
      logger.info("#{Utility.get_time} The request timed out while trying to open a connection. The configured request timeout is: #{@request_timeout}")
    rescue RestClient::Exceptions::ReadTimeout
      logger.info("#{Utility.get_time} The request timed out while waiting for a response. The configured request timeout is: #{@request_timeout}")
    rescue  RestClient::Exceptions::RequestTimeout
      logger.info("#{Utility.get_time} The request timed out. The configured request timeout is: #{@request_timeout}")
    rescue RestClient::ExceptionWithResponse => e
      logger.info("#{Utility.get_time} HTTP request failed: #{e.response}")
    rescue Net::HTTPClientException => e
      logger.info("#{Utility.get_time} An HTTP client error occurred when sending metrics to #{@target_platform}: #{e.message}")
    rescue StandardError => e
      logger.info("#{Utility.get_time} An error occurred when sending metrics to #{@target_platform}: #{e.message}")
    end
  end
end