in source/code/plugins/agent_topology_request_script.rb [32:90]
def get_telemetry_data(os_info, conf_omsadmin, pid_file)
os = AgentTopologyRequestOperatingSystem.new
telemetry = AgentTopologyRequestOperatingSystemTelemetry.new
if !File.exist?(os_info) && !File.readable?(os_info)
raise ArgumentError, " Unable to read file #{os_info}; telemetry information will not be sent to server"
end
if File.exist?('/var/opt/microsoft/docker-cimprov/state/containerhostname')
os.InContainer = "True"
containerimagetagfile = '/var/opt/microsoft/docker-cimprov/state/omscontainertag'
if File.exist?(containerimagetagfile) && File.readable?(containerimagetagfile)
os.InContainerVersion = File.read(containerimagetagfile)
end
if !ENV['AKS_RESOURCE_ID'].nil?
os.IsAKSEnvironment = "True"
end
k8sversionfile = "/var/opt/microsoft/docker-cimprov/state/kubeletversion"
if File.exist?(k8sversionfile) && File.readable?(k8sversionfile)
os.K8SVersion = File.read(k8sversionfile)
end
else
os.InContainer = "False"
end
if ENV['TEST_WORKSPACE_ID'].nil? && ENV['TEST_SHARED_KEY'].nil? && File.exist?(conf_omsadmin)
process_stats = ""
if File.exist?(pid_file) and File.readable?(pid_file)
pid = File.read(pid_file)
process_stats = `/opt/omi/bin/omicli wql root/scx \"SELECT PercentUserTime, PercentPrivilegedTime, UsedMemory, PercentUsedMemory FROM SCX_UnixProcessStatisticalInformation where Handle='#{pid}'\" | grep =`
end
process_stats.each_line do |line|
telemetry.PercentUserTime = line.sub("PercentUserTime=","").strip.to_i if line =~ /PercentUserTime/
telemetry.PercentPrivilegedTime = line.sub("PercentPrivilegedTime=", "").strip.to_i if line =~ /PercentPrivilegedTime/
telemetry.UsedMemory = line.sub("UsedMemory=", "").strip.to_i if line =~ / UsedMemory/
telemetry.PercentUsedMemory = line.sub("PercentUsedMemory=", "").strip.to_i if line =~ /PercentUsedMemory/
end
end
# Get OS info from scx-release
File.open(os_info).each_line do |line|
os.Name = line.sub("OSName=","").strip if line =~ /OSName/
os.Manufacturer = line.sub("OSManufacturer=","").strip if line =~ /OSManufacturer/
os.Version = line.sub("OSVersion=","").strip if line =~ /OSVersion/
end
self.OperatingSystem = os
os.Telemetry = telemetry
os.ProcessorArchitecture = "x64"
# If OperatingSystem is sent in the topology request with nil OS Name, Manufacturer or Version, we get HTTP 403 error
if !os.Name || !os.Manufacturer || !os.Version
self.OperatingSystem = nil
end
end