/// <summary>
        ///
        /// </summary>
        /// <param name="configuration">Hosting configuration</param>
        /// <param name="applicationName">Name of the web application. It will be used as counetrs instance name</param>
        public PerfItDelegatingHandler(HttpConfiguration configuration, string applicationName)
        {
            _applicationName = applicationName;
            _configuration   = configuration;
            var filters = PerfItRuntime.FindAllFilters();

            foreach (var filter in filters)
            {
                foreach (var counterType in filter.Counters)
                {
                    if (!PerfItRuntime.HandlerFactories.ContainsKey(counterType))
                    {
                        throw new ArgumentException("Counter type not registered: " + counterType);
                    }

                    var counterHandler = PerfItRuntime.HandlerFactories[counterType](applicationName, filter);
                    if (!_counterContexts.Keys.Contains(counterHandler.Name))
                    {
                        _counterContexts.Add(counterHandler.Name, new PerfItCounterContext()
                        {
                            Handler = counterHandler,
                            Name    = counterHandler.Name
                        });
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoryName">Name of the grouping category of counters (e.g. Process, Processor, Network Interface are all categories)
        /// if not provided, it will use name of the assembly.
        /// </param>
        public PerfItDelegatingHandler(string categoryName = null)
        {
            PublishCounters    = true;
            RaisePublishErrors = true;

            SetPublish();
            SetErrorPolicy();

            var frames   = new StackTrace().GetFrames();
            var assembly = frames[1].GetMethod().ReflectedType.Assembly;

            if (string.IsNullOrEmpty(categoryName))
            {
                categoryName = assembly.GetName().Name;
            }

            var filters = PerfItRuntime.FindAllFilters(assembly);

            foreach (var filter in filters)
            {
                foreach (var counterType in filter.Counters)
                {
                    if (!PerfItRuntime.HandlerFactories.ContainsKey(counterType))
                    {
                        throw new ArgumentException("Counter type not registered: " + counterType);
                    }

                    var counterHandler = PerfItRuntime.HandlerFactories[counterType](categoryName, filter.InstanceName);
                    if (!_counterContexts.Keys.Contains(counterHandler.UniqueName))
                    {
                        _counterContexts.Add(counterHandler.UniqueName, new PerfItCounterContext()
                        {
                            Handler = counterHandler,
                            Name    = counterHandler.UniqueName
                        });
                    }
                }
            }
        }