Sha256: e79e9cafba97cf3a78e2533518f45caa20988eea91eec1b0a81eb3ae15eb17b4
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true require 'json' require 'rest-client' class DatadogMetrics def initialize(apikey, url) @apikey = apikey @url = url end def add_custom_data(ddtags, record) if ddtags.length() > 0 record_series = record['series'] data_array = [] record_series.each do |interim_data| interim_data['tags'] ||= [] interim_data['tags'].push(*ddtags) data_array << interim_data end record['series'] = data_array return record end return record end def send_metrics(ddtags, record) puts "Additional tags to be added to metrics are", ddtags metrics_data = add_custom_data(ddtags, record) puts "Sending received metrics data" response = RestClient::Request.new( method: :post, url: @url, payload: metrics_data.to_json, headers: {'DD-API-KEY': @apikey, content_type: :json } ).execute do |response, request, result| case response.code when 202 return response.body else puts 'Cannot send metrics to Datadog', response.body end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fluent-plugin-jfrog-send-metrics-0.1.4 | lib/fluent/plugin/datadog_metrics_sender.rb |