Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9628 was 9628, checked in by pfleck, 11 years ago

#2063:
Added zooming in charts.
Used memory is displayed in GB.

File size: 2.7 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      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}
Note: See TracBrowser for help on using the repository browser.