示例#1
0
        public void RegisterCategory(CategoryConfiguration categoryConfiguration)
        {
            if (!PerformanceCounterCategory.Exists(categoryConfiguration.Name))
            {
                PerformanceCounterCategory.Create(
                    categoryConfiguration.Name,
                    categoryConfiguration.Help,
                    PerformanceCounterCategoryType.MultiInstance,
                    new CounterCreationDataCollection(
                        categoryConfiguration.Counters.Select(x => (CounterCreationData)x).ToArray()));
                return;
            }


            CleanUpCategory(categoryConfiguration);
        }
示例#2
0
        void Register(Type counterCategoryType)
        {
            var category = new CategoryConfiguration
            {
                Name = counterCategoryType.Name
            };
            var props = counterCategoryType.GetProperties();

            foreach (var propertyInfo in props)
            {
                var counter = new PerformanceCounterConfiguration(propertyInfo.Name, "no-counter-help-yet",
                                                                  PerformanceCounterType.NumberOfItems32);
                category.Counters.Add(counter);
            }
            _categoryConfigurations.Add(category);
        }
示例#3
0
        static void CleanUpCategory(CategoryConfiguration categoryConfiguration)
        {
            int missing = categoryConfiguration.Counters
                          .Where(counter => !PerformanceCounterCategory.CounterExists(counter.Name, categoryConfiguration.Name))
                          .Count();

            if (missing > 0)
            {
                PerformanceCounterCategory.Delete(categoryConfiguration.Name);

                PerformanceCounterCategory.Create(
                    categoryConfiguration.Name,
                    categoryConfiguration.Help,
                    PerformanceCounterCategoryType.MultiInstance,
                    new CounterCreationDataCollection(
                        categoryConfiguration.Counters.Select(x => (CounterCreationData)x).ToArray()));
            }
        }