Exemplo n.º 1
0
            private async Task UpdateNodeDataAsync()
            {
                const string machineQuery = @"SELECT 
                DNSHostName,
                Domain,
                Manufacturer,
                Model,
                NumberOfLogicalProcessors
                FROM Win32_ComputerSystem";

                using (var q = Wmi.Query(Endpoint, machineQuery))
                {
                    var data = await q.GetFirstResultAsync().ConfigureAwait(false);

                    if (data != null)
                    {
                        Model        = data.Model;
                        Manufacturer = data.Manufacturer;
                        // Only use domain if we're on one - not for things like workgroups
                        Name = _machineDomainName.HasValue() && data.Domain != _machineDomainName
                                   ? $"{data.DNSHostName}.{data.Domain}"
                                   : data.DNSHostName;
                        NumberOfLogicalProcessors = data.NumberOfLogicalProcessors;
                    }
                }

                const string query = @"SELECT 
                Caption,
                LastBootUpTime,
                Version,
                FreePhysicalMemory,
                TotalVisibleMemorySize,
                Version
                FROM Win32_OperatingSystem";

                using (var q = Wmi.Query(Endpoint, query))
                {
                    var data = await q.GetFirstResultAsync().ConfigureAwait(false);

                    if (data != null)
                    {
                        LastBoot      = ManagementDateTimeConverter.ToDateTime(data.LastBootUpTime);
                        TotalMemory   = data.TotalVisibleMemorySize * 1024;
                        MemoryUsed    = TotalMemory - (data.FreePhysicalMemory * 1024);
                        KernelVersion = Version.Parse(data.Version);
                        MachineType   = data.Caption.ToString() + " " + data.Version.ToString();
                    }
                }

                const string servicetagquery = @"SELECT 
                    SerialNumber
                    FROM Win32_BIOS";

                using (var q = Wmi.Query(Endpoint, servicetagquery))
                {
                    var data = await q.GetFirstResultAsync().ConfigureAwait(false);

                    if (data != null)
                    {
                        ServiceTag = data.SerialNumber;
                    }
                }

                LastSync = DateTime.UtcNow;
                Status   = NodeStatus.Active;

                IsVMHost = await GetIsVMHost().ConfigureAwait(false);

                _canQueryAdapterUtilization = await GetCanQueryAdapterUtilization().ConfigureAwait(false);

                _canQueryTeamingInformation = await Wmi.ClassExists(Endpoint, "MSFT_NetLbfoTeamMember", @"root\standardcimv2").ConfigureAwait(false);
            }
Exemplo n.º 2
0
 private Task <bool> GetIsVMHost()
 => Wmi.ClassExists(Endpoint, "Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor");