Sha256: 3cfcdb2b017b227bcf41ed1f6e827680014755ea91bff540ac4b869e0739dbc2

Contents?: true

Size: 655 Bytes

Versions: 1

Compression:

Stored size: 655 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)
    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

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-jfrog-send-metrics-0.1.1 lib/fluent/plugin/newrelic_metrics_sender.rb