[6983] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11171] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6983] | 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;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Web;
|
---|
| 26 | using System.Web.UI;
|
---|
| 27 | using System.Web.UI.WebControls;
|
---|
| 28 | using HeuristicLab.Services.Hive.DataAccess;
|
---|
| 29 | using HeuristicLab.Services.Hive;
|
---|
| 30 | using HeuristicLab.Services.Hive.DataTransfer;
|
---|
| 31 | using System.Text;
|
---|
| 32 | using System.Web.UI.DataVisualization.Charting;
|
---|
| 33 | using DA = HeuristicLab.Services.Hive.DataAccess;
|
---|
[7047] | 34 | using DT = HeuristicLab.Services.Hive.DataTransfer;
|
---|
[6983] | 35 |
|
---|
| 36 | public partial class Status : System.Web.UI.Page {
|
---|
| 37 | protected void Page_Load(object sender, EventArgs e) {
|
---|
| 38 | var dao = ServiceLocator.Instance.HiveDao;
|
---|
[7047] | 39 | var transactionManager = ServiceLocator.Instance.TransactionManager;
|
---|
[6983] | 40 | var resourceName = Request.QueryString["resource"];
|
---|
[7047] | 41 | IEnumerable<Guid> resourceIds = new List<Guid>();
|
---|
| 42 | IEnumerable<DT.Slave> onlineSlaves = new List<DT.Slave>();
|
---|
| 43 | int currentlyJobsWaiting = 0;
|
---|
[9022] | 44 | Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid,int>();
|
---|
| 45 | Dictionary<Guid, int> waitingTasksByUser = new Dictionary<Guid, int>();
|
---|
[9025] | 46 | List<DT.Resource> groups = new List<DT.Resource>();
|
---|
[7047] | 47 |
|
---|
[9025] | 48 | transactionManager.UseTransaction(() => {
|
---|
| 49 | groups = dao.GetResources(x => x.ResourceType == "GROUP").ToList();
|
---|
| 50 | }, false, false);
|
---|
| 51 |
|
---|
[6983] | 52 | if (!string.IsNullOrEmpty(resourceName)) {
|
---|
[7047] | 53 | transactionManager.UseTransaction(() =>
|
---|
| 54 | {
|
---|
| 55 | var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
|
---|
| 56 | resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
|
---|
[9033] | 57 | calculatingTasksByUser = dao.GetCalculatingTasksByUserForResources(resourceIds.ToList());
|
---|
| 58 | waitingTasksByUser = dao.GetWaitingTasksByUserForResources(resourceIds.ToList());
|
---|
[7047] | 59 | }, false, false);
|
---|
[6983] | 60 | } else {
|
---|
[7047] | 61 | transactionManager.UseTransaction(() =>
|
---|
| 62 | {
|
---|
| 63 | resourceIds = dao.GetResources(x => true).Select(y => y.Id);
|
---|
[9033] | 64 | calculatingTasksByUser = dao.GetCalculatingTasksByUser();
|
---|
| 65 | waitingTasksByUser = dao.GetWaitingTasksByUser();
|
---|
[7047] | 66 | }, false, false);
|
---|
| 67 | }
|
---|
[6983] | 68 |
|
---|
[7047] | 69 | transactionManager.UseTransaction(() =>
|
---|
| 70 | {
|
---|
[9033] | 71 | onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
|
---|
| 72 | currentlyJobsWaiting = dao.GetLightweightTasks(x => x.State == DA.TaskState.Waiting).Count();
|
---|
[7047] | 73 | }, false, false);
|
---|
| 74 |
|
---|
[9023] | 75 | int overallCurrentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue).Sum(s => s.Cores.Value);
|
---|
| 76 | int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue && s.IsAllowedToCalculate).Sum(s => s.Cores.Value);
|
---|
| 77 | int currentlyUsedCores = overallCurrentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value);
|
---|
[7047] | 78 |
|
---|
[9023] | 79 | this.overallAvailableCoresLabel.Text = overallCurrentlyAvailableCores.ToString();
|
---|
[6983] | 80 | this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
|
---|
| 81 | this.usedCoresLabel.Text = currentlyUsedCores.ToString();
|
---|
| 82 | this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
|
---|
| 83 |
|
---|
| 84 | slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
|
---|
[9028] | 85 | groupsLabel.Text = "<a href=\"Status.aspx\">All</a>, ";
|
---|
| 86 | groupsLabel.Text += string.Join(", ", groups.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a>", x.Name)));
|
---|
[6983] | 87 |
|
---|
[9023] | 88 | overallCpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
|
---|
[9025] | 89 | cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 && onlineSlaves.Where(x => x.IsAllowedToCalculate).Count() > 0 ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
|
---|
[6983] | 90 |
|
---|
[7047] | 91 | DT.Statistics[] stats = new DT.Statistics[0];
|
---|
| 92 | transactionManager.UseTransaction(() =>
|
---|
| 93 | {
|
---|
| 94 | if (daysDropDownList.SelectedValue == "All") {
|
---|
| 95 | stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
|
---|
| 96 | } else {
|
---|
| 97 | stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
|
---|
| 98 | }
|
---|
| 99 | }, false, false);
|
---|
[6983] | 100 |
|
---|
| 101 | for (int i = 0; i < stats.Length; i++) {
|
---|
| 102 | var s = stats[i];
|
---|
| 103 | var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
|
---|
| 104 |
|
---|
| 105 | var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
|
---|
| 106 | cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
|
---|
| 107 |
|
---|
| 108 | var cores = slaveStats.Sum(x => x.Cores);
|
---|
| 109 |
|
---|
| 110 | var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
|
---|
| 111 | coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
|
---|
| 112 | coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
|
---|
| 113 |
|
---|
| 114 | var memory = slaveStats.Sum(x => x.Memory);
|
---|
| 115 | var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
|
---|
| 116 | memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
|
---|
| 117 | memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
|
---|
| 118 | }
|
---|
[9022] | 119 |
|
---|
[9033] | 120 | GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable);
|
---|
| 121 | GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable);
|
---|
| 122 | }
|
---|
[9022] | 123 |
|
---|
[9033] | 124 | private void GenerateTasksByUserTable(Dictionary<Guid, int> tasksByUser, Table table) {
|
---|
| 125 | foreach (var kvp in tasksByUser) {
|
---|
[9022] | 126 | TableRow curRow = new TableRow();
|
---|
| 127 | TableCell cellUser = new TableCell();
|
---|
| 128 | cellUser.Text = ServiceLocator.Instance.UserManager.GetUserById(kvp.Key).UserName;
|
---|
| 129 | TableCell cellCnt = new TableCell();
|
---|
| 130 | cellCnt.Text = kvp.Value.ToString();
|
---|
| 131 |
|
---|
| 132 | curRow.Cells.Add(cellUser);
|
---|
| 133 | curRow.Cells.Add(cellCnt);
|
---|
[9033] | 134 | table.Rows.Add(curRow);
|
---|
[9022] | 135 | }
|
---|
[9033] | 136 | if (tasksByUser.Count() > 0) {
|
---|
| 137 | TableRow sumRow = new TableRow();
|
---|
| 138 | TableCell sumCell = new TableCell();
|
---|
| 139 | sumCell.BorderWidth = Unit.Pixel(3);
|
---|
| 140 | sumCell.Text = tasksByUser.Sum(x => x.Value).ToString();
|
---|
| 141 | sumRow.Cells.Add(new TableCell());
|
---|
| 142 | sumRow.Cells.Add(sumCell);
|
---|
| 143 | table.Rows.Add(sumRow);
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
[6983] | 146 | } |
---|