[6983] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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;
|
---|
| 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;
|
---|
| 44 |
|
---|
[6983] | 45 | if (!string.IsNullOrEmpty(resourceName)) {
|
---|
[7047] | 46 | transactionManager.UseTransaction(() =>
|
---|
| 47 | {
|
---|
| 48 | var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
|
---|
| 49 | resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
|
---|
| 50 | }, false, false);
|
---|
[6983] | 51 | } else {
|
---|
[7047] | 52 | transactionManager.UseTransaction(() =>
|
---|
| 53 | {
|
---|
| 54 | resourceIds = dao.GetResources(x => true).Select(y => y.Id);
|
---|
| 55 | }, false, false);
|
---|
| 56 | }
|
---|
[6983] | 57 |
|
---|
[7047] | 58 | transactionManager.UseTransaction(() =>
|
---|
| 59 | {
|
---|
| 60 | onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
|
---|
| 61 | currentlyJobsWaiting = dao.GetTasks(x => x.State == DA.TaskState.Waiting).Count();
|
---|
| 62 | }, false, false);
|
---|
| 63 |
|
---|
[6983] | 64 | int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue).Sum(s => s.Cores.Value);
|
---|
| 65 | int currentlyUsedCores = currentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value);
|
---|
[7047] | 66 |
|
---|
[6983] | 67 | this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
|
---|
| 68 | this.usedCoresLabel.Text = currentlyUsedCores.ToString();
|
---|
| 69 | this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
|
---|
| 70 |
|
---|
| 71 | slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
|
---|
| 72 |
|
---|
| 73 | cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
|
---|
| 74 |
|
---|
[7047] | 75 | DT.Statistics[] stats = new DT.Statistics[0];
|
---|
| 76 | transactionManager.UseTransaction(() =>
|
---|
| 77 | {
|
---|
| 78 | if (daysDropDownList.SelectedValue == "All") {
|
---|
| 79 | stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
|
---|
| 80 | } else {
|
---|
| 81 | stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
|
---|
| 82 | }
|
---|
| 83 | }, false, false);
|
---|
[6983] | 84 |
|
---|
| 85 | for (int i = 0; i < stats.Length; i++) {
|
---|
| 86 | var s = stats[i];
|
---|
| 87 | var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
|
---|
| 88 |
|
---|
| 89 | var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
|
---|
| 90 | cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
|
---|
| 91 |
|
---|
| 92 | var cores = slaveStats.Sum(x => x.Cores);
|
---|
| 93 |
|
---|
| 94 | var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
|
---|
| 95 | coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
|
---|
| 96 | coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
|
---|
| 97 |
|
---|
| 98 | var memory = slaveStats.Sum(x => x.Memory);
|
---|
| 99 | var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
|
---|
| 100 | memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
|
---|
| 101 | memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | } |
---|