Exemplo n.º 1
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            //如果监控功能未打开,直接退出
            if (ConfigInfo.Value.PerformanceEnabled == false)
            {
                return;
            }

            //获取action或controller上面的属性,如果标记为DoNotTrackPerformanceAttribute,直接退出
            HttpActionDescriptor actionDescriptor = actionContext.ActionDescriptor;

            if (actionDescriptor.GetCustomAttributes <DoNotTrackPerformanceAttribute>().Count > 0 ||
                actionDescriptor.ControllerDescriptor.GetCustomAttributes <DoNotTrackPerformanceAttribute>().Count > 0)
            {
                return;
            }

            //获取action相关信息
            ActionInfo info = this.CreateActionInfo(actionContext);

            //加载监控器
            PerformanceTracker tracker = new PerformanceTracker(logger, PerformanceMetricFactory.GetPerformanceMetrics(info).ToArray());

            //保存到当前上下文中
            actionContext.Request.Properties.Add(this.GetType().FullName, tracker);

            //启动监控
            tracker.ProcessStart();
        }
Exemplo n.º 2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //如果监控功能未打开,直接退出
            if (ConfigInfo.Value.PerformanceEnabled == false)
            {
                return;
            }


            //获取action或controller上面的属性,如果标记为DoNotTrackPerformanceAttribute,直接退出
            ActionDescriptor actionDescriptor = filterContext.ActionDescriptor;

            if (actionDescriptor.GetCustomAttributes(typeof(DoNotTrackPerformanceAttribute), true).Length > 0 ||
                actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(DoNotTrackPerformanceAttribute), true).Length > 0)
            {
                return;
            }

            //获取action相关信息
            ActionInfo info = this.CreateActionInfo(filterContext);

            //加载监控器
            PerformanceTracker tracker = new PerformanceTracker(logger, PerformanceMetricFactory.GetPerformanceMetrics(info).ToArray());

            //保存到当前上下文中
            String contextKey = this.GetUniqueContextKey(filterContext.ActionDescriptor.UniqueId);

            HttpContext.Current.Items.Add(contextKey, tracker);

            //启动监控
            tracker.ProcessStart();
        }