source: branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/HomeController.cs @ 9625

Last change on this file since 9625 was 9625, checked in by pfleck, 7 years ago

#2063:
Insert charts on index page for CPU utilization, cores and memory usage.
Added html helper for generating chart javascript.
Added ChartDataController for generating JSON data for the charts.

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Linq;
24using System.Web.Mvc;
25using HeuristicLab.Services.Hive.DataAccess;
26using HeuristicLab.Services.Hive.Statistics.Models;
27
28namespace HeuristicLab.Services.Hive.Statistics.Controllers {
29  public class HomeController : Controller {
30    public ActionResult Index() {
31      OverallStatus result = null;
32
33      using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) {
34        var onlineSlaves = (from slave in db.Resources.OfType<Slave>()
35                            where slave.SlaveState == SlaveState.Calculating || slave.SlaveState == SlaveState.Idle
36                            select slave)
37                           .ToList();
38
39        result = new OverallStatus {
40          OverallCurrentlyAvailableCores = onlineSlaves.Sum(s => s.Cores ?? 0),
41          CurrentlyAvailableCores = onlineSlaves.Where(s => s.IsAllowedToCalculate).Sum(s => s.Cores ?? 0),
42          CurrentlyUsedCores = onlineSlaves.Sum(s => s.Cores ?? 0) - onlineSlaves.Sum(s => s.FreeCores ?? 0),
43          CurrentlyJobsWaiting = db.Tasks.Count(x => x.State == TaskState.Waiting),
44          OverallCpuUtilization = onlineSlaves.Any()
45                                  ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2)
46                                  : 0.0,
47          AvailableCpuUtilization = onlineSlaves.Any(x => x.IsAllowedToCalculate)
48                                    ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2)
49                                    : 0.0
50        };
51      }
52
53      return View(result);
54    }
55
56    public ActionResult About() {
57      ViewBag.Message = "Your app description page.";
58
59      return View();
60    }
61
62    public ActionResult Contact() {
63      ViewBag.Message = "Your contact page.";
64
65      return View();
66    }
67
68    public ActionResult Error() {
69      throw new Exception();
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.