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.

Location:
trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi
Files:
5 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      }
  • trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataTransfer/Slave.cs

    r12428 r12435  
    1 namespace HeuristicLab.Services.WebApp.Status.WebApi.DataTransfer {
     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
     22namespace HeuristicLab.Services.WebApp.Status.WebApi.DataTransfer {
    223  public class Slave {
    324    public string Id { get; set; } // currently unused
  • trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataTransfer/Status.cs

    r12428 r12435  
    1 using System.Collections.Generic;
     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.Collections.Generic;
    223
    324namespace HeuristicLab.Services.WebApp.Status.WebApi.DataTransfer {
     
    526  public class CoreStatus {
    627    public int TotalCores { get; set; }
    7     public int AvailableCores { get; set; }
    8     public int FreeCores { get; set; }
     28    public int FreeCores { get; set; } // temporary quickfix for old chart data
     29    public int ActiveCores { get; set; }
     30    public int CalculatingCores { get; set; }
    931  }
    1032
    1133  public class CpuUtilizationStatus {
    1234    public double TotalCpuUtilization { get; set; }
    13     public double UsedCpuUtilization { get; set; }
     35    public double ActiveCpuUtilization { get; set; }
     36    public double CalculatingCpuUtilization { get; set; }
    1437  }
    1538
    1639  public class MemoryStatus {
    1740    public int TotalMemory { get; set; }
    18     public int FreeMemory { get; set; }
     41    public int FreeMemory { get; set; } // temporary quickfix for old chart data
     42    public int ActiveMemory { get; set; }
     43    public int UsedMemory { get; set; }
    1944  }
    2045
     
    2550  }
    2651
    27   public class SlaveCpuStatus {
     52  public class SlaveStatus {
    2853    public Slave Slave { get; set; }
    2954    public double CpuUtilization { get; set; }
     55    public int Cores { get; set; }
     56    public int FreeCores { get; set; }
     57    public int Memory { get; set; }
     58    public int FreeMemory { get; set; }
     59    public bool IsAllowedToCalculate { get; set; }
     60    public string State { get; set; }
    3061  }
    3162
     
    3566    public MemoryStatus MemoryStatus { get; set; }
    3667    public IEnumerable<TaskStatus> TasksStatus { get; set; }
    37     public IEnumerable<SlaveCpuStatus> SlavesCpuStatus { get; set; }
     68    public IEnumerable<SlaveStatus> SlavesStatus { get; set; }
    3869    public long Timestamp { get; set; }
    3970  }
  • trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataTransfer/User.cs

    r12428 r12435  
    1 
     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
    222namespace HeuristicLab.Services.WebApp.Status.WebApi.DataTransfer {
    323  public class User {
  • trunk/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/JavascriptUtils.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;
    223
    324namespace HeuristicLab.Services.WebApp.Status.WebApi {
     
    627      var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    728      var time = input.Subtract(new TimeSpan(epoch.Ticks));
    8       return (long)(time.Ticks / 10000);
     29      return time.Ticks / 10000;
    930    }
    1031  }
Note: See TracChangeset for help on using the changeset viewer.