Esempio n. 1
0
        /// <summary>
        /// Monitor average response time using a counter having the specified instance name
        /// </summary>
        /// <param name="counterInstanceName">Performance counter instance name</param>
        /// <param name="starttime">the start of the interval for a single sample or response time being averaged</param>
        /// <param name="lockType">some type used internally for locking</param>
        /// <param name="isMonitoringActive">caller can forward external monitoring control</param>
        /// <returns>Current time used as end time for previous sample. Can be used as starttime for next sample</returns>
        public static DateTime MonitorAverageResponse(string counterInstanceName, DateTime starttime, System.Type lockType, bool isMonitoringActive)
        {
            try
            {
                // access counter in hashlist if it is there, else null
                CounterBase counter = (CounterBase)PerformanceCounterFacade.Counters[counterInstanceName];
                // allocate counter if needed
                AverageCounter rtCounter = (AverageCounter)PerformanceCounterFacade.SetCounter(lockType, ref counter, "Average", counterInstanceName, isMonitoringActive);

                if (rtCounter != null)
                {
                    // calculate milliseconds
                    TimeSpan ts = DateTime.Now - starttime;
                    long     ms = (long)ts.TotalMilliseconds;
                    // adjust counters
                    rtCounter.AddSampleValue(ms);
                    rtCounter.IncrementSampleCount();;
                }
                // persist static, threadsafe counter (null if perf monitoring off) for reuse by validator instances
                PerformanceCounterFacade.Counters[counterInstanceName] = rtCounter;
            }
            catch (InvalidOperationException ex)
            {
            }
            return(DateTime.Now);
        }
Esempio n. 2
0
        /// <summary>
        /// Monitor an average value with a counter having the specified instance name
        /// </summary>
        /// <param name="counterInstanceName">Performance counter instance name</param>
        /// <param name="count">the value for a single sample being averaged</param>
        /// <param name="lockType">some type used internally for locking</param>
        /// <param name="isMonitoringActive">caller can forward external monitoring control</param>
        public static void MonitorAverageCount(string counterInstanceName, long count, System.Type lockType, bool isMonitoringActive)
        {
            try
            {
                // access counter in hashlist if it is there, else null
                CounterBase counter = (CounterBase)PerformanceCounterFacade.Counters[counterInstanceName];
                // allocate counter if needed
                AverageCounter avgCounter = (AverageCounter)PerformanceCounterFacade.SetCounter(lockType, ref counter, "Average", counterInstanceName, isMonitoringActive);

                if (avgCounter != null)
                {
                    // adjust counters
                    avgCounter.AddSampleValue(count);
                    avgCounter.IncrementSampleCount();;
                }
                // persist static, threadsafe counter (null if perf monitoring off) for reuse by validator instances
                PerformanceCounterFacade.Counters[counterInstanceName] = avgCounter;
            }
            catch (Exception ex)
            {
                NameValueCollection nvc = new NameValueCollection(2);
                nvc.Add("Method", "MonitorAverageCount");
                nvc.Add("Probable cause", "PerfCounters not registered or wrong category in config file");
                new LoggableException(ex, nvc);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Return a SimpleCounter for use by the caller
        /// </summary>
        /// <param name="counterInstanceName">Performance counter instance name</param>
        /// <param name="count">the value for a single sample being averaged</param>
        /// <param name="lockType">some type used internally for locking</param>
        /// <param name="isMonitoringActive">caller can forward external monitoring control</param>
        public static SimpleCounter GetSimpleCounter(string counterInstanceName, System.Type lockType, bool isMonitoringActive)
        {
            SimpleCounter simpleCounter = null;

            try
            {
                // access counter in hashlist if it is there, else null
                CounterBase counter = (CounterBase)PerformanceCounterFacade.Counters[counterInstanceName];
                // allocate counter if needed
                simpleCounter = (SimpleCounter)PerformanceCounterFacade.SetCounter(lockType, ref counter, "SimpleCounter", counterInstanceName, isMonitoringActive);
                // persist static, threadsafe counter (null if perf monitoring off) for reuse by validator instances
                PerformanceCounterFacade.Counters[counterInstanceName] = simpleCounter;
            }
            catch (Exception ex)
            {
                NameValueCollection nvc = new NameValueCollection(2);
                nvc.Add("Method", "MonitorAverageCount");
                nvc.Add("Probable cause", "PerfCounters not registered or wrong category in config file");
                new LoggableException(ex, nvc);
            }
            return(simpleCounter);
        }