Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/15 18:02:03 (9 years ago)
Author:
dglaser
Message:

#2388:

HeuristicLab.Services.WebApp.Statistics-3.3:

  • added groups page
  • improved jobs, clients and users pages

HeuristicLab.Services.WebApp-3.3:

  • merged from trunk
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/ClientController.cs

    r12516 r12525  
    8686                    State = clientInfo.SlaveState.ToString(),
    8787                    LastUpdate = clientInfo.Time,
     88                    GroupId = client.ResourceGroupId,
     89                    GroupName = client.GroupName,
    8890                    UpTime = offline ? 0 : upTime,
    8991                    TotalUnavailableTime = timeData != null ? timeData.TotalUnavailableTime : 0,
     
    124126                         CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
    125127                         State = clientInfo.SlaveState.ToString(),
     128                         GroupId = client.ResourceGroupId,
     129                         GroupName = client.GroupName
    126130                       });
    127131          return new DT.ClientPage {
     
    186190    }
    187191
     192    public DT.ClientPage GetClientsByGroupId(Guid id, int page, int size, bool expired = false) {
     193      using (var pm = PersistenceManager) {
     194        var dimClientDao = pm.DimClientDao;
     195        var factClientInfoDao = pm.FactClientInfoDao;
     196        return pm.UseTransaction(() => {
     197          var clients = expired ? dimClientDao.GetExpiredClients() : dimClientDao.GetActiveClients();
     198          clients = clients.Where(x => x.ResourceGroupId == id);
     199          var query = (from client in clients
     200                       join info in factClientInfoDao.GetAll()
     201                         on client.Id equals info.ClientId into clientInfoJoin
     202                       from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1)
     203                       let offline = (expired || clientInfo.SlaveState == SlaveState.Offline)
     204                       select new DT.Client {
     205                         Id = client.Id,
     206                         Name = client.Name,
     207                         TotalCores = clientInfo.NumTotalCores,
     208                         UsedCores = offline ? 0 : clientInfo.NumUsedCores,
     209                         TotalMemory = clientInfo.TotalMemory,
     210                         UsedMemory = offline ? 0 : clientInfo.UsedMemory,
     211                         CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
     212                         State = clientInfo.SlaveState.ToString(),
     213                         GroupId = client.ResourceGroupId,
     214                         GroupName = client.GroupName
     215                       });
     216          return new DT.ClientPage {
     217            TotalClients = query.Count(),
     218            Clients = query.Skip((page - 1) * size)
     219              .Take(size)
     220              .ToList()
     221          };
     222        });
     223      }
     224    }
     225
     226    public IEnumerable<DT.ClientStatus> GetClientHistoryByGroupId(Guid id, DateTime start, DateTime end) {
     227      TimeSpan ts = end - start;
     228      int increment = 1;
     229      double totalMinutes = ts.TotalMinutes;
     230      while (totalMinutes > 5761) {
     231        totalMinutes -= 5761;
     232        increment += 5;
     233      }
     234      using (var pm = PersistenceManager) {
     235        var factClientInfo = pm.FactClientInfoDao;
     236        var dimClientDao = pm.DimClientDao;
     237        var clientInfos = factClientInfo.GetAll()
     238          .Where(x => x.Time >= start && x.Time <= end)
     239          .OrderBy(x => x.Time)
     240          .Join(dimClientDao.GetAll(),
     241            fact => fact.ClientId,
     242            client => client.Id,
     243            (fact, client) => new {
     244              client.ResourceGroupId,
     245              fact.Time,
     246              fact.CpuUtilization,
     247              fact.NumTotalCores,
     248              fact.NumUsedCores,
     249              fact.TotalMemory,
     250              fact.UsedMemory
     251            })
     252          .Where(x => x.ResourceGroupId == id)
     253          .ToList();
     254        var clientStatus = new DT.ClientStatus {
     255          CpuUtilization = 0,
     256          TotalCores = 0,
     257          UsedCores = 0,
     258          TotalMemory = 0,
     259          UsedMemory = 0
     260        };
     261        int i = 1;
     262        foreach (var clientInfo in clientInfos) {
     263          clientStatus.CpuUtilization += clientInfo.CpuUtilization;
     264          clientStatus.TotalCores += clientInfo.NumTotalCores;
     265          clientStatus.UsedCores += clientInfo.NumUsedCores;
     266          clientStatus.TotalMemory += clientInfo.TotalMemory;
     267          clientStatus.UsedMemory += clientInfo.UsedMemory;
     268          if (i >= increment) {
     269            clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time);
     270            clientStatus.CpuUtilization /= i;
     271            clientStatus.TotalCores /= i;
     272            clientStatus.UsedCores /= i;
     273            clientStatus.TotalMemory /= i;
     274            clientStatus.UsedMemory /= i;
     275            yield return clientStatus;
     276            clientStatus = new DT.ClientStatus {
     277              CpuUtilization = 0,
     278              TotalCores = 0,
     279              UsedCores = 0,
     280              TotalMemory = 0,
     281              UsedMemory = 0
     282            };
     283            i = 1;
     284          } else {
     285            ++i;
     286          }
     287        }
     288      }
     289    }
    188290  }
    189291}
Note: See TracChangeset for help on using the changeset viewer.