1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.UI;
|
---|
6 | using System.Web.UI.WebControls;
|
---|
7 | using HeuristicLab.Services.Hive.DataAccess;
|
---|
8 | using HeuristicLab.Services.Hive;
|
---|
9 | using HeuristicLab.Services.Hive.Common.DataTransfer;
|
---|
10 | using System.Text;
|
---|
11 | using System.Web.UI.DataVisualization.Charting;
|
---|
12 |
|
---|
13 | public partial class Status : System.Web.UI.Page {
|
---|
14 | protected void Page_Load(object sender, EventArgs e) {
|
---|
15 | var dao = ServiceLocator.Instance.HiveDao;
|
---|
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 | }
|
---|
28 |
|
---|
29 | var onlineSlaves = dao.GetSlaves(x => (x.SlaveState == SlaveState.Calculating || x.SlaveState == SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
|
---|
30 |
|
---|
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();
|
---|
34 |
|
---|
35 | this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
|
---|
36 | this.usedCoresLabel.Text = currentlyUsedCores.ToString();
|
---|
37 | this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
|
---|
38 |
|
---|
39 | slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
|
---|
40 |
|
---|
41 | cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
|
---|
42 |
|
---|
43 | HeuristicLab.Services.Hive.Common.DataTransfer.Statistics[] stats;
|
---|
44 | if (daysDropDownList.SelectedValue == "All")
|
---|
45 | stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
|
---|
46 | else
|
---|
47 | stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
|
---|
48 |
|
---|
49 | var firstStatisticsDate = DateTime.Parse("2011-05-24 17:16:40");
|
---|
50 | var statisticsSince = DateTime.Now - firstStatisticsDate;
|
---|
51 | totalExecutionTimeLabel.Text = new TimeSpan(stats.Last().UserStatistics.Sum(x => x.ExecutionTime.Ticks)).ToString() + " (since " + Math.Round(statisticsSince.TotalDays, 2) + " days)";
|
---|
52 |
|
---|
53 | for (int i = 0; i < stats.Length; i++) {
|
---|
54 | var s = stats[i];
|
---|
55 | var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
|
---|
56 |
|
---|
57 | var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
|
---|
58 | cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
|
---|
59 |
|
---|
60 | var cores = slaveStats.Sum(x => x.Cores);
|
---|
61 |
|
---|
62 | var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
|
---|
63 | coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
|
---|
64 | coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
|
---|
65 |
|
---|
66 | var memory = slaveStats.Sum(x => x.Memory);
|
---|
67 | var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
|
---|
68 | memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
|
---|
69 | memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
|
---|
70 |
|
---|
71 | if (i > 0) {
|
---|
72 | var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
|
---|
73 | var execTimePrev = new TimeSpan(stats[i - 1].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
|
---|
74 | var execTimeDifference = execTimePrev - execTime;
|
---|
75 |
|
---|
76 | var timeDifference = stats[i - 1].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
|
---|
77 | var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
|
---|
78 | speedupChartMinutes.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
|
---|
79 | speedupChartMinutes.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
|
---|
80 | }
|
---|
81 | if (i - 60 >= 0) {
|
---|
82 | var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
|
---|
83 | var execTimePrev = new TimeSpan(stats[i - 60].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
|
---|
84 | var execTimeDifference = execTimePrev - execTime;
|
---|
85 |
|
---|
86 | var timeDifference = stats[i - 60].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
|
---|
87 | var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
|
---|
88 | speedupChartHours.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
|
---|
89 | speedupChartHours.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected void daysDropDownList_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
95 |
|
---|
96 | }
|
---|
97 | } |
---|