Exemplo n.º 1
0
        /// <summary>
        /// Добавить все счётчики из категории
        /// </summary>
        private void AddCountersFromCategory(string prefix, CategoryAggregatedInfo categoryInfo, List <GraphiteCounterData> result)
        {
            if (categoryInfo.Type == CategoryTypes.Empty && categoryInfo.Instances.Count > 0)
            {
                throw new ArgumentException("Bad empty categoryInfo");
            }
            if (categoryInfo.Type == CategoryTypes.SingleInstance && categoryInfo.Instances.Count != 1)
            {
                throw new ArgumentException("Bad singleInstance categoryInfo");
            }

            if (categoryInfo.Type == CategoryTypes.Empty)
            {
                return;
            }

            string newPrefix = categoryInfo.JoinedNamePath;

            if (!string.IsNullOrEmpty(prefix))
            {
                newPrefix = prefix + "." + categoryInfo.JoinedNamePath;
            }

            foreach (var instance in categoryInfo.Instances)
            {
                AddCountersFromInstance(newPrefix, instance, result);
            }
        }
        /// <summary>
        /// Сформировать описатель категории
        /// </summary>
        private CategoryDescriptionData BuildCategoryDescription(CategoryAggregatedInfo categoryInfo)
        {
            if (categoryInfo.Type == CategoryTypes.Empty && categoryInfo.CounterDescriptors.Count > 0)
            {
                throw new ArgumentException("categoryInfo");
            }

            var counterDescriptors = categoryInfo.CounterDescriptors;
            var resultCounters     = new CounterDescriptionData[counterDescriptors.Count];

            for (int i = 0; i < counterDescriptors.Count; i++)
            {
                resultCounters[i] = new CounterDescriptionData(counterDescriptors[i].Name, counterDescriptors[i].Description, counterDescriptors[i].Type);
            }

            return(new CategoryDescriptionData(categoryInfo.NamePath, categoryInfo.Description, categoryInfo.Type, resultCounters));
        }
        /// <summary>
        /// Получить значения по категории
        /// </summary>
        private CategoryValueData BuildCategoryValueData(CategoryAggregatedInfo categoryInfo)
        {
            if (categoryInfo.Type == CategoryTypes.Empty && categoryInfo.Instances.Count > 0)
            {
                throw new ArgumentException("Bad empty categoryInfo");
            }
            if (categoryInfo.Type == CategoryTypes.SingleInstance && categoryInfo.Instances.Count != 1)
            {
                throw new ArgumentException("Bad singleInstance categoryInfo");
            }

            InstanceValueData[] instances = new InstanceValueData[categoryInfo.Instances.Count];
            for (int i = 0; i < instances.Length; i++)
            {
                instances[i] = BuildInstanceValueData(categoryInfo.Instances[i]);
            }

            return(new CategoryValueData(categoryInfo.NamePath, categoryInfo.Type, instances));
        }