29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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/datadog_metrics_sender.rb', line 29
def send_metrics(ddtags, record, http_proxy, verify_ssl, request_timeout, gzip_compression)
puts "#{Utility.get_time} Additional tags to be added to metrics are:", ddtags
metrics_data = add_custom_data(ddtags, record)
puts "#{Utility.get_time} Sending received metrics data"
if http_proxy
RestClient.proxy = URI.parse(http_proxy)
puts "#{Utility.get_time} Using http_proxy param to set proxy for request. Proxy url: #{RestClient.proxy}"
elsif ENV['HTTP_PROXY']
RestClient.proxy = ENV['HTTP_PROXY']
puts "#{Utility.get_time} Using 'HTTP_PROXY' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
elsif ENV['http_proxy']
RestClient.proxy = ENV['http_proxy']
puts "#{Utility.get_time} Using 'http_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
elsif ENV['https_proxy']
RestClient.proxy = ENV['https_proxy']
puts "#{Utility.get_time} Using 'https_proxy' environment variable to set proxy for request. Proxy url: #{RestClient.proxy}"
end
= {
'DD-API-KEY': @apikey,
content_type: :json
}
payload = metrics_data.to_json
if gzip_compression
payload = Utility.compress_payload(metrics_data)
[:'Content-Encoding'] = 'gzip'
end
response = RestClient::Request.new(
method: :post,
url: @url,
payload: payload,
headers: ,
verify_ssl: verify_ssl,
timeout: request_timeout
).execute do |response, request, result|
case response.code
when 202
puts "#{Utility.get_time} Metrics were successfully sent to DataDog"
return response.body
else
puts "#{Utility.get_time} Cannot send metrics to DataDog url: %s. Received response code: %d, Response body: %s" % [@url, response.code, response.body]
end
end
end
|