Class: NewRelic::Agent::Utilization::AWS
- Defined in:
- lib/new_relic/agent/utilization/aws.rb
Constant Summary collapse
- IMDS_BASE_URL =
'http://169.254.169.254/latest'.freeze
- IMDS_KEYS =
%w[instanceId instanceType availabilityZone].freeze
- IMDS_TOKEN_TTL_SECS =
'60'.freeze
- TOKEN_OPEN_TIMEOUT_SECS =
1.freeze
- TOKEN_READ_TIMEOUT_SECS =
1.freeze
Constants inherited from Vendor
Instance Attribute Summary
Attributes inherited from Vendor
Class Method Summary collapse
Methods inherited from Vendor
#detect, endpoint, headers, #initialize, key_transforms, keys, processed_headers, vendor_name
Constructor Details
This class inherits a constructor from NewRelic::Agent::Utilization::Vendor
Class Method Details
.imds_token ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/new_relic/agent/utilization/aws.rb', line 18 def imds_token uri = URI.parse("#{IMDS_BASE_URL}/api/token") http = Net::HTTP.new(uri.hostname) http.open_timeout = TOKEN_OPEN_TIMEOUT_SECS http.read_timeout = TOKEN_READ_TIMEOUT_SECS response = http.send_request('PUT', uri.path, '', {'X-aws-ec2-metadata-token-ttl-seconds' => IMDS_TOKEN_TTL_SECS}) unless response.code == Vendor::SUCCESS NewRelic::Agent.logger.debug('Failed to obtain an AWS token for use with IMDS - encountered ' \ "#{response.class} with HTTP response code #{response.code} - " \ 'assuming non AWS') return end response.body rescue Net::OpenTimeout NewRelic::Agent.logger.debug('Timed out waiting for AWS IMDS - assuming non AWS') end |