IncrementBy() public method

public IncrementBy ( long value ) : long
value long
return long
 /// <summary>
 /// Invoked before passing to the method
 /// </summary>
 /// <param name="c"></param>
 protected virtual void BeforeCallInvoke(PerformanceCounter c)
 {
     if (c != null)
     {
         lock (c)
         {
             string name = c.InstanceName;
             c.IncrementBy(_increaseDecrease);
             //also update overall insance!
             c.InstanceName = OverallInstance;
             c.IncrementBy(_increaseDecrease);
             c.InstanceName = name;
         }
     }
 }
Beispiel #2
0
        protected void Listener()
        {
            try
            {
                listener = new TcpListener(port);
                listener.Start();
                while (true)
                {
                    Socket          socket  = listener.AcceptSocket();
                    string          message = GetRandomQuoteOfTheDay();
                    UnicodeEncoding encoder = new UnicodeEncoding();
                    byte[]          buffer  = encoder.GetBytes(message);
                    socket.Send(buffer, buffer.Length, 0);
                    socket.Close();

                    performanceCounterRequestsTotal.Increment();
                    performanceCounterBytesSentTotal.IncrementBy(buffer.Length);
                    requestsPerSec++;
                    bytesPerSec += buffer.Length;
                }
            }
            catch (SocketException e)
            {
                string message = "Quote Server Exception in Listener: " +
                                 e.Message;
                eventLog.WriteEntry(e.Message, EventLogEntryType.Error);
            }
        }
		public void WriteCounters ()
		{
			using (var hitCounter = new PerformanceCounter ("Category", "Hits")) {
				using (var rateCounter = new PerformanceCounter ("Category", "Rate")) {
					for (var x = 0; x < 5; x++) {
						hitCounter.Increment ();
						rateCounter.IncrementBy (x + 10);
					}
				}
			}
		}
 public static void IncreaseCounter(int numberOfExecutedRequests, string instanceName)
 {
     using (
         var processedRequestsPerSecondCounter = new PerformanceCounter(Category, 
                                                                        ProcessedRequestsPerSecondCounterName, 
                                                                        instanceName, 
                                                                        false))
     {
         processedRequestsPerSecondCounter.IncrementBy(numberOfExecutedRequests);
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            CounterCreationDataCollection counters = new CounterCreationDataCollection();
            counters.Add(new CounterCreationData("Sales", "Number of total sales", PerformanceCounterType.NumberOfItems64));
            counters.Add(new CounterCreationData("Active Users", "Number of active users", PerformanceCounterType.NumberOfItems64));
            counters.Add(new CounterCreationData("Sales value", "Total value of all sales", PerformanceCounterType.NumberOfItems64));
            PerformanceCounterCategory.Create("MyApp Counters", "Counters describing the performance of MyApp",
                PerformanceCounterCategoryType.SingleInstance, counters);

            PerformanceCounter pc = new PerformanceCounter("MyApp Counters", "Sales", false);

            pc.RawValue = 7;
            pc.Decrement();
            pc.Increment();
            pc.IncrementBy(3);
        }
Beispiel #6
0
        /// <summary>
        /// Stops counting time (Happens at the end of the request)
        /// </summary>
        public void Stop()
        {
            _Stopwatch.Stop();

            if (_OperationsPerSecond != null)
            {
                _OperationsPerSecond.Increment();
            }

            if (_AverageDuration != null & _AverageDurationBase != null)
            {
                var elapsedTicks = _Stopwatch.ElapsedTicks;
                _AverageDuration.IncrementBy(elapsedTicks);
                _AverageDurationBase.Increment();
            }
        }
Beispiel #7
0
        internal bool IncrementBy(long value)
        {
            if (!this.Accessible)
            {
                return(false);
            }

            try
            {
                _counter.IncrementBy(value);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }

            return(true);
        }
        public void StopCounter()
        {
            this.stopWatch.Stop();

            using (
                var averageExecutionTimeCounter = new PerformanceCounter(Category, 
                                                                         AverageExecutionTimeCounterName, 
                                                                         this.instanceName, 
                                                                         false))
            {
                using (
                    var averageExecutionTimeBaseCounter = new PerformanceCounter(Category, 
                                                                                 AverageExecutionTimeBaseCounterName, 
                                                                                 this.instanceName, 
                                                                                 false))
                {
                    averageExecutionTimeCounter.IncrementBy(this.stopWatch.ElapsedTicks);
                    averageExecutionTimeBaseCounter.Increment();
                }
            }
        }
 //public static void CountBeginAverageTimerCounter
 //                        (
 //                            this PerformanceCounter performanceCounter
 //                            , PerformanceCounter basePerformanceCounter
 //                            , Stopwatch stopwatch
 //                        )
 //{
 //        //stopwatch.Reset();
 //        //stopwatch.Start();
 //        stopwatch.Restart();
 //}
 public static void CountEndAverageTimerCounter
                 (
                     this PerformanceCounter performanceCounter
                     , PerformanceCounter basePerformanceCounter
                     , Stopwatch stopwatch
                     , Func<PerformanceCounterProcessingFlagsType, PerformanceCounter, long> onBasePerformanceCounterChangeValueProcessFunc = null
                 )
 {
     if
         (
             stopwatch != null
         )
     {
         if (stopwatch.IsRunning)
         {
             stopwatch.Stop();
         }
         performanceCounter
                 .IncrementBy(stopwatch.ElapsedTicks);
         //stopwatch = null;
         var increment = 1L;
         if (onBasePerformanceCounterChangeValueProcessFunc != null)
         {
             increment = onBasePerformanceCounterChangeValueProcessFunc
                                 (
                                     PerformanceCounterProcessingFlagsType.TimeBasedOnEnd
                                     , basePerformanceCounter
                                 );
         }
         if (increment == 1)
         {
             basePerformanceCounter.Increment();
         }
         else
         {
             basePerformanceCounter.IncrementBy(increment);
         }
         
     }
 }
Beispiel #10
0
        PerformanceCounter GetCounter(string category, string counter,
             PerformanceCounterType type = PerformanceCounterType.AverageCount64,
             string machine = ".", string instance = "_Total")
        {
            if (!PerformanceCounterCategory.Exists(category))
            {
                // create category
                var counterInfos = new CounterCreationDataCollection();
                var counterInfo = new CounterCreationData()
                    {
                        CounterType = type,
                        CounterName = counter,
                    };
                counterInfos.Add(counterInfo);
                PerformanceCounterCategory
                    .Create(category, category, counterInfos);

                // check creation
                var counters
                    = new PerformanceCounterCategory(category, machine);
                if (!counters.CounterExists(counter))
                    Debug.Fail("Counter was not created");
                if (!counters.InstanceExists(instance))
                    Debug.Fail("Instance not found");
            }

            // get counter

            var perfCounter = new PerformanceCounter
            {
                CategoryName = category,
                CounterName = counter,
                MachineName = machine,
                ReadOnly = false,
            };
            perfCounter.IncrementBy(10);

            return perfCounter;
        }
        public void GetPerformanceCounter()
        {
            var counter = new System.Diagnostics.PerformanceCounter
            {
                CategoryName     = "Distracey.Examples.Website-ApiFilter",
                InstanceName     = "Default",
                CounterName      = "ValuesController.Get(Int32 id) - GET - Average seconds taken to execute",
                ReadOnly         = false,
                InstanceLifetime = PerformanceCounterInstanceLifetime.Process,
            };

            counter.RawValue = 0;

            const int value = 100;

            counter.IncrementBy(value);

            System.Diagnostics.PerformanceCounter.CloseSharedResources();

            Assert.AreEqual(value, counter.RawValue);

            counter.RemoveInstance();
            counter.Dispose();
        }
        private static void setupAndIncrement(PerformanceCounter counter, string counterName, long? value = null)
        {
            if (Diagnostics.CassandraPerformanceCountersEnabled)
            {
                if (counter == null)
                    counter = SetupCounter(CassandraCountersCategory, counterName);

                if (counter != null && CategoryReady)
                    if (value != null)
                        counter.IncrementBy((long)value);
                    else
                        counter.Increment();
            }
        }
Beispiel #13
0
 private static void ClearCounter(PerformanceCounter counter)
 {
     counter.IncrementBy(-1 * counter.RawValue);
 }
		private void IncrementBy(PerformanceCounter counter, long value)
		{
			if (counter != null)
				counter.IncrementBy(value);
		}
        /// <summary>
        /// Initialises the extension.
        /// </summary>
        /// <param name="extensionConfig"></param>
        /// <param name="server">The server that this extension is for.</param>
        public void Initialise(ICruiseServer server, ExtensionConfiguration extensionConfig)
        {
            if (!PerformanceCounterCategory.Exists("CruiseControl.NET"))
            {
                Log.Info("Initialising new performance counters for integration requests");
                var collection = new CounterCreationDataCollection();

                // Number of integrations completed counter
                var numberOfCompletedIntegrations = new CounterCreationData();
                numberOfCompletedIntegrations.CounterType = PerformanceCounterType.NumberOfItems32;
                numberOfCompletedIntegrations.CounterName = "Number of Completed Integrations";
                collection.Add(numberOfCompletedIntegrations);

                // Number of integrations failed counter
                var numberOfFailedIntegrations = new CounterCreationData();
                numberOfFailedIntegrations.CounterType = PerformanceCounterType.NumberOfItems32;
                numberOfFailedIntegrations.CounterName = "Number of Failed Integrations";
                collection.Add(numberOfFailedIntegrations);

                // Integration time counter
                var integrationElapsedTime = new CounterCreationData();
                integrationElapsedTime.CounterType = PerformanceCounterType.AverageTimer32;
                integrationElapsedTime.CounterName = "Integration Time";
                collection.Add(integrationElapsedTime);

                // Integration count counter
                var averageIntegrations = new CounterCreationData();
                averageIntegrations.CounterType = PerformanceCounterType.AverageBase;
                averageIntegrations.CounterName = "Average number of integrations";
                collection.Add(averageIntegrations);

                // Create the category
                PerformanceCounterCategory.Create("CruiseControl.NET",
                    "Performance counters for CruiseControl.NET",
                    collection);
            }

            // Retrieve the counters
            Log.Debug("Initialising performance monitoring - integration requests");
            var numberOfCompletedIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Number of Completed Integrations", false);
            var numberOfFailedIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Number of Failed Integrations", false);
            var integrationElapsedTimeCounter = new PerformanceCounter("CruiseControl.NET", "Integration Time", false);
            var averageIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Average number of integrations", false);
            var stopwatches = new Dictionary<string, Stopwatch>();

            server.IntegrationStarted += (o, e) =>
            {
                Log.Debug(string.Format("Starting stopwatch for '{0}'", e.ProjectName));

                // Start a stopwatch for the project
                if (stopwatches.ContainsKey(e.ProjectName))
                {
                    stopwatches[e.ProjectName].Reset();
                }
                else
                {
                    var stopwatch = new Stopwatch();
                    stopwatches.Add(e.ProjectName, stopwatch);
                    stopwatch.Start();
                }
            };
            server.IntegrationCompleted += (o, e) =>
            {
                Log.Debug(string.Format("Performance logging for '{0}'", e.ProjectName));

                // Stop the stopwatch and record the elapsed time
                if (stopwatches.ContainsKey(e.ProjectName))
                {
                    var stopwatch = stopwatches[e.ProjectName];
                    stopwatch.Stop();
                    stopwatches.Remove(e.ProjectName);
                    averageIntegrationsCounter.Increment();
                    integrationElapsedTimeCounter.IncrementBy(stopwatch.ElapsedTicks);
                }

                // Record the result
                if (e.Status == IntegrationStatus.Success)
                {
                    numberOfCompletedIntegrationsCounter.Increment();
                }
                else
                {
                    numberOfFailedIntegrationsCounter.Increment();
                }
            };
        }
Beispiel #16
0
		void PerformanceCountersEndRequest()
		{
			try
			{
			if (HttpContext.Current.Items["DsiPage"] != null)
			{
				if (PerformanceCounterCategory.Exists("DontStayIn"))
				{
					PerformanceCounter DsiPages = new PerformanceCounter();
					DsiPages.CategoryName = "DontStayIn";
					DsiPages.CounterName = "DsiPages per sec";
					DsiPages.MachineName = ".";
					DsiPages.ReadOnly = false;

					PerformanceCounter GenTime = new PerformanceCounter();
					GenTime.CategoryName = "DontStayIn";
					GenTime.CounterName = "DsiPage generation time";
					GenTime.MachineName = ".";
					GenTime.ReadOnly = false;

					PerformanceCounter GenTimeBase = new PerformanceCounter();
					GenTimeBase.CategoryName = "DontStayIn";
					GenTimeBase.CounterName = "DsiPage generation time base";
					GenTimeBase.MachineName = ".";
					GenTimeBase.ReadOnly = false;

					DsiPages.Increment();
					long ticksStart = (long)HttpContext.Current.Items["ApplicationStartTicks"];
					long ticksEnd = 0;
					QueryPerformanceCounter(ref ticksEnd);
					GenTime.IncrementBy(ticksEnd - ticksStart);
					GenTimeBase.Increment();
				}

			}
		}
			catch { }
		}
		private void DecrementBy(PerformanceCounter counter, long value)
		{
			if (counter != null)
				counter.IncrementBy(value < 0 ? value : value * -1);
		}
 public static void IncrementCounter(string counterName, int incrementBy)
 {
     try
     {
         if (m_sipsorceryCategoryReady)
         {
             if (m_counters.ContainsKey(counterName))
             {
                 m_counters[counterName].IncrementBy(incrementBy);
             }
             else
             {
                 PerformanceCounter counter = new PerformanceCounter(PERFORMANCE_COUNTER_CATEGORY_NAME, counterName, false);
                 m_counters.Add(counterName, counter);
                 counter.IncrementBy(incrementBy);
             }
         }
     }
     catch (Exception excp)
     {
         logger.Error("Exception SIPSorceryPerformanceMonitor IncrementCounter (" + counterName + "). " + excp.Message);
     }
 }
Beispiel #19
0
        static void Increment(long amount, PerformanceCounter total, PerformanceCounter remote, PerformanceCounter local)
        {
            total.IncrementBy(amount);

            if (ServiceHandler.IsExecuting)
                remote.IncrementBy(amount);
            else
                local.IncrementBy(amount);
        }