コード例 #1
0
        private static void AddInstanceIndexStats(StoreStats stats, InstanceStatsHolder response)
        {
            foreach (var index in stats.Indexing)
            {
                IndexStats indexStats = null;

                if (response.DatabaseStats != null &&
                    response.DatabaseStats.Indexes != null)
                {
                    indexStats = response.DatabaseStats.Indexes
                                 .Where(idx => idx.Name == index.Name)
                                 .FirstOrDefault();
                }

                var instanceIdxStatus = new InstanceIndexStats()
                {
                    Url = response.Url
                };
                if (indexStats == null)
                {
                    instanceIdxStatus.Exists  = false;
                    instanceIdxStatus.IsStale = true;
                }
                else
                {
                    instanceIdxStatus.Exists = true;
                    if (response.DatabaseStats != null &&
                        response.DatabaseStats.Indexes != null)
                    {
                        instanceIdxStatus.IsStale = response.DatabaseStats.StaleIndexes.Contains(index.Name);
                    }
                    else
                    {
                        instanceIdxStatus.IsStale = true;
                    }

                    if (response.IndexHashCodes != null)
                    {
                        int hashCode;
                        if (response.IndexHashCodes.TryGetValue(indexStats.Name, out hashCode))
                        {
                            instanceIdxStatus.HashCode = hashCode;
                        }
                    }

                    instanceIdxStatus.CopyFrom(indexStats);
                }

                index.Instances.Add(instanceIdxStatus);
            }
        }
コード例 #2
0
        private static async Task <List <InstanceStatsHolder> > GatherResponses(
            Store store,
            Dictionary <Uri, Task <DatabaseStatistics> > dbStats,
            Dictionary <Uri, Task <RavenJToken> > replicationStats,
            Dictionary <Uri, Task <IndexDefinition[]> > indexes)
        {
            var responses = new List <InstanceStatsHolder>();

            foreach (var instance in store.Instances)
            {
                var response = new InstanceStatsHolder {
                    Url = instance.Url
                };
                try
                {
                    response.DatabaseStats = await dbStats[instance.Url];

                    var indexData = await indexes[instance.Url];
                    response.IndexHashCodes = indexData.ToDictionary(
                        i => i.Name,
                        i => i.GetHashCode());

                    var data = await replicationStats[instance.Url];
                    response.ReplicationStats = new RavenImports.JsonSerializer()
                                                .Deserialize <ReplicationStatistics>(new RavenJTokenReader(data));
                }
                catch (Exception exception)
                {
                    if (exception.IsFatal())
                    {
                        throw;
                    }

                    // TODO: Log exception.

                    response.DatabaseStats = response.DatabaseStats
                                             ?? new DatabaseStatistics();
                    response.ReplicationStats = response.ReplicationStats
                                                ?? new ReplicationStatistics {
                        Self = response.Url.ToString()
                    };
                }

                responses.Add(response);
            }

            return(responses);
        }
コード例 #3
0
ファイル: StatsExtensions.cs プロジェクト: jtbennett/brnkly
        private static async Task<List<InstanceStatsHolder>> GatherResponses(
            Store store,
            Dictionary<Uri, Task<DatabaseStatistics>> dbStats,
            Dictionary<Uri, Task<RavenJToken>> replicationStats,
            Dictionary<Uri, Task<IndexDefinition[]>> indexes)
        {
            var responses = new List<InstanceStatsHolder>();

            foreach (var instance in store.Instances)
            {
                var response = new InstanceStatsHolder { Url = instance.Url };
                try
                {
                    response.DatabaseStats = await dbStats[instance.Url];

                    var indexData = await indexes[instance.Url];
                    response.IndexHashCodes = indexData.ToDictionary(
                        i => i.Name,
                        i => i.GetHashCode());

                    var data = await replicationStats[instance.Url];
                    response.ReplicationStats = new RavenImports.JsonSerializer()
                        .Deserialize<ReplicationStatistics>(new RavenJTokenReader(data));
                }
                catch (Exception exception)
                {
                    if (exception.IsFatal()) { throw; }

                    // TODO: Log exception.

                    response.DatabaseStats = response.DatabaseStats
                        ?? new DatabaseStatistics();
                    response.ReplicationStats = response.ReplicationStats
                        ?? new ReplicationStatistics { Self = response.Url.ToString() };
                }

                responses.Add(response);
            }

            return responses;
        }
コード例 #4
0
ファイル: StatsExtensions.cs プロジェクト: jtbennett/brnkly
        private static void AddInstanceIndexStats(StoreStats stats, InstanceStatsHolder response)
        {
            foreach (var index in stats.Indexing)
            {
                IndexStats indexStats = null;

                if (response.DatabaseStats != null && 
                    response.DatabaseStats.Indexes != null)
                {
                    indexStats = response.DatabaseStats.Indexes
                        .Where(idx => idx.Name == index.Name)
                        .FirstOrDefault();
                }

                var instanceIdxStatus = new InstanceIndexStats() { Url = response.Url };
                if (indexStats == null)
                {
                    instanceIdxStatus.Exists = false;
                    instanceIdxStatus.IsStale = true;
                }
                else
                {
                    instanceIdxStatus.Exists = true;
                    if (response.DatabaseStats != null &&
                        response.DatabaseStats.Indexes != null)
                    {
                        instanceIdxStatus.IsStale = response.DatabaseStats.StaleIndexes.Contains(index.Name);
                    }
                    else
                    {
                        instanceIdxStatus.IsStale = true;
                    }

                    if (response.IndexHashCodes != null)
                    {
                        int hashCode;
                        if (response.IndexHashCodes.TryGetValue(indexStats.Name, out hashCode))
                        {
                            instanceIdxStatus.HashCode = hashCode;
                        }
                    }

                    instanceIdxStatus.CopyFrom(indexStats);
                }

                index.Instances.Add(instanceIdxStatus);
            }
        }