/// <summary>
        /// 移除计数器
        /// </summary>
        /// <param name="name"></param>
        public static void RemoveMonitor(string name)
        {
            MonitorData md = null;

            ExceptionHelper.FalseThrow(StopWatchContextCache.Instance.TryGetValue(name, out md),
                                       "不能找到名称为{0}的MonitorData");

            md.Stopwatch.Stop();
            StopWatchContextCache.Instance.Remove(name);
        }
        /// <summary>
        /// 得到默认的Monitor
        /// </summary>
        /// <returns></returns>
        public static MonitorData GetDefaultMonitor()
        {
            MonitorData md = null;

            if (StopWatchContextCache.Instance.TryGetValue(DefaultMonitorName, out md) == false)
            {
                md = StartMonitor(DefaultMonitorName);
            }

            return(md);
        }
        /// <summary>
        /// 得到指定名称的监控数据
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MonitorData GetMonitor(string name)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(name, "name");

            MonitorData md = null;

            ExceptionHelper.FalseThrow(StopWatchContextCache.Instance.TryGetValue(name, out md),
                                       "不能找到名称为{0}的MonitorData");

            return(md);
        }
        /// <summary>
        /// 开始执行计数
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MonitorData StartMonitor(string name)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(name, "name");

            ExceptionHelper.TrueThrow(StopWatchContextCache.Instance.ContainsKey(name),
                                      "已经启动了名称为{0}的MonitorData", name);

            MonitorData md = new MonitorData();

            StopWatchContextCache.Instance.Add(name, md);

            md.Stopwatch.Start();

            return(md);
        }
Exemplo n.º 5
0
		private void SetCountersValue(MonitorData md)
		{
			PMPerformanceCounters counters = PMPerformanceCounters.GetCounters(md.InstanceName);

			counters.PageAccessCount.Increment();
			counters.PageAccessCountPerSecond.Increment();

			if (md.HasErrors)
				counters.PageErrorCount.Increment();
			else
			{
				counters.PageSuccessCount.Increment();
				counters.PageSuccessRatio.Increment();
			}

			counters.PageSuccessRatioBase.Increment();

			counters.PageAccessCurrentAverageBase.Increment();
			counters.PageAccessCurrentAverage.IncrementBy(md.Stopwatch.ElapsedTicks);
			counters.PageAccessTotalAverageBase.Increment();
			counters.PageAccessTotalAverage.IncrementBy(md.Stopwatch.ElapsedMilliseconds / 100);
		}
Exemplo n.º 6
0
		private void CommitLogging(MonitorData md)
		{
			StringBuilder strB = ((StringWriter)md.LogWriter).GetStringBuilder();

			if (strB.Length > 0)
			{
				try
				{
					Logger logger = LoggerFactory.Create("PageMonitor");

					if (logger != null)
						logger.Write(strB.ToString(), LogPriority.Normal, 8005, TraceEventType.Information, "页面访问日志");
				}
				catch (System.Exception)
				{
				}
			}
		}
        private static void SetOnePFInstanceValues(WebMethodServerCounters instance, MonitorData md, bool hasErrors)
        {
            instance.RequestCount.Increment();

            instance.RequestAverageDurationBase.Increment();
            instance.RequestAverageDuration.IncrementBy(md.Stopwatch.ElapsedMilliseconds / 100);

            if (hasErrors)
                instance.RequestFailCount.Increment();
            else
                instance.RequestSuccessCount.Increment();

            instance.RequestsPerSecond.Increment();
        }
        private static void SetCountersValues(MonitorData md, bool hasErrors)
        {
            WebMethodServerCounters global = (WebMethodServerCounters)md.Context["GlobalInstance"];
            WebMethodServerCounters instance = (WebMethodServerCounters)md.Context["Instance"];

            SetOnePFInstanceValues(global, md, hasErrors);
            SetOnePFInstanceValues(instance, md, hasErrors);
        }