public DiskSize GetSize() { DiskSize disksize = new DiskSize(); long totallength = 0; foreach (var item in this.AllRepositories) { RepoSize reposize = new RepoSize(); reposize.Name = item.StoreName; string folder = item.Store.ObjectFolder; reposize.Length = IOHelper.GetDirectorySize(folder); reposize.ItemCount = item.Store.Count(); disksize.RepositorySize.Add(reposize); totallength += reposize.Length; } disksize.RepositoryEditCount = this.Log.Store.Count(); //disksize.ImageLogWeeks = this.GetLogWeekNames(LogType.Image); disksize.VisitorLogWeeks = this.LogWeekNames(); //disksize.ImageLog = IOHelper.GetDirectorySize(this.LogFolder); disksize.VisitorLog = IOHelper.GetDirectorySize(this.LogFolder); long editlogsize = IOHelper.GetDirectorySize(this.Log.Store.ObjectFolder); totallength += disksize.VisitorLog; totallength += editlogsize; disksize.Total = totallength; return(disksize); }
public override int GetHashCode() { int hash = 1; if (Id.Length != 0) { hash ^= Id.GetHashCode(); } if (FolderId.Length != 0) { hash ^= FolderId.GetHashCode(); } if (createdAt_ != null) { hash ^= CreatedAt.GetHashCode(); } if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (Description.Length != 0) { hash ^= Description.GetHashCode(); } hash ^= Labels.GetHashCode(); if (StorageSize != 0L) { hash ^= StorageSize.GetHashCode(); } if (DiskSize != 0L) { hash ^= DiskSize.GetHashCode(); } hash ^= productIds_.GetHashCode(); if (Status != global::Yandex.Cloud.Compute.V1.Snapshot.Types.Status.Unspecified) { hash ^= Status.GetHashCode(); } if (SourceDiskId.Length != 0) { hash ^= SourceDiskId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public async Task NotifyAsync( TriggerMode mode, DriveInfo driveInfo, MeasurementUnit unit, double thresholdValueInBytes, string machineName, CancellationToken token) { if (!IsEnabled) { return; } var diskSize = new DiskSize(driveInfo.AvailableFreeSpace); diskSize = diskSize.ConvertTo(unit); var messageBody = mode == TriggerMode.Accuracy ? $"Available - <b>{diskSize}</b>, limit - <b>{new DiskSize(thresholdValueInBytes).ConvertTo(unit)}</b>" : $"Available - <b>{Math.Round((double)driveInfo.AvailableFreeSpace/driveInfo.TotalSize*100, 2)}%</b>, limit - <b>{thresholdValueInBytes*100}%</b>"; var message = "<p><b>Warning</b> </p>" + $"<p>Not enough free space for drive <b>{driveInfo.Name}</b>. </p>" + $"<p>{messageBody}</p>" + $"<p>Machine name - <b>{machineName}</b></p>"; foreach (var emailAddress in _emails) { var email = Email .From(_config.Email) .To(emailAddress) .Subject($"Alert triggered on machine {machineName}") .Body(message, true); var response = await email.SendAsync(token); if (!response.Successful) { foreach (var responseErrorMessage in response.ErrorMessages) { _logger.LogWarning($"Error on sending email to {emailAddress}. " + $"Error message: {responseErrorMessage}"); } } else { _logger.LogInformation($"Email successfully sent to {emailAddress}"); } } }
/// <summary> /// /// </summary> /// <returns></returns> public Dictionary <string, string> ToExtend() { Dictionary <string, string> data = new Dictionary <string, string>(); data["MachineName"] = MachineName; data["BaseBoard"] = BaseBoard; data["Processors"] = Processors; data["Disk"] = Disk; data["DiskSerial"] = DiskSerial; data["Volume"] = Volume; data["Macs"] = Macs; data["IPs"] = IPs; data["OSVersion"] = OSVersion; data["Memory"] = Memory.ToString(); data["ScreenWidth"] = ScreenWidth.ToString(); data["ScreenHeight"] = ScreenHeight.ToString(); data["DiskSize"] = DiskSize.ToString(); return(data); }
public async Task Import(CancellationToken cancellationToken = default) { var currentUser = await _userService.GetCurrentUserAsync(); var regionsFromDb = await _db.Regions.Include(r => r.DiskSizeAssociations).ThenInclude(va => va.DiskSize).Where(r => !r.Disabled).ToListAsync(); if (regionsFromDb.Count() == 0) { throw new Exception($"Could not update Vm Disk Cache, No regions found in DB"); } var diskEntriesFromAzure = await _azureDiskPriceService.GetDiskPrices(cancellationToken : cancellationToken); if (diskEntriesFromAzure == null || (diskEntriesFromAzure != null && diskEntriesFromAzure.Count() == 0)) { throw new Exception("No VM Disk Size and Price found in Azure"); } foreach (var curRegionFromDb in regionsFromDb) { _logger.LogInformation($"Updating VM Disk Cache for Region: {curRegionFromDb.Key}"); try { if (diskEntriesFromAzure.TryGetValue(curRegionFromDb.KeyInPriceApi, out AzureDiskPriceForRegion diskSizesForRegion)) { _logger.LogInformation($"Updating VM Size Cache for Region: {curRegionFromDb.Key}. Found {diskSizesForRegion.Types.Count} Disk sizes for region"); var existingDbItemsForRegion = curRegionFromDb.DiskSizeAssociations.ToDictionary(r => r.DiskSize.Key, r => r.DiskSize); var validDiskSizesFromAzure = new HashSet <string>(); DiskSize curDiskSizeInDb; foreach (var curDiskSizeForRegion in diskSizesForRegion.Types) { if (existingDbItemsForRegion.TryGetValue(curDiskSizeForRegion.Key, out curDiskSizeInDb)) { //Get updated price for VM Size var regionAssociation = curDiskSizeInDb.RegionAssociations.Where(ra => ra.RegionKey == curRegionFromDb.Key).SingleOrDefault(); regionAssociation.Price = curDiskSizeForRegion.Value.price; await _db.SaveChangesAsync(); validDiskSizesFromAzure.Add(curDiskSizeInDb.Key); } else { //Size item might exist in db for other region curDiskSizeInDb = await _db.DiskSizes.FirstOrDefaultAsync(r => r.Key == curDiskSizeForRegion.Key); if (curDiskSizeInDb == null) { curDiskSizeInDb = new DiskSize() { Key = curDiskSizeForRegion.Key, Size = curDiskSizeForRegion.Value.size, DisplayText = AzureVmUtil.GetDiskSizeDisplayTextForDropdown(curDiskSizeForRegion.Value.size), CreatedBy = currentUser.UserName }; } ; //Add to lookup existingDbItemsForRegion.Add(curDiskSizeForRegion.Key, curDiskSizeInDb); //Add to DB curRegionFromDb.DiskSizeAssociations.Add(new RegionDiskSize() { Region = curRegionFromDb, DiskSize = curDiskSizeInDb, Price = curDiskSizeForRegion.Value.price }); await _db.SaveChangesAsync(); validDiskSizesFromAzure.Add(curDiskSizeForRegion.Key); } } //Delete those that are no longer present in Azure, or that does not pass the filter foreach (var curDbDiskSize in existingDbItemsForRegion.Values) { if (!validDiskSizesFromAzure.Contains(curDbDiskSize.Key)) { var toRemoveFromDb = curRegionFromDb.DiskSizeAssociations.FirstOrDefault(ra => ra.VmDiskKey == curDbDiskSize.Key); if (toRemoveFromDb != null) { curRegionFromDb.DiskSizeAssociations.Remove(toRemoveFromDb); } } } await _db.SaveChangesAsync(); _logger.LogInformation($"Done updating VM Disk Size and Price Cache for Region: {curRegionFromDb.Name}"); } else { _logger.LogError($"Update VM Size cache: Unable to update Size cache for Region {curRegionFromDb.Key}. No items for region in response"); } } catch (Exception ex) { _logger.LogError($"Update VM Size cache: Unable to update Size cache for Region {curRegionFromDb.Key}. Se inner exception for details", ex); continue; } } _logger.LogInformation($"Deleting Disk size entries not associated with any region"); foreach (var curDiskSize in await _db.DiskSizes.Include(s => s.RegionAssociations).ToListAsync()) { if (curDiskSize.RegionAssociations == null || (curDiskSize.RegionAssociations != null && curDiskSize.RegionAssociations.Count == 0)) { _db.DiskSizes.Remove(curDiskSize); } } await _db.SaveChangesAsync(); _logger.LogInformation($"Done updating VM Disk size cache"); }