Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/12/15 14:59:54 (9 years ago)
Author:
dglaser
Message:

#2394: Improved PluginManager and updated hive status monitor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataController.cs

    r12428 r12435  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 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;
    223using System.Collections.Generic;
    324using System.Linq;
     
    2142        SELECT
    2243          DISTINCT UserId,
    23           ISNULL((SELECT Count FROM UserTasks WHERE TaskState = 'Calculating' AND UserId = ut.UserId), 0) AS CalculatingTasks,
    24           ISNULL((SELECT Count FROM UserTasks WHERE TaskState = 'Waiting' AND UserId = ut.UserId), 0) AS WaitingTasks
     44          (SELECT Count FROM UserTasks WHERE TaskState = 'Calculating' AND UserId = ut.UserId) AS CalculatingTasks,
     45          (SELECT Count FROM UserTasks WHERE TaskState = 'Waiting' AND UserId = ut.UserId) AS WaitingTasks
    2546        FROM UserTasks ut;";
    2647
     
    4162        CalculatingTasks = uts.CalculatingTasks,
    4263        WaitingTasks = uts.WaitingTasks
    43       });
     64      }).OrderBy(x => x.User.Name);
    4465    }
    4566    // end temporary quickfix
     
    5071                            where slave.SlaveState == SlaveState.Calculating || slave.SlaveState == SlaveState.Idle
    5172                            select slave).ToList();
     73        var activeSlaves = onlineSlaves.Where(s => s.IsAllowedToCalculate).ToList();
     74        var calculatingSlaves = activeSlaves.Where(s => s.SlaveState == SlaveState.Calculating).ToList();
     75
     76        int calculatingMemory = calculatingSlaves.Any() ? (int)calculatingSlaves.Sum(s => s.Memory) / 1024 : 0;
     77        int freeCalculatingMemory = calculatingSlaves.Any() ? (int)calculatingSlaves.Sum(s => s.FreeMemory) / 1024 : 0;
     78
    5279        return new DTO.Status {
    5380          CoreStatus = new DTO.CoreStatus {
    5481            TotalCores = onlineSlaves.Sum(s => s.Cores ?? 0),
    55             AvailableCores = onlineSlaves.Where(s => s.IsAllowedToCalculate).Sum(s => s.Cores ?? 0),
    56             FreeCores = onlineSlaves.Sum(s => s.FreeCores ?? 0)
     82            FreeCores = onlineSlaves.Sum(s => s.FreeCores ?? 0), // temporary for old chart data
     83            ActiveCores = activeSlaves.Sum(s => s.Cores ?? 0),
     84            CalculatingCores = calculatingSlaves.Sum(s => s.Cores ?? 0)
    5785          },
    5886          CpuUtilizationStatus = new DTO.CpuUtilizationStatus {
     
    6088                                  ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2)
    6189                                  : 0.0,
    62             UsedCpuUtilization = onlineSlaves.Any(x => x.IsAllowedToCalculate)
    63                                  ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2)
    64                                  : 0.0
     90            ActiveCpuUtilization = activeSlaves.Any()
     91                                   ? Math.Round(activeSlaves.Average(s => s.CpuUtilization), 2)
     92                                   : 0.0,
     93            CalculatingCpuUtilization = calculatingSlaves.Any()
     94                                        ? Math.Round(calculatingSlaves.Average(s => s.CpuUtilization), 2)
     95                                        : 0.0
    6596          },
    6697          MemoryStatus = new DTO.MemoryStatus {
    6798            TotalMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.Memory) / 1024 : 0,
    68             FreeMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.FreeMemory) / 1024 : 0
     99            FreeMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.FreeMemory) / 1024 : 0,
     100            ActiveMemory = activeSlaves.Any() ? (int)activeSlaves.Sum(s => s.Memory) / 1024 : 0,
     101            UsedMemory = calculatingMemory - freeCalculatingMemory
    69102          },
    70103          TasksStatus = GetTaskStatus(db),
    71           SlavesCpuStatus = onlineSlaves.Select(x => new DTO.SlaveCpuStatus {
    72             CpuUtilization = Math.Round(x.CpuUtilization, 2),
     104          SlavesStatus = onlineSlaves.Select(x => new DTO.SlaveStatus {
    73105            Slave = new DTO.Slave {
    74106              Id = x.ResourceId.ToString(),
    75107              Name = x.Name
    76             }
    77           }),
     108            },
     109            CpuUtilization = x.CpuUtilization,
     110            Cores = x.Cores ?? 0,
     111            FreeCores = x.FreeCores ?? 0,
     112            Memory = (x.Memory ?? 0) / 1024,
     113            FreeMemory = (x.FreeMemory ?? 0) / 1024,
     114            IsAllowedToCalculate = x.IsAllowedToCalculate,
     115            State = x.SlaveState.ToString()
     116          }).OrderBy(x => x.Slave.Name),
    78117          Timestamp = JavascriptUtils.ToTimestamp(DateTime.Now)
    79118        };
     
    82121
    83122    public IEnumerable<DTO.Status> GetStatusHistory(DateTime start, DateTime end) {
     123      TimeSpan ts = end - start;
     124      int increment = 1;
     125      double totalMinutes = ts.TotalMinutes;
     126      while (totalMinutes > 5761) {
     127        totalMinutes -= 5761;
     128        increment += 5;
     129      }
    84130      using (var db = new HiveDataContext()) {
    85         var statistics = db.Statistics.Where(s => s.Timestamp >= start && s.Timestamp <= end)
    86                                       .OrderBy(x => x.Timestamp)
    87                                       .ToList();
     131        var statistics = db.Statistics.Where(s => s.Timestamp >= start && s.Timestamp <= end);
     132        var status = new DTO.Status {
     133          CoreStatus = new DTO.CoreStatus(),
     134          CpuUtilizationStatus = new DTO.CpuUtilizationStatus(),
     135          MemoryStatus = new DTO.MemoryStatus()
     136        };
     137        int freeCores = 0;
     138        int freeMemory = 0;
     139        int i = 1;
    88140        foreach (var statistic in statistics) {
    89           yield return new DTO.Status {
    90             CoreStatus = new DTO.CoreStatus {
    91               TotalCores = statistic.SlaveStatistics.Sum(x => x.Cores),
    92               AvailableCores = 0,
    93               FreeCores = statistic.SlaveStatistics.Sum(x => x.FreeCores)
    94             },
    95             CpuUtilizationStatus = new DTO.CpuUtilizationStatus {
    96               TotalCpuUtilization = 0.0,
    97               UsedCpuUtilization = statistic.SlaveStatistics.Any() ? statistic.SlaveStatistics.Average(x => x.CpuUtilization) : 0.0
    98             },
    99             MemoryStatus = new DTO.MemoryStatus {
    100               TotalMemory = statistic.SlaveStatistics.Sum(x => x.Memory) / 1024,
    101               FreeMemory = statistic.SlaveStatistics.Sum(x => x.FreeMemory) / 1024
    102             },
    103             Timestamp = JavascriptUtils.ToTimestamp(statistic.Timestamp)
    104           };
     141          status.CoreStatus.TotalCores += statistic.SlaveStatistics.Sum(x => x.Cores);
     142          freeCores += statistic.SlaveStatistics.Sum(x => x.FreeCores);
     143          status.CpuUtilizationStatus.TotalCpuUtilization += statistic.SlaveStatistics.Any()
     144                                                             ? statistic.SlaveStatistics.Average(x => x.CpuUtilization)
     145                                                             : 0.0;
     146          status.MemoryStatus.TotalMemory += statistic.SlaveStatistics.Sum(x => x.Memory) / 1024;
     147          freeMemory += statistic.SlaveStatistics.Sum(x => x.FreeMemory) / 1024;
     148          if (i >= increment) {
     149            status.Timestamp = JavascriptUtils.ToTimestamp(statistic.Timestamp);
     150            status.CoreStatus.TotalCores /= i;
     151            freeCores /= i;
     152            status.CpuUtilizationStatus.TotalCpuUtilization /= i;
     153            status.MemoryStatus.TotalMemory /= i;
     154            freeMemory /= i;
     155            status.CoreStatus.ActiveCores = status.CoreStatus.TotalCores;
     156            status.MemoryStatus.ActiveMemory = status.MemoryStatus.TotalMemory;
     157            status.CpuUtilizationStatus.ActiveCpuUtilization = status.CpuUtilizationStatus.TotalCpuUtilization;
     158            status.CpuUtilizationStatus.CalculatingCpuUtilization = status.CpuUtilizationStatus.CalculatingCpuUtilization;
     159            status.CoreStatus.CalculatingCores = status.CoreStatus.TotalCores - freeCores;
     160            status.MemoryStatus.UsedMemory = status.MemoryStatus.TotalMemory - freeMemory;
     161            yield return status;
     162            status = new DTO.Status {
     163              CoreStatus = new DTO.CoreStatus(),
     164              CpuUtilizationStatus = new DTO.CpuUtilizationStatus(),
     165              MemoryStatus = new DTO.MemoryStatus()
     166            };
     167            freeCores = 0;
     168            freeMemory = 0;
     169            i = 1;
     170          } else {
     171            i++;
     172          }
    105173        }
    106174      }
Note: See TracChangeset for help on using the changeset viewer.