示例#1
0
        /// <summary>
        /// Get the system uptime
        /// </summary>
        /// <returns>System uptime</returns>
        public async Task <Uptime> GetSystemUpTime()
        {
            var queryString = "SELECT LastBootUpTime FROM Win32_OperatingSystem";
            var wmiReader   = new WmiReader();
            var results     = await wmiReader.ExecuteScalar(queryString);

            return(new Uptime()
            {
                UpTime = Uptime.ParseUpTime(results["LastBootUpTime"].ToString())
            });
        }
示例#2
0
        /// <summary>
        /// Provide the list of CPU
        /// </summary>
        /// <returns>A list of CPU</returns>
        public async Task <IEnumerable <Cpu> > GetCPUsUsage()
        {
            var queryString = "SELECT name, PercentProcessorTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE NOT name = '_Total'";
            var wmiReader   = new WmiReader();
            var results     = await wmiReader.Execute(queryString);

            return(results.Select(mo => new wttop.Core.Cpu()
            {
                Name = mo["name"].ToString(),
                PercentageUsage = int.Parse(mo["PercentProcessorTime"].ToString())
            }));
        }
示例#3
0
        /// <summary>
        /// Provide the operating system information
        /// </summary>
        /// <returns>Operating system information </returns>
        public async Task <OSInfo> GetOSInfo()
        {
            var queryString = "SELECT caption, version, CSName FROM Win32_OperatingSystem";
            var wmiReader   = new WmiReader();
            var results     = await wmiReader.ExecuteScalar(queryString);

            return(new OSInfo()
            {
                MachineName = results["CSName"].ToString(),
                OSName = results["caption"].ToString(),
                Version = results["version"].ToString()
            });
        }
示例#4
0
        /// <summary>
        /// Get the disk storage information
        /// </summary>
        /// <returns>A list of storage information</returns>
        public async Task <IEnumerable <Storage> > GetDiskStorageInfo()
        {
            var queryString = "SELECT VolumeName, Caption, FreeSpace, Size FROM Win32_logicaldisk";
            var wmiReader   = new WmiReader();
            var results     = await wmiReader.Execute(queryString);

            return(results.Select(mo => new Storage()
            {
                VolumeCaption = mo["Caption"].ToString(),
                VolumeName = mo["VolumeName"].ToString(),
                AvailableKb = Convert.ToInt64(mo["FreeSpace"]),
                TotalKb = Convert.ToInt64(mo["Size"])
            }));
        }
示例#5
0
        /// <summary>
        /// Get the disk activity
        /// </summary>
        /// <returns>Disk information</returns>
        public async Task <Disk> GetDiskActivity()
        {
            var queryString = "SELECT DiskReadBytesPersec, DiskWriteBytesPersec, Name FROM Win32_PerfRawData_PerfDisk_PhysicalDisk WHERE NOT name = '_Total'";
            var wmiReader   = new WmiReader();
            var results     = await wmiReader.Execute(queryString);

            return(new Disk()
            {
                Disks = results.Select(mo => new DiskDetails()
                {
                    Name = mo["Name"].ToString(),
                    BytesRead = Convert.ToInt64(mo["DiskReadBytesPersec"]),
                    BytesWriten = Convert.ToInt64(mo["DiskWriteBytesPersec"])
                })
                        .ToList()
            });
        }
示例#6
0
        ///// <summary>
        /// Get the network statistics
        /// </summary>
        /// <returns>Network information</returns>
        public async Task <Network> GetNetworkStatistics()
        {
            var queryString = "SELECT BytesReceivedPersec, BytesSentPersec, Name FROM Win32_PerfRawData_Tcpip_NetworkInterface";
            var wmiReader   = new WmiReader();
            var results     = await wmiReader.Execute(queryString);

            return(new Network()
            {
                Interfaces = results.Select(mo => new InterfaceDetails()
                {
                    Name = mo["Name"].ToString(),
                    BytesReceived = Convert.ToInt64(mo["BytesReceivedPersec"]),
                    BytesSent = Convert.ToInt64(mo["BytesSentPersec"])
                })
                             .ToList()
            });
        }