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