Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/Status.aspx.cs @ 6712

Last change on this file since 6712 was 6712, checked in by ascheibe, 13 years ago

#1233

  • got db scripts up-to-date
  • renamed db related stuff back to 3.3
  • fixed a bug in the Status page that occured when the db is empty
File size: 5.2 KB
RevLine 
[6457]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.UI;
6using System.Web.UI.WebControls;
7using HeuristicLab.Services.Hive.DataAccess;
8using HeuristicLab.Services.Hive;
9using HeuristicLab.Services.Hive.Common.DataTransfer;
10using System.Text;
[6458]11using System.Web.UI.DataVisualization.Charting;
[6457]12
13public partial class Status : System.Web.UI.Page {
14  protected void Page_Load(object sender, EventArgs e) {
15    var dao = ServiceLocator.Instance.HiveDao;
[6478]16    var resourceName = Request.QueryString["resource"];
17    IEnumerable<Guid> resourceIds;
18    if (!string.IsNullOrEmpty(resourceName)) {
19      var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
20      resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
21      speedupChartHours.Visible = false;
22      speedupChartMinutes.Visible = false;
23    } else {
24      resourceIds = dao.GetResources(x => true).Select(y => y.Id);
25      speedupChartHours.Visible = true;
26      speedupChartMinutes.Visible = true;
27    }
[6457]28
[6478]29    var onlineSlaves = dao.GetSlaves(x => (x.SlaveState == SlaveState.Calculating || x.SlaveState == SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
30
[6458]31    int currentlyAvailableCores = onlineSlaves.Sum(s => s.Cores.Value);
32    int currentlyUsedCores = currentlyAvailableCores - onlineSlaves.Sum(s => s.FreeCores.Value);
33    int currentlyJobsWaiting = ServiceLocator.Instance.HiveDao.GetJobs(x => x.State == JobState.Waiting).Count();
[6457]34
[6458]35    this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
36    this.usedCoresLabel.Text = currentlyUsedCores.ToString();
37    this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
[6457]38
[6478]39    slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
[6457]40
[6469]41    cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
[6458]42
43    HeuristicLab.Services.Hive.Common.DataTransfer.Statistics[] stats;
44    if (daysDropDownList.SelectedValue == "All")
[6478]45      stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
[6458]46    else
[6478]47      stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
[6458]48
[6469]49    var firstStatisticsDate = DateTime.Parse("2011-05-24 17:16:40");
50    var statisticsSince = DateTime.Now - firstStatisticsDate;
[6712]51    if (stats.Length != 0) {
52      totalExecutionTimeLabel.Text = new TimeSpan(stats.Last().UserStatistics.Sum(x => x.ExecutionTime.Ticks)).ToString() + " (since " + Math.Round(statisticsSince.TotalDays, 2) + " days)";
53    } else {
54      totalExecutionTimeLabel.Text = "00:00:00.00";
55    }
[6478]56   
[6458]57    for (int i = 0; i < stats.Length; i++) {
58      var s = stats[i];
[6478]59      var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
[6458]60
[6478]61      var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
[6458]62      cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
63
[6478]64      var cores = slaveStats.Sum(x => x.Cores);
[6458]65
[6478]66      var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
[6458]67      coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
68      coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
69
[6478]70      var memory = slaveStats.Sum(x => x.Memory);
71      var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
72      memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
73      memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
[6458]74
75      if (i > 0) {
[6457]76        var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
[6458]77        var execTimePrev = new TimeSpan(stats[i - 1].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
78        var execTimeDifference = execTimePrev - execTime;
79
80        var timeDifference = stats[i - 1].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
81        var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
82        speedupChartMinutes.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
[6478]83        speedupChartMinutes.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
[6457]84      }
[6458]85      if (i - 60 >= 0) {
86        var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
87        var execTimePrev = new TimeSpan(stats[i - 60].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
88        var execTimeDifference = execTimePrev - execTime;
89
90        var timeDifference = stats[i - 60].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
91        var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
92        speedupChartHours.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
[6478]93        speedupChartHours.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
[6458]94      }
[6457]95    }
96  }
[6458]97
98  protected void daysDropDownList_SelectedIndexChanged(object sender, EventArgs e) {
99
100  }
[6457]101}
Note: See TracBrowser for help on using the repository browser.