Class: NewRelic::Agent::UtilizationData
- Inherits:
-
Object
- Object
- NewRelic::Agent::UtilizationData
- Defined in:
- lib/new_relic/agent/utilization_data.rb
Constant Summary collapse
- METADATA_VERSION =
5
- VENDORS =
{ Utilization::AWS => :'utilization.detect_aws', Utilization::GCP => :'utilization.detect_gcp', Utilization::Azure => :'utilization.detect_azure', Utilization::PCF => :'utilization.detect_pcf' }
- KUBERNETES_SERVICE_HOST =
'KUBERNETES_SERVICE_HOST'.freeze
Instance Method Summary collapse
- #append_boot_id(collector_hash) ⇒ Object
- #append_configured_values(collector_hash) ⇒ Object
- #append_docker_info(collector_hash) ⇒ Object
- #append_ecs_info(collector_hash) ⇒ Object
- #append_full_hostname(collector_hash) ⇒ Object
- #append_ip_address(collector_hash) ⇒ Object
- #append_kubernetes_info(collector_hash) ⇒ Object
- #append_vendor_info(collector_hash) ⇒ Object
- #config_hash ⇒ Object
- #configured_hostname ⇒ Object
-
#configured_logical_processors ⇒ Object
this is slightly ugly, but if a string value is passed in for the env var: NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS the coercion from EnvironmentSource will turn that into a numerical 0, which is not a reasonable value for logical_processes and should not be sent up.
-
#configured_total_ram_mib ⇒ Object
see comment above as the situation is the same for: NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB.
- #container_id ⇒ Object
- #cpu_count ⇒ Object
- #fqdn ⇒ Object
- #hostname ⇒ Object
- #ip_addresses ⇒ Object
- #ram_in_mib ⇒ Object
- #to_collector_hash ⇒ Object
Instance Method Details
#append_boot_id(collector_hash) ⇒ Object
149 150 151 152 153 |
# File 'lib/new_relic/agent/utilization_data.rb', line 149 def append_boot_id(collector_hash) if bid = ::NewRelic::Agent::SystemInfo.boot_id collector_hash[:boot_id] = bid end end |
#append_configured_values(collector_hash) ⇒ Object
145 146 147 |
# File 'lib/new_relic/agent/utilization_data.rb', line 145 def append_configured_values(collector_hash) collector_hash[:config] = config_hash unless config_hash.empty? end |
#append_docker_info(collector_hash) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/new_relic/agent/utilization_data.rb', line 136 def append_docker_info(collector_hash) return unless Agent.config[:'utilization.detect_docker'] if docker_container_id = container_id collector_hash[:vendors] ||= {} collector_hash[:vendors][:docker] = {:id => docker_container_id} end end |
#append_ecs_info(collector_hash) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/new_relic/agent/utilization_data.rb', line 89 def append_ecs_info(collector_hash) return unless Agent.config[:'utilization.detect_aws'] Thread.new do # try v4 first, and only try unversioned endpoint if v4 fails ecs = Utilization::ECSV4.new if ecs.detect collector_hash[:vendors] ||= {} collector_hash[:vendors][:ecs] = ecs. else ecs = Utilization::ECS.new if ecs.detect collector_hash[:vendors] ||= {} collector_hash[:vendors][:ecs] = ecs. end end end end |
#append_full_hostname(collector_hash) ⇒ Object
173 174 175 176 177 178 |
# File 'lib/new_relic/agent/utilization_data.rb', line 173 def append_full_hostname(collector_hash) full_hostname = fqdn return if full_hostname.nil? || full_hostname.empty? collector_hash[:full_hostname] = full_hostname end |
#append_ip_address(collector_hash) ⇒ Object
155 156 157 158 |
# File 'lib/new_relic/agent/utilization_data.rb', line 155 def append_ip_address(collector_hash) ips = ip_addresses collector_hash[:ip_address] = ips unless ips.empty? end |
#append_kubernetes_info(collector_hash) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/new_relic/agent/utilization_data.rb', line 162 def append_kubernetes_info(collector_hash) return unless Agent.config[:'utilization.detect_kubernetes'] if host = ENV[KUBERNETES_SERVICE_HOST] collector_hash[:vendors] ||= {} collector_hash[:vendors][:kubernetes] = { kubernetes_service_host: host } end end |
#append_vendor_info(collector_hash) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/new_relic/agent/utilization_data.rb', line 108 def append_vendor_info(collector_hash) threads = [] complete = false # ecs needs be checked even if AWS check succeeds ecs_thread = append_ecs_info(collector_hash) VENDORS.each_pair do |klass, config_option| next unless Agent.config[config_option] threads << Thread.new do vendor = klass.new if vendor.detect collector_hash[:vendors] ||= {} collector_hash[:vendors][vendor.vendor_name.to_sym] = vendor. complete = true end end end while complete == false && threads.any?(&:alive?) sleep 0.01 end ecs_thread&.join end |
#config_hash ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/new_relic/agent/utilization_data.rb', line 180 def config_hash config_hash = {} if hostname = configured_hostname config_hash[:hostname] = hostname end if logical_processors = configured_logical_processors config_hash[:logical_processors] = logical_processors end if total_ram_mib = configured_total_ram_mib config_hash[:total_ram_mib] = total_ram_mib end config_hash end |
#configured_hostname ⇒ Object
49 50 51 |
# File 'lib/new_relic/agent/utilization_data.rb', line 49 def configured_hostname Agent.config[:'utilization.billing_hostname'] end |
#configured_logical_processors ⇒ Object
this is slightly ugly, but if a string value is passed in for the env var: NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS the coercion from EnvironmentSource will turn that into a numerical 0, which is not a reasonable value for logical_processes and should not be sent up
58 59 60 61 |
# File 'lib/new_relic/agent/utilization_data.rb', line 58 def configured_logical_processors logical_processors = Agent.config[:'utilization.logical_processors'] logical_processors unless logical_processors == 0 end |
#configured_total_ram_mib ⇒ Object
see comment above as the situation is the same for: NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB
65 66 67 68 |
# File 'lib/new_relic/agent/utilization_data.rb', line 65 def configured_total_ram_mib total_ram = Agent.config[:'utilization.total_ram_mib'] total_ram unless total_ram == 0 end |
#container_id ⇒ Object
36 37 38 |
# File 'lib/new_relic/agent/utilization_data.rb', line 36 def container_id ::NewRelic::Agent::SystemInfo.docker_container_id end |
#cpu_count ⇒ Object
40 41 42 43 |
# File 'lib/new_relic/agent/utilization_data.rb', line 40 def cpu_count ::NewRelic::Agent::SystemInfo.clear_processor_info ::NewRelic::Agent::SystemInfo.num_logical_processors end |
#fqdn ⇒ Object
28 29 30 |
# File 'lib/new_relic/agent/utilization_data.rb', line 28 def fqdn NewRelic::Agent::Hostname.get_fqdn end |
#hostname ⇒ Object
24 25 26 |
# File 'lib/new_relic/agent/utilization_data.rb', line 24 def hostname NewRelic::Agent::Hostname.get end |
#ip_addresses ⇒ Object
32 33 34 |
# File 'lib/new_relic/agent/utilization_data.rb', line 32 def ip_addresses ::NewRelic::Agent::SystemInfo.ip_addresses end |
#ram_in_mib ⇒ Object
45 46 47 |
# File 'lib/new_relic/agent/utilization_data.rb', line 45 def ram_in_mib ::NewRelic::Agent::SystemInfo.ram_in_mib end |
#to_collector_hash ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/new_relic/agent/utilization_data.rb', line 70 def to_collector_hash result = { :metadata_version => METADATA_VERSION, :logical_processors => cpu_count, :total_ram_mib => ram_in_mib, :hostname => hostname } append_vendor_info(result) append_docker_info(result) append_configured_values(result) append_boot_id(result) append_ip_address(result) append_full_hostname(result) append_kubernetes_info(result) result end |