コード例 #1
0
 //------------------------------------------------------------------------------
 //
 // Method: PerformanceCounterMetricLoggerImplementation (constructor)
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Initialises a new instance of the ApplicationMetrics.PerformanceCounterMetricLoggerImplementation class.  Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions.
 /// </summary>
 /// <param name="metricCategoryName">The name of the performance counter category which the metric events should be logged under.</param>
 /// <param name="metricCategoryDescription">The description of the performance counter category which the metric events should be logged under.</param>
 /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param>
 /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param>
 /// <param name="counterCreationDataCollection">A test (mock) counter creation data collection object.</param>
 /// <param name="counterCreationDataFactory">A test (mock) counter creation data factory object.</param>
 /// <param name="performanceCounterCategory">A test (mock) performance counter category object.</param>
 /// <param name="performanceCounterFactory">A test (mock) performance counter factory object.</param>
 /// <param name="dateTime">A test (mock) DateTime object.</param>
 /// <param name="exceptionHandler">A test (mock) exception handler object.</param>
 public PerformanceCounterMetricLoggerImplementation(string metricCategoryName, string metricCategoryDescription, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, ICounterCreationDataCollection counterCreationDataCollection, ICounterCreationDataFactory counterCreationDataFactory, IPerformanceCounterCategory performanceCounterCategory, IPerformanceCounterFactory performanceCounterFactory, IDateTime dateTime, IExceptionHandler exceptionHandler)
     : base(bufferProcessingStrategy, intervalMetricChecking, dateTime, exceptionHandler)
 {
     InitialisePrivateMembers(metricCategoryName, metricCategoryDescription);
     this.counterCreationDataCollection = counterCreationDataCollection;
     this.counterCreationDataFactory    = counterCreationDataFactory;
     this.performanceCounterCategory    = performanceCounterCategory;
     this.performanceCounterFactory     = performanceCounterFactory;
 }
コード例 #2
0
 //------------------------------------------------------------------------------
 //
 // Method: PerformanceCounterMetricLogger (constructor)
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Initialises a new instance of the ApplicationMetrics.PerformanceCounterMetricLogger class.  Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions.
 /// </summary>
 /// <param name="metricCategoryName">The name of the performance counter category which the metric events should be logged under.</param>
 /// <param name="metricCategoryDescription">The description of the performance counter category which the metric events should be logged under.</param>
 /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param>
 /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param>
 /// <param name="counterCreationDataCollection">A test (mock) counter creation data collection object.</param>
 /// <param name="counterCreationDataFactory">A test (mock) counter creation data factory object.</param>
 /// <param name="performanceCounterCategory">A test (mock) performance counter category object.</param>
 /// <param name="performanceCounterFactory">A test (mock) performance counter factory object.</param>
 /// <param name="dateTime">A test (mock) DateTime object.</param>
 /// <param name="exceptionHandler">A test (mock) exception handler object.</param>
 public PerformanceCounterMetricLogger(string metricCategoryName, string metricCategoryDescription, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, ICounterCreationDataCollection counterCreationDataCollection, ICounterCreationDataFactory counterCreationDataFactory, IPerformanceCounterCategory performanceCounterCategory, IPerformanceCounterFactory performanceCounterFactory, IDateTime dateTime, IExceptionHandler exceptionHandler)
 {
     loggerImplementation = new PerformanceCounterMetricLoggerImplementation(metricCategoryName, metricCategoryDescription, bufferProcessingStrategy, intervalMetricChecking, counterCreationDataCollection, counterCreationDataFactory, performanceCounterCategory, performanceCounterFactory, dateTime, exceptionHandler);
 }
コード例 #3
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:FrameworkAbstraction.IPerformanceCounterCategory.Create(System.String,System.String,System.Diagnostics.PerformanceCounterCategoryType,ICounterCreationDataCollection)"]/*'/>
 public void Create(string categoryName, string categoryHelp, System.Diagnostics.PerformanceCounterCategoryType categoryType, ICounterCreationDataCollection counterData)
 {
     System.Diagnostics.PerformanceCounterCategory.Create(categoryName, categoryHelp, categoryType, counterData.Collection);
 }
コード例 #4
0
        //------------------------------------------------------------------------------
        //
        // Method: CreatePerformanceCounters
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Creates Windows performance counters for the registered metrics and defined aggregates on the local computer.
        /// </summary>
        public void CreatePerformanceCounters()
        {
            if (counterCreationDataCollection == null)
            {
                counterCreationDataCollection = new CounterCreationDataCollection();
            }

            // Create performance counters for metrics
            foreach (MetricBase currentMetric in registeredMetrics.Values)
            {
                ValidateMetricName(currentMetric);
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentMetric.Name, currentMetric.Description, System.Diagnostics.PerformanceCounterType.NumberOfItems64);
                counterCreationDataCollection.Add(counterCreationData);
            }

            // Create performance counters for various types of aggregates
            foreach (MetricAggregateContainer <CountMetric> currentAggregate in countOverTimeUnitAggregateDefinitions)
            {
                // Create the basic counter as type NumberOfItems64.  The value of the aggregate will be calculated by this class, and will show the average count of items per time unit of the entire duration of running instances of this class (i.e. from when Start() was called).
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentAggregate.Name, currentAggregate.Description, System.Diagnostics.PerformanceCounterType.NumberOfItems64);
                counterCreationDataCollection.Add(counterCreationData);
                // Create a second 'instantaneous' instance of the same metric aggregate
                // If the time unit of the aggregate is second use the RateOfCountsPerSecond64 counter time, for other time units use the where the AverageCount64 type
                //   As per http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecountertype%28v=vs.110%29.aspx AverageCount64 requires an accompanying base counter added directly after it
                if (currentAggregate.DenominatorTimeUnit == TimeUnit.Second)
                {
                    ICounterCreationData instantaneousCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneous(currentAggregate.Name), CounterDescriptionAppendInstantaneous(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond64);
                    counterCreationDataCollection.Add(instantaneousCounterCreationData);
                }
                else
                {
                    ICounterCreationData instantaneousCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneous(currentAggregate.Name), CounterDescriptionAppendInstantaneous(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageCount64);
                    counterCreationDataCollection.Add(instantaneousCounterCreationData);
                    ICounterCreationData instantaneousBaseCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneousBase(currentAggregate.Name), CounterDescriptionAppendInstantaneousBase(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageBase);
                    counterCreationDataCollection.Add(instantaneousBaseCounterCreationData);
                }
            }

            foreach (MetricAggregateContainer <AmountMetric, CountMetric> currentAggregate in amountOverCountAggregateDefinitions)
            {
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentAggregate.Name, currentAggregate.Description, System.Diagnostics.PerformanceCounterType.NumberOfItems64);
                counterCreationDataCollection.Add(counterCreationData);
                // Create a second 'instantaneous' instance of the same metric aggregate
                ICounterCreationData instantaneousCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneous(currentAggregate.Name), CounterDescriptionAppendInstantaneous(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageCount64);
                counterCreationDataCollection.Add(instantaneousCounterCreationData);
                ICounterCreationData instantaneousBaseCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneousBase(currentAggregate.Name), CounterDescriptionAppendInstantaneousBase(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageBase);
                counterCreationDataCollection.Add(instantaneousBaseCounterCreationData);
            }

            foreach (MetricAggregateContainer <AmountMetric> currentAggregate in amountOverTimeUnitAggregateDefinitions)
            {
                // Create the basic counter as type NumberOfItems64.  The value of the aggregate will be calculated by this class, and will show the average amount per time unit of the entire duration of running instances of this class (i.e. from when Start() was called).
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentAggregate.Name, currentAggregate.Description, System.Diagnostics.PerformanceCounterType.NumberOfItems64);
                counterCreationDataCollection.Add(counterCreationData);
                // Create a second 'instantaneous' instance of the same metric aggregate
                // If the time unit of the aggregate is second use the RateOfCountsPerSecond64 counter time, for other time units use the where the AverageCount64 type
                //   As per http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecountertype%28v=vs.110%29.aspx AverageCount64 requires an accompanying base counter added directly after it
                if (currentAggregate.DenominatorTimeUnit == TimeUnit.Second)
                {
                    ICounterCreationData instantaneousCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneous(currentAggregate.Name), CounterDescriptionAppendInstantaneous(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond64);
                    counterCreationDataCollection.Add(instantaneousCounterCreationData);
                }
                else
                {
                    ICounterCreationData instantaneousCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneous(currentAggregate.Name), CounterDescriptionAppendInstantaneous(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageCount64);
                    counterCreationDataCollection.Add(instantaneousCounterCreationData);
                    ICounterCreationData instantaneousBaseCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneousBase(currentAggregate.Name), CounterDescriptionAppendInstantaneousBase(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageBase);
                    counterCreationDataCollection.Add(instantaneousBaseCounterCreationData);
                }
            }

            foreach (MetricAggregateContainer <AmountMetric, AmountMetric> currentAggregate in amountOverAmountAggregateDefinitions)
            {
                // Create counter as type RawFraction
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentAggregate.Name, currentAggregate.Description, System.Diagnostics.PerformanceCounterType.RawFraction);
                counterCreationDataCollection.Add(counterCreationData);
                ICounterCreationData baseCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendBase(currentAggregate.Name), CounterDescriptionAppendBase(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.RawBase);
                counterCreationDataCollection.Add(baseCounterCreationData);
            }

            foreach (MetricAggregateContainer <IntervalMetric, CountMetric> currentAggregate in intervalOverAmountAggregateDefinitions)
            {
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentAggregate.Name, currentAggregate.Description, System.Diagnostics.PerformanceCounterType.NumberOfItems64);
                counterCreationDataCollection.Add(counterCreationData);
                // Create a second 'instantaneous' instance of the same metric aggregate
                ICounterCreationData instantaneousCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneous(currentAggregate.Name), CounterDescriptionAppendInstantaneous(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageCount64);
                counterCreationDataCollection.Add(instantaneousCounterCreationData);
                ICounterCreationData instantaneousBaseCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendInstantaneousBase(currentAggregate.Name), CounterDescriptionAppendInstantaneousBase(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.AverageBase);
                counterCreationDataCollection.Add(instantaneousBaseCounterCreationData);
            }

            foreach (MetricAggregateContainer <IntervalMetric> currentAggregate in intervalOverTotalRunTimeAggregateDefinitions)
            {
                ICounterCreationData counterCreationData = counterCreationDataFactory.Create(currentAggregate.Name, currentAggregate.Description, System.Diagnostics.PerformanceCounterType.RawFraction);
                counterCreationDataCollection.Add(counterCreationData);
                ICounterCreationData baseCounterCreationData = counterCreationDataFactory.Create(CounterNameAppendBase(currentAggregate.Name), CounterDescriptionAppendBase(currentAggregate.Description), System.Diagnostics.PerformanceCounterType.RawBase);
                counterCreationDataCollection.Add(baseCounterCreationData);
            }

            try
            {
                if (performanceCounterCategory.Exists(metricCategoryName) == true)
                {
                    performanceCounterCategory.Delete(metricCategoryName);
                }
                performanceCounterCategory.Create(metricCategoryName, metricCategoryDescription, System.Diagnostics.PerformanceCounterCategoryType.SingleInstance, counterCreationDataCollection);
            }
            catch (Exception e)
            {
                throw new Exception("Failed to create performance counter category.", e);
            }
        }
コード例 #5
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:FrameworkAbstraction.IPerformanceCounterCategory.Create(System.String,System.String,System.Diagnostics.PerformanceCounterCategoryType,ICounterCreationDataCollection)"]/*'/>
 public void Create(string categoryName, string categoryHelp, System.Diagnostics.PerformanceCounterCategoryType categoryType, ICounterCreationDataCollection counterData)
 {
     System.Diagnostics.PerformanceCounterCategory.Create(categoryName, categoryHelp, categoryType, counterData.Collection);
 }