private static void UpdateMountPoint(StorageConfiguration storageConfiguration, Client.ServerWide.Operations.MountPointUsage mountPointUsage, string databaseName, DrivesUsage drivesUsage) { var mountPoint = mountPointUsage.DiskSpaceResult.DriveName; var usage = drivesUsage.Items.FirstOrDefault(x => x.MountPoint == mountPoint); if (usage == null) { usage = new MountPointUsage { MountPoint = mountPoint, }; drivesUsage.Items.Add(usage); } usage.VolumeLabel = mountPointUsage.DiskSpaceResult.VolumeLabel; usage.FreeSpace = mountPointUsage.DiskSpaceResult.TotalFreeSpaceInBytes; usage.TotalCapacity = mountPointUsage.DiskSpaceResult.TotalSizeInBytes; usage.IsLowSpace = StorageSpaceMonitor.IsLowSpace(new Size(usage.FreeSpace, SizeUnit.Bytes), new Size(usage.TotalCapacity, SizeUnit.Bytes), storageConfiguration, out string _); var existingDatabaseUsage = usage.Items.FirstOrDefault(x => x.Database == databaseName); if (existingDatabaseUsage == null) { existingDatabaseUsage = new DatabaseDiskUsage { Database = databaseName }; usage.Items.Add(existingDatabaseUsage); } existingDatabaseUsage.Size += mountPointUsage.UsedSpace; existingDatabaseUsage.TempBuffersSize += mountPointUsage.UsedSpaceByTempBuffers; }
private static void UpdateMountPoint( Client.ServerWide.Operations.MountPointUsage mountPointUsage, string databaseName, DrivesUsage drivesUsage) { var mountPoint = mountPointUsage.DiskSpaceResult.DriveName; var usage = drivesUsage.Items.FirstOrDefault(x => x.MountPoint == mountPoint); if (usage == null) { usage = new MountPointUsage { MountPoint = mountPoint, VolumeLabel = mountPointUsage.DiskSpaceResult.VolumeLabel, FreeSpace = mountPointUsage.DiskSpaceResult.TotalFreeSpaceInBytes, TotalCapacity = mountPointUsage.DiskSpaceResult.TotalSizeInBytes }; drivesUsage.Items.Add(usage); } usage.VolumeLabel = mountPointUsage.DiskSpaceResult.VolumeLabel; usage.FreeSpace = mountPointUsage.DiskSpaceResult.TotalFreeSpaceInBytes; usage.TotalCapacity = mountPointUsage.DiskSpaceResult.TotalSizeInBytes; var existingDatabaseUsage = usage.Items.FirstOrDefault(x => x.Database == databaseName); if (existingDatabaseUsage == null) { existingDatabaseUsage = new DatabaseDiskUsage { Database = databaseName }; usage.Items.Add(existingDatabaseUsage); } existingDatabaseUsage.Size += mountPointUsage.UsedSpace; existingDatabaseUsage.TempBuffersSize += mountPointUsage.UsedSpaceByTempBuffers; }
public static IEnumerable <AbstractDashboardNotification> FetchDatabasesInfo(ServerStore serverStore, CancellationTokenSource cts) { var databasesInfo = new DatabasesInfo(); var indexingSpeed = new IndexingSpeed(); var trafficWatch = new TrafficWatch(); var drivesUsage = new DrivesUsage(); using (serverStore.ContextPool.AllocateOperationContext(out TransactionOperationContext transactionContext)) using (transactionContext.OpenReadTransaction()) { foreach (var databaseTuple in serverStore.Cluster.ItemsStartingWith(transactionContext, Constants.Documents.Prefix, 0, int.MaxValue)) { var databaseName = databaseTuple.ItemName.Substring(3); if (cts.IsCancellationRequested) { yield break; } if (serverStore.DatabasesLandlord.DatabasesCache.TryGetValue(databaseName, out var databaseTask) == false) { // database does not exist in this server or disabled continue; } var databaseOnline = IsDatabaseOnline(databaseTask, out var database); if (databaseOnline == false) { var databaseRecord = serverStore.LoadDatabaseRecord(databaseName, out var _); if (databaseRecord == null) { // database doesn't exist continue; } var databaseInfoItem = new DatabaseInfoItem { Database = databaseName, Online = false }; DatabaseInfo databaseInfo = null; if (serverStore.DatabaseInfoCache.TryGet(databaseName, databaseInfoJson => databaseInfo = JsonDeserializationServer.DatabaseInfo(databaseInfoJson))) { Debug.Assert(databaseInfo != null); databaseInfoItem.DocumentsCount = databaseInfo.DocumentsCount ?? 0; databaseInfoItem.IndexesCount = databaseInfo.IndexesCount ?? databaseRecord.Indexes.Count; databaseInfoItem.ReplicationFactor = databaseRecord.Topology?.ReplicationFactor ?? databaseInfo.ReplicationFactor; databaseInfoItem.ErroredIndexesCount = databaseInfo.IndexingErrors ?? 0; } databasesInfo.Items.Add(databaseInfoItem); continue; } var indexingSpeedItem = new IndexingSpeedItem { Database = database.Name, IndexedPerSecond = database.Metrics.MapIndexes.IndexedPerSec.FiveSecondRate, MappedPerSecond = database.Metrics.MapReduceIndexes.MappedPerSec.FiveSecondRate, ReducedPerSecond = database.Metrics.MapReduceIndexes.ReducedPerSec.FiveSecondRate }; indexingSpeed.Items.Add(indexingSpeedItem); var replicationFactor = GetReplicationFactor(databaseTuple.Value); var documentsStorage = database.DocumentsStorage; var indexStorage = database.IndexStore; using (documentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext documentsContext)) using (documentsContext.OpenReadTransaction()) { var databaseInfoItem = new DatabaseInfoItem { Database = databaseName, DocumentsCount = documentsStorage.GetNumberOfDocuments(documentsContext), IndexesCount = database.IndexStore.Count, AlertsCount = database.NotificationCenter.GetAlertCount(), ReplicationFactor = replicationFactor, ErroredIndexesCount = indexStorage.GetIndexes().Count(index => index.GetErrorCount() > 0), Online = true }; databasesInfo.Items.Add(databaseInfoItem); } var trafficWatchItem = new TrafficWatchItem { Database = databaseName, RequestsPerSecond = (int)database.Metrics.Requests.RequestsPerSec.FiveSecondRate, WritesPerSecond = (int)database.Metrics.Docs.PutsPerSec.FiveSecondRate, WriteBytesPerSecond = database.Metrics.Docs.BytesPutsPerSec.FiveSecondRate }; trafficWatch.Items.Add(trafficWatchItem); foreach (var mountPointUsage in database.GetMountPointsUsage()) { if (cts.IsCancellationRequested) { yield break; } var mountPoint = mountPointUsage.DiskSpaceResult.DriveName; var usage = drivesUsage.Items.FirstOrDefault(x => x.MountPoint == mountPoint); if (usage == null) { usage = new MountPointUsage { MountPoint = mountPoint, VolumeLabel = mountPointUsage.DiskSpaceResult.VolumeLabel, FreeSpace = mountPointUsage.DiskSpaceResult.TotalFreeSpace.GetValue(SizeUnit.Bytes), TotalCapacity = mountPointUsage.DiskSpaceResult.TotalSize.GetValue(SizeUnit.Bytes) }; drivesUsage.Items.Add(usage); } var existingDatabaseUsage = usage.Items.FirstOrDefault(x => x.Database == databaseName); if (existingDatabaseUsage == null) { existingDatabaseUsage = new DatabaseDiskUsage { Database = databaseName }; usage.Items.Add(existingDatabaseUsage); } existingDatabaseUsage.Size += mountPointUsage.UsedSpace; } } } yield return(databasesInfo); yield return(indexingSpeed); yield return(trafficWatch); yield return(drivesUsage); }