コード例 #1
0
ファイル: IoMetricsUtil.cs プロジェクト: yitaom2/ravendb
        public static IOMetricsResponse GetIoMetricsResponse(IEnumerable <StorageEnvironmentWithType> environments, IEnumerable <DatabasePerformanceMetrics> performanceMetrics)
        {
            var result = new IOMetricsResponse();

            foreach (var storageEnvironment in environments)
            {
                var metrics = GetIoMetrics(storageEnvironment.Environment);
                metrics.Type = storageEnvironment.Type;
                result.Environments.Add(metrics);
            }

            if (performanceMetrics != null)
            {
                foreach (var metrics in performanceMetrics)
                {
                    result.Performances.Add(metrics.Buffer);
                }
            }
            else
            {
                result.Performances = new List <PerformanceMetrics>(0);
            }

            return(result);
        }
コード例 #2
0
        private IOMetricsResponse PrepareIOMetrics()
        {
            // 0. Prepare Response Object - Keep envs order the same as in the static endpoint response !
            var  preparedMetricsResponse = new IOMetricsResponse();
            bool responseHasContent      = false;

            // 1. Iterate over environments files in dictionary
            foreach (var envFile in _perEnvironmentsFilesMetrics)
            {
                // 2. Retrieve/Take meter items per environment file from the collection in dictionary
                var listOfMeterItems = new List <IoMeterBuffer.MeterItem>();
                while (envFile.Value.TryTake(out IoMeterBuffer.MeterItem newItem))
                {
                    listOfMeterItems.Add(newItem);
                }

                if (listOfMeterItems.Count == 0)
                {
                    continue;
                }

                // 3. Get env path & file name from dictionary item
                var meterItem = listOfMeterItems[0];
                var file      = new FileInfo(envFile.Key);
                var envPath   = file.Directory;
                if (meterItem.Type == Sparrow.Server.Meters.IoMetrics.MeterType.Compression || meterItem.Type == Sparrow.Server.Meters.IoMetrics.MeterType.JournalWrite)
                {
                    envPath = envPath?.Parent;
                }

                // 3a. Should not happen, but being extra careful here
                if (envPath == null)
                {
                    continue;
                }

                // 4. Find relevant environment
                var currentEnvironment = preparedMetricsResponse.Environments.FirstOrDefault(x => x.Path == envPath.FullName);
                if (currentEnvironment == null)
                {
                    var existingEnv = _environments.FirstOrDefault(x => x.Environment.Options.BasePath.FullPath == envPath.FullName);

                    if (existingEnv != null)
                    {
                        currentEnvironment = new IOMetricsEnvironment {
                            Path = envPath.FullName, Files = new List <IOMetricsFileStats>(), Type = existingEnv.Type
                        };
                    }
                    else
                    {
                        // If new index for example was added...

                        currentEnvironment = new IOMetricsEnvironment {
                            Path = envPath.FullName, Files = new List <IOMetricsFileStats>()
                        };

                        if (envPath.FullName.Contains("Indexes"))
                        {
                            currentEnvironment.Type = StorageEnvironmentWithType.StorageEnvironmentType.Index;
                        }
                        else if (envPath.FullName.Contains("Configuration"))
                        {
                            currentEnvironment.Type = StorageEnvironmentWithType.StorageEnvironmentType.Configuration;
                        }
                        else if (envPath.FullName.Contains("System"))
                        {
                            currentEnvironment.Type = StorageEnvironmentWithType.StorageEnvironmentType.System;
                        }
                        else
                        {
                            currentEnvironment.Type = StorageEnvironmentWithType.StorageEnvironmentType.Documents;
                        }
                    }

                    preparedMetricsResponse.Environments.Add(currentEnvironment);
                }

                // 5. Prepare response, add recent items.  Note: History items are not added since studio does not display them anyway
                var preparedFilesInfo = currentEnvironment.Files.FirstOrDefault(x => x.File == file.Name) ?? new IOMetricsFileStats
                {
                    File = file.Name
                };

                currentEnvironment.Files.Add(preparedFilesInfo);

                foreach (var item in listOfMeterItems)
                {
                    var preparedRecentStats = new IOMetricsRecentStats
                    {
                        Start          = item.Start.GetDefaultRavenFormat(true),
                        Size           = item.Size,
                        HumaneSize     = Sizes.Humane(item.Size),
                        FileSize       = item.FileSize,
                        HumaneFileSize = Sizes.Humane(item.FileSize),
                        Duration       = Math.Round(item.Duration.TotalMilliseconds, 2),
                        Type           = item.Type
                    };

                    responseHasContent = true;
                    preparedFilesInfo.Recent.Add(preparedRecentStats);
                }
            }

            if (responseHasContent == false)
            {
                return(null);
            }

            return(preparedMetricsResponse);
        }