Ejemplo n.º 1
0
        public static IOMetricsEnvironment GetIoMetrics(StorageEnvironment storageEnvironment)
        {
            var ioMetrics = new IOMetricsEnvironment
            {
                Path = storageEnvironment.Options.BasePath.FullPath
            };

            foreach (var fileMetric in storageEnvironment.Options.IoMetrics.Files)
            {
                ioMetrics.Files.Add(GetFileMetrics(fileMetric));
            }

            return(ioMetrics);
        }
Ejemplo n.º 2
0
        private void AddEnvironmentTypeToPathIfNeeded(IOMetricsEnvironment environment)
        {
            switch (environment.Type)
            {
            case StorageEnvironmentWithType.StorageEnvironmentType.Documents:
                environment.Path = Path.Combine(_basePath, "Documents");
                break;

            case StorageEnvironmentWithType.StorageEnvironmentType.System:
            case StorageEnvironmentWithType.StorageEnvironmentType.Configuration:
            case StorageEnvironmentWithType.StorageEnvironmentType.Index:
                // those envs already contain env type in path
                Debug.Assert(environment.Path.Contains(environment.Type.ToString()), "environment.Path.Contains(environment.Type.ToString())");
                break;

            default:
                throw new InvalidOperationException("Unknown type: " + environment.Type);
            }
        }
Ejemplo n.º 3
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);
        }