public static string GetUpdatedSystemPerformanceDrivesStatistic(string ThreadLastUpdateDateStr) { DataTransfer <List <ControlPanel.Core.Entities.DriveStatistic> > dt = new DataTransfer <List <ControlPanel.Core.Entities.DriveStatistic> >(); try { DriveStatisticRepository repo = new DriveStatisticRepository(); DateTime date = DateTime.UtcNow; if (!DateTime.TryParse(ThreadLastUpdateDateStr, out date)) { date = DateTime.UtcNow; } List <ControlPanel.Core.Entities.DriveStatistic> stats = repo.GetPerformanceDrivesStatisticThreadByLastUpdatedDate(date.ToUniversalTime()); if (stats != null) { stats = stats.OrderBy(x => x.CreationDate).ToList(); } dt.Data = stats; } catch (Exception exp) { dt.IsSuccess = false; dt.Errors = new string[] { exp.Message }; } return(JSONhelper.GetString(dt)); }
public PerformanceStatistic GetPCPerformance() { PerformanceStatistic stats = new PerformanceStatistic(); PerformanceCounter cpuCounter; PerformanceCounter ramCounter; cpuCounter = new PerformanceCounter(); cpuCounter.CategoryName = "Processor"; cpuCounter.CounterName = "% Processor Time"; cpuCounter.InstanceName = "_Total"; ramCounter = new PerformanceCounter("Memory", "Available MBytes"); Int64 phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB(); Int64 tot = PerformanceInfo.GetTotalMemoryInMiB(); stats.Memory = Math.Round((double)(100 - (((decimal)phav / (decimal)tot) * 100)), 2); stats.Cpu = cpuCounter.NextValue(); Thread.Sleep(1000); stats.Cpu = cpuCounter.NextValue(); stats.CreationDate = DateTime.UtcNow; stats.MachineName = System.Environment.MachineName.ToString(); DriveInfo[] allDrives = DriveInfo.GetDrives(); DriveStatisticRepository driveRepo = new DriveStatisticRepository(); if (allDrives.Count() > 0) { stats.DriveSpaceAvailable = 0; stats.DriveTotalSpace = 0; for (int i = 0; i < allDrives.Count(); i++) { try { DriveStatistic dS = new DriveStatistic(); dS.CreationDate = stats.CreationDate; dS.DriveName = allDrives[i].Name; dS.MachineName = stats.MachineName + ":" + allDrives[i].Name; dS.DriveSpaceAvailable = Math.Round(((allDrives[i].TotalFreeSpace / 1024.0) / 1024.0) / 1024.0, 2); dS.DriveTotalSpace = Math.Round(((allDrives[i].TotalSize / 1024.0) / 1024.0) / 1024.0, 2); string hostNames = Dns.GetHostName(); string myIPs = Dns.GetHostByName(hostNames).AddressList[0].ToString(); dS.IpAddress = myIPs + ":" + allDrives[i].Name; driveRepo.InsertDriveStatistic(dS); stats.DriveSpaceAvailable += dS.DriveSpaceAvailable; stats.DriveTotalSpace += dS.DriveTotalSpace; } catch (Exception exp) { } } } string hostName = Dns.GetHostName(); string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString(); stats.IpAddress = myIP; return(stats); }