Beispiel #1
0
 public override Task <object> NetworkThroughput()
 {
     return(Task.Run(() =>
     {
         return (object)new
         {
             sent = Math.Round(SentCounters.Sum(s => s.NextValue()) / 1024 / 1024, 2),
             received = Math.Round(ReceivedCounters.Sum(r => r.NextValue()) / 1024 / 1024, 2)
         };
     }));
 }
Beispiel #2
0
        public WindowsSystemStatus()
        {
            try
            {
                using (var mc = new ManagementClass("Win32_Processor"))
                {
                    var moc = mc.GetInstances();
                    Cpu = moc.OfType <ManagementObject>()
                          .Select(mo => mo["Name"].ToString())
                          .FirstOrDefault();
                }
            }
            catch
            {
                Cpu = "Unable to obtain";
            }

            CpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            CpuCounter.NextValue();

            RamCounter = new PerformanceCounter("Memory", "Available MBytes");
            RamCounter.NextValue();

            PerformanceCounterCategory pcCategory = new PerformanceCounterCategory("Network Interface");

            string[] iNames = pcCategory.GetInstanceNames();

            SentCounters = iNames.Select(i => new PerformanceCounter("Network Interface", "Bytes Sent/sec", i)).ToArray();
            SentCounters.Sum(s => s.NextValue());
            ReceivedCounters = iNames.Select(i => new PerformanceCounter("Network Interface", "Bytes Received/sec", i)).ToArray();
            ReceivedCounters.Sum(r => r.NextValue());

            var memStatus       = new MEMORYSTATUSEX();
            var installedMemory = GlobalMemoryStatusEx(memStatus) ? memStatus.ullTotalPhys / 1024 / 1024 : 0f;

            Memory = installedMemory;
        }
Beispiel #3
0
        /// <summary>
        /// 网络上传速度
        /// </summary>
        public double GetSentSpeed()
        {
            var sendSum = SentCounters.Sum(t => t.NextValue());

            return(Math.Round(sendSum / 1024, 1));
        }