public IEnumerable <DT.ClientStatus> GetClientHistory(Guid id, DateTime start, DateTime end) { TimeSpan ts = end - start; int increment = 1; double totalMinutes = ts.TotalMinutes; while (totalMinutes > 5761) { totalMinutes -= 5761; increment += 5; } var pm = PersistenceManager; var factClientInfo = pm.FactClientInfoDao; var clientInfos = factClientInfo.GetByClientId(id) .Where(x => x.Time >= start && x.Time <= end) .OrderBy(x => x.Time) .ToList(); var clientStatus = new DT.ClientStatus { CpuUtilization = 0, TotalCores = 0, UsedCores = 0, TotalMemory = 0, UsedMemory = 0 }; int i = 1; foreach (var clientInfo in clientInfos) { clientStatus.CpuUtilization += clientInfo.CpuUtilization; clientStatus.TotalCores += clientInfo.NumTotalCores; clientStatus.UsedCores += clientInfo.NumUsedCores; clientStatus.TotalMemory += clientInfo.TotalMemory; clientStatus.UsedMemory += clientInfo.UsedMemory; if (i >= increment) { clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time); clientStatus.CpuUtilization /= i; clientStatus.TotalCores /= i; clientStatus.UsedCores /= i; clientStatus.TotalMemory /= i; clientStatus.UsedMemory /= i; yield return(clientStatus); clientStatus = new DT.ClientStatus { CpuUtilization = 0, TotalCores = 0, UsedCores = 0, TotalMemory = 0, UsedMemory = 0 }; i = 1; } else { ++i; } } }
public IEnumerable<DT.ClientStatus> GetClientHistoryByGroupId(Guid id, DateTime start, DateTime end) { TimeSpan ts = end - start; int increment = 1; double totalMinutes = ts.TotalMinutes; while (totalMinutes > 5761) { totalMinutes -= 5761; increment += 5; } var pm = PersistenceManager; var factClientInfo = pm.FactClientInfoDao; var dimClientDao = pm.DimClientDao; var clientInfos = factClientInfo.GetAll() .Where(x => x.Time >= start && x.Time <= end) .OrderBy(x => x.Time) .Join(dimClientDao.GetAll(), fact => fact.ClientId, client => client.Id, (fact, client) => new { client.ResourceGroupId, fact.Time, fact.CpuUtilization, fact.NumTotalCores, fact.NumUsedCores, fact.TotalMemory, fact.UsedMemory }) .Where(x => x.ResourceGroupId == id) .ToList(); var clientStatus = new DT.ClientStatus { CpuUtilization = 0, TotalCores = 0, UsedCores = 0, TotalMemory = 0, UsedMemory = 0 }; int i = 1; foreach (var clientInfo in clientInfos) { clientStatus.CpuUtilization += clientInfo.CpuUtilization; clientStatus.TotalCores += clientInfo.NumTotalCores; clientStatus.UsedCores += clientInfo.NumUsedCores; clientStatus.TotalMemory += clientInfo.TotalMemory; clientStatus.UsedMemory += clientInfo.UsedMemory; if (i >= increment) { clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time); clientStatus.CpuUtilization /= i; clientStatus.TotalCores /= i; clientStatus.UsedCores /= i; clientStatus.TotalMemory /= i; clientStatus.UsedMemory /= i; yield return clientStatus; clientStatus = new DT.ClientStatus { CpuUtilization = 0, TotalCores = 0, UsedCores = 0, TotalMemory = 0, UsedMemory = 0 }; i = 1; } else { ++i; } } }