Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Hive.WebRole/Status.aspx.cs @ 14877

Last change on this file since 14877 was 8266, checked in by spimming, 12 years ago

#1888:

  • disabled some transactions since dtc is not supported in sql azure
  • settings in dataaccess updated
File size: 3.8 KB
RevLine 
[8235]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web.UI.DataVisualization.Charting;
5using DA = HeuristicLab.Services.Hive.DataAccess;
6using DT = HeuristicLab.Services.Hive.DataTransfer;
7
8namespace HeuristicLab.Services.Hive.WebRole {
9  public partial class Status : System.Web.UI.Page {
10    protected void Page_Load(object sender, EventArgs e) {
11      var dao = ServiceLocator.Instance.HiveDao;
12      var transactionManager = ServiceLocator.Instance.TransactionManager;
13      var resourceName = Request.QueryString["resource"];
14      IEnumerable<Guid> resourceIds = new List<Guid>();
15      IEnumerable<DT.Slave> onlineSlaves = new List<DT.Slave>();
16      int currentlyJobsWaiting = 0;
17
18      if (!string.IsNullOrEmpty(resourceName)) {
19        transactionManager.UseTransaction(() => {
20          var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
21          resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
22        }, false, false);
23      } else {
24        transactionManager.UseTransaction(() => {
25          resourceIds = dao.GetResources(x => true).Select(y => y.Id);
26        }, false, false);
27      }
28
29      transactionManager.UseTransaction(() => {
30        onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
[8266]31      }, false, false);
32      transactionManager.UseTransaction(() => {
[8235]33        currentlyJobsWaiting = dao.GetTasks(x => x.State == DA.TaskState.Waiting).Count();
34      }, false, false);
35
36      int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue).Sum(s => s.Cores.Value);
37      int currentlyUsedCores = currentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value);
38
39      this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
40      this.usedCoresLabel.Text = currentlyUsedCores.ToString();
41      this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
42
43      slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
44
45      cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
46
47      DT.Statistics[] stats = new DT.Statistics[0];
48      transactionManager.UseTransaction(() => {
49        if (daysDropDownList.SelectedValue == "All") {
50          stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
51        } else {
52          stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
53        }
54      }, false, false);
55
56      for (int i = 0; i < stats.Length; i++) {
57        var s = stats[i];
58        var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
59
60        var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
61        cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
62
63        var cores = slaveStats.Sum(x => x.Cores);
64
65        var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
66        coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
67        coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
68
69        var memory = slaveStats.Sum(x => x.Memory);
70        var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
71        memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
72        memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
73      }
74
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.