- Timestamp:
- 06/12/15 14:59:54 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataController.cs
r12428 r12435 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 21 42 SELECT 22 43 DISTINCT UserId, 23 ISNULL((SELECT Count FROM UserTasks WHERE TaskState = 'Calculating' AND UserId = ut.UserId), 0) AS CalculatingTasks,24 ISNULL((SELECT Count FROM UserTasks WHERE TaskState = 'Waiting' AND UserId = ut.UserId), 0) AS WaitingTasks44 (SELECT Count FROM UserTasks WHERE TaskState = 'Calculating' AND UserId = ut.UserId) AS CalculatingTasks, 45 (SELECT Count FROM UserTasks WHERE TaskState = 'Waiting' AND UserId = ut.UserId) AS WaitingTasks 25 46 FROM UserTasks ut;"; 26 47 … … 41 62 CalculatingTasks = uts.CalculatingTasks, 42 63 WaitingTasks = uts.WaitingTasks 43 }) ;64 }).OrderBy(x => x.User.Name); 44 65 } 45 66 // end temporary quickfix … … 50 71 where slave.SlaveState == SlaveState.Calculating || slave.SlaveState == SlaveState.Idle 51 72 select slave).ToList(); 73 var activeSlaves = onlineSlaves.Where(s => s.IsAllowedToCalculate).ToList(); 74 var calculatingSlaves = activeSlaves.Where(s => s.SlaveState == SlaveState.Calculating).ToList(); 75 76 int calculatingMemory = calculatingSlaves.Any() ? (int)calculatingSlaves.Sum(s => s.Memory) / 1024 : 0; 77 int freeCalculatingMemory = calculatingSlaves.Any() ? (int)calculatingSlaves.Sum(s => s.FreeMemory) / 1024 : 0; 78 52 79 return new DTO.Status { 53 80 CoreStatus = new DTO.CoreStatus { 54 81 TotalCores = onlineSlaves.Sum(s => s.Cores ?? 0), 55 AvailableCores = onlineSlaves.Where(s => s.IsAllowedToCalculate).Sum(s => s.Cores ?? 0), 56 FreeCores = onlineSlaves.Sum(s => s.FreeCores ?? 0) 82 FreeCores = onlineSlaves.Sum(s => s.FreeCores ?? 0), // temporary for old chart data 83 ActiveCores = activeSlaves.Sum(s => s.Cores ?? 0), 84 CalculatingCores = calculatingSlaves.Sum(s => s.Cores ?? 0) 57 85 }, 58 86 CpuUtilizationStatus = new DTO.CpuUtilizationStatus { … … 60 88 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2) 61 89 : 0.0, 62 UsedCpuUtilization = onlineSlaves.Any(x => x.IsAllowedToCalculate) 63 ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2) 64 : 0.0 90 ActiveCpuUtilization = activeSlaves.Any() 91 ? Math.Round(activeSlaves.Average(s => s.CpuUtilization), 2) 92 : 0.0, 93 CalculatingCpuUtilization = calculatingSlaves.Any() 94 ? Math.Round(calculatingSlaves.Average(s => s.CpuUtilization), 2) 95 : 0.0 65 96 }, 66 97 MemoryStatus = new DTO.MemoryStatus { 67 98 TotalMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.Memory) / 1024 : 0, 68 FreeMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.FreeMemory) / 1024 : 0 99 FreeMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.FreeMemory) / 1024 : 0, 100 ActiveMemory = activeSlaves.Any() ? (int)activeSlaves.Sum(s => s.Memory) / 1024 : 0, 101 UsedMemory = calculatingMemory - freeCalculatingMemory 69 102 }, 70 103 TasksStatus = GetTaskStatus(db), 71 SlavesCpuStatus = onlineSlaves.Select(x => new DTO.SlaveCpuStatus { 72 CpuUtilization = Math.Round(x.CpuUtilization, 2), 104 SlavesStatus = onlineSlaves.Select(x => new DTO.SlaveStatus { 73 105 Slave = new DTO.Slave { 74 106 Id = x.ResourceId.ToString(), 75 107 Name = x.Name 76 } 77 }), 108 }, 109 CpuUtilization = x.CpuUtilization, 110 Cores = x.Cores ?? 0, 111 FreeCores = x.FreeCores ?? 0, 112 Memory = (x.Memory ?? 0) / 1024, 113 FreeMemory = (x.FreeMemory ?? 0) / 1024, 114 IsAllowedToCalculate = x.IsAllowedToCalculate, 115 State = x.SlaveState.ToString() 116 }).OrderBy(x => x.Slave.Name), 78 117 Timestamp = JavascriptUtils.ToTimestamp(DateTime.Now) 79 118 }; … … 82 121 83 122 public IEnumerable<DTO.Status> GetStatusHistory(DateTime start, DateTime end) { 123 TimeSpan ts = end - start; 124 int increment = 1; 125 double totalMinutes = ts.TotalMinutes; 126 while (totalMinutes > 5761) { 127 totalMinutes -= 5761; 128 increment += 5; 129 } 84 130 using (var db = new HiveDataContext()) { 85 var statistics = db.Statistics.Where(s => s.Timestamp >= start && s.Timestamp <= end) 86 .OrderBy(x => x.Timestamp) 87 .ToList(); 131 var statistics = db.Statistics.Where(s => s.Timestamp >= start && s.Timestamp <= end); 132 var status = new DTO.Status { 133 CoreStatus = new DTO.CoreStatus(), 134 CpuUtilizationStatus = new DTO.CpuUtilizationStatus(), 135 MemoryStatus = new DTO.MemoryStatus() 136 }; 137 int freeCores = 0; 138 int freeMemory = 0; 139 int i = 1; 88 140 foreach (var statistic in statistics) { 89 yield return new DTO.Status { 90 CoreStatus = new DTO.CoreStatus { 91 TotalCores = statistic.SlaveStatistics.Sum(x => x.Cores), 92 AvailableCores = 0, 93 FreeCores = statistic.SlaveStatistics.Sum(x => x.FreeCores) 94 }, 95 CpuUtilizationStatus = new DTO.CpuUtilizationStatus { 96 TotalCpuUtilization = 0.0, 97 UsedCpuUtilization = statistic.SlaveStatistics.Any() ? statistic.SlaveStatistics.Average(x => x.CpuUtilization) : 0.0 98 }, 99 MemoryStatus = new DTO.MemoryStatus { 100 TotalMemory = statistic.SlaveStatistics.Sum(x => x.Memory) / 1024, 101 FreeMemory = statistic.SlaveStatistics.Sum(x => x.FreeMemory) / 1024 102 }, 103 Timestamp = JavascriptUtils.ToTimestamp(statistic.Timestamp) 104 }; 141 status.CoreStatus.TotalCores += statistic.SlaveStatistics.Sum(x => x.Cores); 142 freeCores += statistic.SlaveStatistics.Sum(x => x.FreeCores); 143 status.CpuUtilizationStatus.TotalCpuUtilization += statistic.SlaveStatistics.Any() 144 ? statistic.SlaveStatistics.Average(x => x.CpuUtilization) 145 : 0.0; 146 status.MemoryStatus.TotalMemory += statistic.SlaveStatistics.Sum(x => x.Memory) / 1024; 147 freeMemory += statistic.SlaveStatistics.Sum(x => x.FreeMemory) / 1024; 148 if (i >= increment) { 149 status.Timestamp = JavascriptUtils.ToTimestamp(statistic.Timestamp); 150 status.CoreStatus.TotalCores /= i; 151 freeCores /= i; 152 status.CpuUtilizationStatus.TotalCpuUtilization /= i; 153 status.MemoryStatus.TotalMemory /= i; 154 freeMemory /= i; 155 status.CoreStatus.ActiveCores = status.CoreStatus.TotalCores; 156 status.MemoryStatus.ActiveMemory = status.MemoryStatus.TotalMemory; 157 status.CpuUtilizationStatus.ActiveCpuUtilization = status.CpuUtilizationStatus.TotalCpuUtilization; 158 status.CpuUtilizationStatus.CalculatingCpuUtilization = status.CpuUtilizationStatus.CalculatingCpuUtilization; 159 status.CoreStatus.CalculatingCores = status.CoreStatus.TotalCores - freeCores; 160 status.MemoryStatus.UsedMemory = status.MemoryStatus.TotalMemory - freeMemory; 161 yield return status; 162 status = new DTO.Status { 163 CoreStatus = new DTO.CoreStatus(), 164 CpuUtilizationStatus = new DTO.CpuUtilizationStatus(), 165 MemoryStatus = new DTO.MemoryStatus() 166 }; 167 freeCores = 0; 168 freeMemory = 0; 169 i = 1; 170 } else { 171 i++; 172 } 105 173 } 106 174 }
Note: See TracChangeset
for help on using the changeset viewer.