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