Sha256: 5bf333ad8837f70edbddfb715a62c9e50957ea18ec9fc7a7f495fa56a84bf495

Contents?: true

Size: 696 Bytes

Versions: 3

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true
require 'json'
require 'rest-client'

class NewRelicMetrics
  def initialize(apikey, url)
    @apikey = apikey
    @url = url
  end

  def send_metrics(metrics_data)
    puts "Sending received metrics data"
    metrics_payload = []
    metrics_payload.push(JSON.parse(metrics_data.to_json))
    response = RestClient::Request.new(
        method: :post,
        url: @url,
        payload:  metrics_payload.to_json,
        headers: {params: {'Api-Key' => @apikey}}
    ).execute do |response, request, result|
      case response.code
      when 202
        return response.body
      else
        puts 'Cannot send metrics to NewRelic'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fluent-plugin-jfrog-send-metrics-0.1.4 lib/fluent/plugin/newrelic_metrics_sender.rb
fluent-plugin-jfrog-send-metrics-0.1.3 lib/fluent/plugin/newrelic_metrics_sender.rb
fluent-plugin-jfrog-send-metrics-0.1.2 lib/fluent/plugin/newrelic_metrics_sender.rb