Inheritance: CollectableValue
        public IList<CollectableValue> Read()
        {
            var collectedValueList = new List<CollectableValue>();

            collectedValueList.AddRange(GetCommonAttributes());

            if (_readEC2InstanceMetadata)
            {
                // This is only done once on the assumption that the EC2 would have to reboot for these values to change
                collectedValueList.AddRange(GetEC2Metadata());
                _readEC2InstanceMetadata = false;
            }
            foreach (Attribute attribute in _attributes)
            {
                try
                {
                    string value = Environment.GetEnvironmentVariable(attribute.variableName);
                    AttributeValue attr = new AttributeValue(_hostName, attribute.name, value);
                    attr.HostName = _hostName;
                    collectedValueList.Add(attr);

                }
                catch (Exception ex)
                {
                    Logger.Warn(string.Format("Failed to collect attribute: {0}", attribute.variableName), ex);
                }
            }
            return collectedValueList;
        }
        private IList<CollectableValue> GetCommonAttributes()
        {
            // Return standard attributes
            IList<CollectableValue> attributes = new List<CollectableValue>();

            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);

            AttributeValue numProcessors = new AttributeValue(_hostName, "cpus", Environment.ProcessorCount.ToString());
            attributes.Add(numProcessors);

            AttributeValue osVersion = new AttributeValue(_hostName, "osversion", Environment.OSVersion.ToString());
            attributes.Add(osVersion);

            AttributeValue agent = new AttributeValue(_hostName, "agent", "collectdwin-" + fvi.FileVersion);
            attributes.Add(agent);

            long totalRAM = 0;
            try
            {
                ConnectionOptions connection = new ConnectionOptions();
                connection.Impersonation = ImpersonationLevel.Impersonate;
                ManagementScope scope = new ManagementScope("\\\\.\\root\\CIMV2", connection);
                scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    totalRAM += Convert.ToInt64(queryObj["Capacity"]);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("Failed to get system memory", ex);
            }
            AttributeValue ramBytes = new AttributeValue(_hostName, "ram bytes", totalRAM.ToString());
            attributes.Add(ramBytes);
            AttributeValue ram = new AttributeValue(_hostName, "ram", BytesToString(totalRAM));
            attributes.Add(ram);

            if (_readIPAddress)
            {
                try
                {
                    var host = Dns.GetHostEntry(Dns.GetHostName());
                    List<String> addressList = new List<string>();
                    foreach (var ip in host.AddressList)
                    {
                        // Only get IP V4 addresses for now
                        if (ip.AddressFamily == AddressFamily.InterNetwork)
                            addressList.Add(ip.ToString());
                    }

                    string ipStr = string.Join(",", addressList.ToArray());

                    AttributeValue ipAttr = new AttributeValue(_hostName, "ip", ipStr);
                    attributes.Add(ipAttr);
                }
                catch (Exception ex)
                {
                    Logger.Warn("Failed to get IP address", ex);
                }
            }
            return attributes;
        }
 protected void GetIngestAttributes(AttributeValue value, out List<IngestAttribute> attributes)
 {
     attributes = new List<IngestAttribute>();
     attributes.Add(new IngestAttribute(value.Name, value.Value));
 }