- Timestamp:
- 08/13/15 15:22:51 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataController.cs
r12691 r12858 99 99 100 100 public DT.Status GetStatus() { 101 using (var pm = PersistenceManager) { 102 var slaveDao = pm.SlaveDao; 103 var onlineSlaves = pm.UseTransaction(() => slaveDao.GetOnlineSlaves().ToList()); 104 var activeSlaves = onlineSlaves.Where(s => s.IsAllowedToCalculate).ToList(); 105 var calculatingSlaves = activeSlaves.Where(s => s.SlaveState == SlaveState.Calculating).ToList(); 106 int totalCores = onlineSlaves.Sum(s => s.Cores ?? 0); 107 int totalMemory = onlineSlaves.Sum(s => s.Memory ?? 0); 108 return new DT.Status { 109 CoreStatus = new DT.CoreStatus { 110 TotalCores = totalCores, 111 UsedCores = totalCores - onlineSlaves.Sum(s => s.FreeCores ?? 0), 112 ActiveCores = activeSlaves.Sum(s => s.Cores ?? 0), 113 CalculatingCores = calculatingSlaves.Sum(s => s.Cores ?? 0) - calculatingSlaves.Sum(s => s.FreeCores ?? 0) 101 var pm = PersistenceManager; 102 var slaveDao = pm.SlaveDao; 103 var onlineSlaves = pm.UseTransaction(() => slaveDao.GetOnlineSlaves().ToList()); 104 var activeSlaves = onlineSlaves.Where(s => s.IsAllowedToCalculate).ToList(); 105 var calculatingSlaves = activeSlaves.Where(s => s.SlaveState == SlaveState.Calculating).ToList(); 106 int totalCores = onlineSlaves.Sum(s => s.Cores ?? 0); 107 int totalMemory = onlineSlaves.Sum(s => s.Memory ?? 0); 108 return new DT.Status { 109 CoreStatus = new DT.CoreStatus { 110 TotalCores = totalCores, 111 UsedCores = totalCores - onlineSlaves.Sum(s => s.FreeCores ?? 0), 112 ActiveCores = activeSlaves.Sum(s => s.Cores ?? 0), 113 CalculatingCores = calculatingSlaves.Sum(s => s.Cores ?? 0) - calculatingSlaves.Sum(s => s.FreeCores ?? 0) 114 }, 115 CpuUtilizationStatus = new DT.CpuUtilizationStatus { 116 TotalCpuUtilization = onlineSlaves.Any() 117 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2) 118 : 0.0, 119 ActiveCpuUtilization = activeSlaves.Any() 120 ? Math.Round(activeSlaves.Average(s => s.CpuUtilization), 2) 121 : 0.0, 122 CalculatingCpuUtilization = calculatingSlaves.Any() 123 ? Math.Round(calculatingSlaves.Average(s => s.CpuUtilization), 2) 124 : 0.0 125 }, 126 MemoryStatus = new DT.MemoryStatus { 127 TotalMemory = totalMemory, 128 UsedMemory = totalMemory - onlineSlaves.Sum(s => s.FreeMemory ?? 0), 129 ActiveMemory = activeSlaves.Sum(s => s.Memory ?? 0), 130 CalculatingMemory = calculatingSlaves.Sum(s => s.Memory ?? 0) - calculatingSlaves.Sum(s => s.FreeMemory ?? 0) 131 }, 132 TimeStatus = GetTimeStatus(pm), 133 TasksStatus = GetTaskStatus(pm), 134 SlavesStatus = onlineSlaves.Select(x => new DT.SlaveStatus { 135 Slave = new DT.Slave { 136 Id = x.ResourceId.ToString(), 137 Name = x.Name 114 138 }, 115 CpuUtilizationStatus = new DT.CpuUtilizationStatus { 116 TotalCpuUtilization = onlineSlaves.Any() 117 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2) 118 : 0.0, 119 ActiveCpuUtilization = activeSlaves.Any() 120 ? Math.Round(activeSlaves.Average(s => s.CpuUtilization), 2) 121 : 0.0, 122 CalculatingCpuUtilization = calculatingSlaves.Any() 123 ? Math.Round(calculatingSlaves.Average(s => s.CpuUtilization), 2) 124 : 0.0 125 }, 126 MemoryStatus = new DT.MemoryStatus { 127 TotalMemory = totalMemory, 128 UsedMemory = totalMemory - onlineSlaves.Sum(s => s.FreeMemory ?? 0), 129 ActiveMemory = activeSlaves.Sum(s => s.Memory ?? 0), 130 CalculatingMemory = calculatingSlaves.Sum(s => s.Memory ?? 0) - calculatingSlaves.Sum(s => s.FreeMemory ?? 0) 131 }, 132 TimeStatus = GetTimeStatus(pm), 133 TasksStatus = GetTaskStatus(pm), 134 SlavesStatus = onlineSlaves.Select(x => new DT.SlaveStatus { 135 Slave = new DT.Slave { 136 Id = x.ResourceId.ToString(), 137 Name = x.Name 138 }, 139 CpuUtilization = x.CpuUtilization, 140 Cores = x.Cores ?? 0, 141 FreeCores = x.FreeCores ?? 0, 142 Memory = x.Memory ?? 0, 143 FreeMemory = x.FreeMemory ?? 0, 144 IsAllowedToCalculate = x.IsAllowedToCalculate, 145 State = x.SlaveState.ToString() 146 }).OrderBy(x => x.Slave.Name), 147 Timestamp = JavascriptUtils.ToTimestamp(DateTime.Now) 148 }; 149 } 139 CpuUtilization = x.CpuUtilization, 140 Cores = x.Cores ?? 0, 141 FreeCores = x.FreeCores ?? 0, 142 Memory = x.Memory ?? 0, 143 FreeMemory = x.FreeMemory ?? 0, 144 IsAllowedToCalculate = x.IsAllowedToCalculate, 145 State = x.SlaveState.ToString() 146 }).OrderBy(x => x.Slave.Name), 147 Timestamp = JavascriptUtils.ToTimestamp(DateTime.Now) 148 }; 150 149 } 151 150 … … 158 157 increment += 5; 159 158 } 160 using (var pm = PersistenceManager) { 161 var factClientInfoDao = pm.FactClientInfoDao; 162 var clientInfos = pm.UseTransaction(() => { 163 return factClientInfoDao.GetAll() 164 .Where(s => s.Time >= start 165 && s.Time <= end 166 && s.SlaveState != SlaveState.Offline) 167 .OrderBy(s => s.Time) 168 .GroupBy(s => s.Time) 169 .Select(x => new { 170 Timestamp = x.Key, 171 TotalCores = x.Sum(y => y.NumTotalCores), 172 UsedCores = x.Sum(y => y.NumUsedCores), 173 TotalMemory = x.Sum(y => y.TotalMemory), 174 UsedMemory = x.Sum(y => y.UsedMemory), 175 CpuUtilization = x.Where(y => y.IsAllowedToCalculate).Average(y => y.CpuUtilization) 176 }) 177 .ToList(); 178 }); 179 var statusList = new List<DT.Status>(); 180 var e = clientInfos.GetEnumerator(); 181 do { 182 var status = new DT.Status { 183 CoreStatus = new DT.CoreStatus(), 184 CpuUtilizationStatus = new DT.CpuUtilizationStatus(), 185 MemoryStatus = new DT.MemoryStatus() 186 }; 187 int i = 0; 188 DateTime lastTimestamp = DateTime.Now; 189 while (e.MoveNext()) { 190 var clientInfo = e.Current; 191 status.CoreStatus.TotalCores += clientInfo.TotalCores; 192 status.CoreStatus.UsedCores += clientInfo.UsedCores; 193 status.MemoryStatus.TotalMemory += clientInfo.TotalMemory; 194 status.MemoryStatus.UsedMemory += clientInfo.UsedMemory; 195 status.CpuUtilizationStatus.TotalCpuUtilization += clientInfo.CpuUtilization; 196 lastTimestamp = clientInfo.Timestamp; 197 i++; 198 if (i >= increment) 199 break; 200 } 201 if (i <= 0) continue; 202 status.Timestamp = JavascriptUtils.ToTimestamp(lastTimestamp); 203 status.CoreStatus.TotalCores /= i; 204 status.CoreStatus.UsedCores /= i; 205 status.MemoryStatus.TotalMemory /= i; 206 status.MemoryStatus.UsedMemory /= i; 207 status.CpuUtilizationStatus.TotalCpuUtilization /= i; 208 statusList.Add(status); 209 } while (e.Current != null); 210 return statusList; 211 } 159 var pm = PersistenceManager; 160 var factClientInfoDao = pm.FactClientInfoDao; 161 var clientInfos = pm.UseTransaction(() => { 162 return factClientInfoDao.GetAll() 163 .Where(s => s.Time >= start 164 && s.Time <= end 165 && s.SlaveState != SlaveState.Offline) 166 .OrderBy(s => s.Time) 167 .GroupBy(s => s.Time) 168 .Select(x => new { 169 Timestamp = x.Key, 170 TotalCores = x.Sum(y => y.NumTotalCores), 171 UsedCores = x.Sum(y => y.NumUsedCores), 172 TotalMemory = x.Sum(y => y.TotalMemory), 173 UsedMemory = x.Sum(y => y.UsedMemory), 174 CpuUtilization = x.Where(y => y.IsAllowedToCalculate).Average(y => y.CpuUtilization) 175 }) 176 .ToList(); 177 }); 178 var statusList = new List<DT.Status>(); 179 var e = clientInfos.GetEnumerator(); 180 do { 181 var status = new DT.Status { 182 CoreStatus = new DT.CoreStatus(), 183 CpuUtilizationStatus = new DT.CpuUtilizationStatus(), 184 MemoryStatus = new DT.MemoryStatus() 185 }; 186 int i = 0; 187 DateTime lastTimestamp = DateTime.Now; 188 while (e.MoveNext()) { 189 var clientInfo = e.Current; 190 status.CoreStatus.TotalCores += clientInfo.TotalCores; 191 status.CoreStatus.UsedCores += clientInfo.UsedCores; 192 status.MemoryStatus.TotalMemory += clientInfo.TotalMemory; 193 status.MemoryStatus.UsedMemory += clientInfo.UsedMemory; 194 status.CpuUtilizationStatus.TotalCpuUtilization += clientInfo.CpuUtilization; 195 lastTimestamp = clientInfo.Timestamp; 196 i++; 197 if (i >= increment) 198 break; 199 } 200 if (i <= 0) continue; 201 status.Timestamp = JavascriptUtils.ToTimestamp(lastTimestamp); 202 status.CoreStatus.TotalCores /= i; 203 status.CoreStatus.UsedCores /= i; 204 status.MemoryStatus.TotalMemory /= i; 205 status.MemoryStatus.UsedMemory /= i; 206 status.CpuUtilizationStatus.TotalCpuUtilization /= i; 207 statusList.Add(status); 208 } while (e.Current != null); 209 return statusList; 212 210 } 213 211
Note: See TracChangeset
for help on using the changeset viewer.