private void LoadTestStarting(object sender, EventArgs e)
        {
            // Delete the category if already exists
            if (PerformanceCounterCategory.Exists("AMSStressCounterSet"))
            {

                PerformanceCounterCategory.Delete("AMSStressCounterSet");
            }

            CounterCreationDataCollection counters = new CounterCreationDataCollection();

                // 1. counter for counting totals: PerformanceCounterType.NumberOfItems32
                CounterCreationData totalOps = new CounterCreationData();
                totalOps.CounterName = "# operations executed";
                totalOps.CounterHelp = "Total number of operations executed";
                totalOps.CounterType = PerformanceCounterType.NumberOfItems32;
                counters.Add(totalOps);

                // 2. counter for counting operations per second:
                //        PerformanceCounterType.RateOfCountsPerSecond32
                CounterCreationData opsPerSecond = new CounterCreationData();
                opsPerSecond.CounterName = "# operations / sec";
                opsPerSecond.CounterHelp = "Number of operations executed per second";
                opsPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
                counters.Add(opsPerSecond);

                // create new category with the counters above
                PerformanceCounterCategory.Create("AMSStressCounterSet", "KeyDelivery Stress Counters", PerformanceCounterCategoryType.SingleInstance, counters);
        }
		public void AddRange (CounterCreationDataCollection value)
		{
			foreach (CounterCreationData v in value)
			{
				Add (v);
			}
		}
        public void Test()
        {
            const string categoryName = "TestCategory";
            const string categoryHelp = "Test category help";
            const PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.SingleInstance;
            const string counterName = "TestElapsedTime";
            const string counterHelp = "Test elapsed time";

            if (!PerformanceCounterCategory.Exists(categoryName))
            {
                var counterCreationData = new CounterCreationDataCollection(ElapsedTime.CounterCreator.CreateCounterData(counterName, counterHelp));
                var category = PerformanceCounterCategory.Create(categoryName, categoryHelp, categoryType, counterCreationData);
            }
            var elapsedTime = new ElapsedTime(PerformanceCounterFactory.Singleton, categoryName, "TestElapsedTime", false);
            elapsedTime.Reset();

            var count = 0;
            while (++count < 10)
            {
                Thread.Sleep(1000);
                var value = elapsedTime.NextValue();
                Debug.Print("Value = {0}", value);
            }

            elapsedTime.Dispose();
            
            PerformanceCounterCategory.Delete(categoryName);
        }
示例#4
0
        private static void SetupCategory()
        {
            if (PerformanceCounterCategory.Exists(CategoryName))
            {
                PerformanceCounterCategory.Delete(CategoryName);
            }
            if (!PerformanceCounterCategory.Exists(CategoryName))
            {
                CounterCreationDataCollection creationDataCollection =
                    new CounterCreationDataCollection();

                CounterCreationData ctrCreationData = new CounterCreationData();
                ctrCreationData.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
                ctrCreationData.CounterName = SpeedCounterName;
                creationDataCollection.Add(ctrCreationData);

                CounterCreationData ctrCreationData2 = new CounterCreationData();
                ctrCreationData2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
                ctrCreationData2.CounterName = SpeedBytesCounterName;
                creationDataCollection.Add(ctrCreationData2);

                PerformanceCounterCategory.Create(CategoryName,
                    "Sample TransVault category",
                    PerformanceCounterCategoryType.MultiInstance,
                    creationDataCollection);
            }
        }
		public static bool InstallCounters()
		{
			string message = String.Empty;
			try
			{
				if(RelayNode.log.IsInfoEnabled)
                    RelayNode.log.InfoFormat("Creating performance counter category {0}", RelayNodeCounters.PerformanceCategoryName);
				Console.WriteLine("Creating performance counter category " + RelayNodeCounters.PerformanceCategoryName);
				CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

				for (int i = 0; i < RelayNodeCounters.PerformanceCounterNames.Length; i++)
				{
					counterDataCollection.Add(new CounterCreationData(RelayNodeCounters.PerformanceCounterNames[i], RelayNodeCounters.PerformanceCounterHelp[i], RelayNodeCounters.PerformanceCounterTypes[i]));
					message = "Creating perfomance counter " + RelayNodeCounters.PerformanceCounterNames[i];
					Console.WriteLine(message);
					if(RelayNode.log.IsInfoEnabled)
                        RelayNode.log.Info(message);
				}

				PerformanceCounterCategory.Create(RelayNodeCounters.PerformanceCategoryName, "Counters for the MySpace Data Relay", PerformanceCounterCategoryType.MultiInstance, counterDataCollection);
				return true;
			}
			catch (Exception ex)
			{
				message = "Error creating Perfomance Counter Category " + RelayNodeCounters.PerformanceCategoryName + ": " + ex.ToString() + ". Counter category will not be used.";
				Console.WriteLine(message);
                if (RelayNode.log.IsErrorEnabled)
                    RelayNode.log.Error(message);
				return false;
			}




		}
示例#6
0
        private static void InitializeCounters()
        {
            try
            {
                var counterDatas =
                    new CounterCreationDataCollection();

                // Create the counters and set their properties.
                var cdCounter1 =
                    new CounterCreationData();
                var cdCounter2 =
                    new CounterCreationData();

                cdCounter1.CounterName = "Total Requests Handled";
                cdCounter1.CounterHelp = "Total number of requests handled";
                cdCounter1.CounterType = PerformanceCounterType.NumberOfItems64;
                cdCounter2.CounterName = "Requests Per Secpmd";
                cdCounter2.CounterHelp = "Average number of requests per second.";
                cdCounter2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;

                // Add both counters to the collection.
                counterDatas.Add(cdCounter1);
                counterDatas.Add(cdCounter2);

                // Create the category and pass the collection to it.
                PerformanceCounterCategory.Create(
                    "Socket Service Data Stats", "Stats for the socket service.",
                    PerformanceCounterCategoryType.MultiInstance, counterDatas);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }
        /// <summary>
        /// Gets the or create counter category.
        /// </summary>
        /// <param name="categoryInfo">The category information.</param>
        /// <param name="counters">The counters.</param>
        /// <returns>PerformanceCounterCategory.</returns>
        private static PerformanceCounterCategory GetOrCreateCounterCategory(
            PerformanceCounterCategoryInfo categoryInfo, CounterCreationData[] counters)
        {
            var creationPending = true;
            var categoryExists = false;
            var categoryName = categoryInfo.CategoryName;
            var counterNames = new HashSet<string>(counters.Select(info => info.CounterName));
            PerformanceCounterCategory category = null;

            if (PerformanceCounterCategory.Exists(categoryName))
            {
                categoryExists = true;
                category = new PerformanceCounterCategory(categoryName);
                var counterList = category.GetCounters();
                if (category.CategoryType == categoryInfo.CategoryType && counterList.Length == counterNames.Count)
                {
                    creationPending = counterList.Any(x => !counterNames.Contains(x.CounterName));
                }
            }

            if (!creationPending) return category;

            if (categoryExists)
                PerformanceCounterCategory.Delete(categoryName);

            var counterCollection = new CounterCreationDataCollection(counters);

            category = PerformanceCounterCategory.Create(
                categoryInfo.CategoryName,
                categoryInfo.CategoryHelp,
                categoryInfo.CategoryType,
                counterCollection);

            return category;
        }
        public void CreatePerformanceCategory()
        {
            const string category = "MikePerfSpike";

            if (!PerformanceCounterCategory.Exists(category))
            {
                var counters = new CounterCreationDataCollection();

                // 1. counter for counting values
                var totalOps = new CounterCreationData
                {
                    CounterName = "# of operations executed",
                    CounterHelp = "Total number of operations that have been executed",
                    CounterType = PerformanceCounterType.NumberOfItems32
                };
                counters.Add(totalOps);

                // 2. counter for counting operations per second
                var opsPerSecond = new CounterCreationData
                {
                    CounterName = "# of operations/second",
                    CounterHelp = "Number of operations per second",
                    CounterType = PerformanceCounterType.RateOfCountsPerSecond32
                };
                counters.Add(opsPerSecond);

                PerformanceCounterCategory.Create(
                    category,
                    "An experiment",
                    PerformanceCounterCategoryType.MultiInstance,
                    counters);
            }
        }
        public static PerformanceCounter CreateCounter(string name, string description, PerformanceCounterType type)
        {
            if (_countersAllowed == false)
            {
                return null;
            }

            string categoryName = Application.ProductName + "." + name;
            if (PerformanceCounterCategory.Exists(categoryName) == false)
            {
                CounterCreationDataCollection counters = new CounterCreationDataCollection();

                CounterCreationData counterData = new CounterCreationData();
                counterData.CounterName = name;
                counterData.CounterHelp = description;
                counterData.CounterType = type;

                counters.Add(counterData);

                PerformanceCounterCategory category = PerformanceCounterCategory.Create(categoryName, "Category for the counters of " + Application.ProductName,
                    PerformanceCounterCategoryType.SingleInstance, counters);
            }

            PerformanceCounter counter = new PerformanceCounter(categoryName, name, string.Empty, false);
            return counter;
        }
示例#10
0
        static PerformanceCounters()
        {
            if (PerformanceCounterCategory.Exists(CategoryName))
                return;

            var counters = new CounterCreationDataCollection
            {
                new CounterCreationData(TotalCommitsName, "Total number of commits persisted", PerformanceCounterType.NumberOfItems32),
                new CounterCreationData(CommitsRateName, "Rate of commits persisted per second", PerformanceCounterType.RateOfCountsPerSecond32),
                new CounterCreationData(AvgCommitDuration, "Average duration for each commit", PerformanceCounterType.AverageTimer32),
                new CounterCreationData(AvgCommitDurationBase, "Average duration base for each commit", PerformanceCounterType.AverageBase),
                new CounterCreationData(TotalEventsName, "Total number of events persisted", PerformanceCounterType.NumberOfItems32),
                new CounterCreationData(EventsRateName, "Rate of events persisted per second", PerformanceCounterType.RateOfCountsPerSecond32),
                new CounterCreationData(TotalSnapshotsName, "Total number of snapshots persisted", PerformanceCounterType.NumberOfItems32),
                new CounterCreationData(SnapshotsRateName, "Rate of snapshots persisted per second", PerformanceCounterType.RateOfCountsPerSecond32),
                new CounterCreationData(UndispatchedQueue, "Undispatched commit queue length", PerformanceCounterType.CountPerTimeInterval32)
            };

            // TODO: add other useful counts such as:
            //
            //	* Total Commit Bytes
            //  * Average Commit Bytes
            //  * Total Queries
            //  * Queries Per Second
            //  * Average Query Duration
            //  * Commits per Query (Total / average / per second)
            //  * Events per Query (Total / average / per second)
            //
            // Some of these will involve hooking into other parts of the EventStore

            PerformanceCounterCategory.Create(CategoryName, "EventStore Event-Sourcing Persistence", PerformanceCounterCategoryType.MultiInstance, counters);
        }
示例#11
0
        static PerformanceCounters()
        {
            try
            {
                if (PerformanceCounterCategory.Exists(category))
                    PerformanceCounterCategory.Delete(category);

                // order to be sure that *Base follows counter
                var props = typeof(PerformanceCounters).GetProperties().OrderBy(p => p.Name).ToList();

                var counterCollection = new CounterCreationDataCollection();

                foreach (var p in props)
                {
                    var attr = (PerformanceCounterTypeAttribute)p.GetCustomAttributes(typeof(PerformanceCounterTypeAttribute), true).First();
                    counterCollection.Add(new CounterCreationData() { CounterName = p.Name, CounterHelp = string.Empty, CounterType = attr.Type });
                }

                PerformanceCounterCategory.Create(category, "Online Trainer Perf Counters", PerformanceCounterCategoryType.MultiInstance, counterCollection);
            }
            catch (Exception e)
            {
                new TelemetryClient().TrackException(e);
            }
        }
        private static bool CreatePerformanceCounters()
        {
            if (!PerformanceCounterCategory.Exists("MyCategory"))
            {
                var counters =
                    new CounterCreationDataCollection
                    {
                        new CounterCreationData(
                            "# operations executed",
                            "Total number of operations executed",
                            PerformanceCounterType.NumberOfItems32),
                        new CounterCreationData(
                            "# operations / sec",
                            "Number of operations executed per second",
                            PerformanceCounterType.RateOfCountsPerSecond32)
                    };

                PerformanceCounterCategory.Create("MyCategory",
                    "Sample category for Codeproject", counters);

                return true;
            }

            return false;
        }
示例#13
0
        private void InitializeClicked(object sender, RoutedEventArgs e)
        {
            if (PerformanceCounterCategory.Exists(CategoryName))
            {
                PerformanceCounterCategory.Delete(CategoryName);
            }
            if (!PerformanceCounterCategory.Exists(CategoryName))
            {
                CounterCreationDataCollection creationDataCollection =
                    new CounterCreationDataCollection();

                CounterCreationData ctrCreationData = new CounterCreationData();
                ctrCreationData.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
                ctrCreationData.CounterName = SpeedCounterName;
                creationDataCollection.Add(ctrCreationData);

                CounterCreationData ctrCreationData2 = new CounterCreationData();
                ctrCreationData2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
                ctrCreationData2.CounterName = SpeedBytesCounterName;
                creationDataCollection.Add(ctrCreationData2);

                PerformanceCounterCategory.Create(CategoryName,
                    "Sample Custom category",
                    PerformanceCounterCategoryType.MultiInstance,
                    creationDataCollection);
            }
            currentContainer = new CountersContainer()
            {
                BytesPerSecCounter = SetupCounter(CategoryName, SpeedCounterName, "Task " + currentTask),
                ItemsPerSecCounter = SetupCounter(CategoryName, SpeedBytesCounterName, "Task " + currentTask)
            };
        }
        public static SyntheticCountersReporter createDefaultReporter(Logger _log, ICounterSamplingConfiguration counterSamplingConfig)
        {
            string signalFxCategory = "SignalFX";

            try
            {
                System.Diagnostics.CounterCreationDataCollection CounterDatas =
                    new System.Diagnostics.CounterCreationDataCollection();

                createCounterIfNotExist(signalFxCategory, "UsedMemory", "Total used memory", System.Diagnostics.PerformanceCounterType.NumberOfItems64, CounterDatas);

                if (CounterDatas.Count != 0)
                {
                    System.Diagnostics.PerformanceCounterCategory.Create(
                        signalFxCategory, "SignalFx synthetic counters.",
                        System.Diagnostics.PerformanceCounterCategoryType.SingleInstance, CounterDatas);
                }
            }
            catch (Exception e)
            {
                _log.Info(e.ToString());
                return(null);
            }

            SyntheticCountersReporter reporter = new SyntheticCountersReporter(counterSamplingConfig);

            reporter._sfxCountersUpdateMethods.Add("UsedMemory", updateUsedMemoryCounter);
            return(reporter);
        }
示例#15
0
 protected InstrumentationManager(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType)
 {
     _categoryName = categoryName;
     _categoryHelp = categoryHelp;
     _categoryType = categoryType;
     _counterDefinitions = new CounterCreationDataCollection();
 }
示例#16
0
        public static void CreateCounter()
        {
            CounterCreationDataCollection col = new CounterCreationDataCollection();

            // Create two custom counter objects.
            CounterCreationData addCounter = new CounterCreationData();
            addCounter.CounterName = "AddCounter";
            addCounter.CounterHelp = "Custom Add counter ";
            addCounter.CounterType = PerformanceCounterType.NumberOfItemsHEX32;

            // Add custom counter objects to CounterCreationDataCollection.
            col.Add(addCounter);

            // Bind the counters to a PerformanceCounterCategory
            // Check if the category already exists or not.
            if (!PerformanceCounterCategory.Exists("MyCategory"))
            {
                PerformanceCounterCategory category =
                PerformanceCounterCategory.Create("MyCategory", "My Perf Category Description ", PerformanceCounterCategoryType.Unknown, col);
            }
            else
            {
                Console.WriteLine("Counter already exists");
            }
        }
        private static void CreateCounters(string groupName)
        {
            if (PerformanceCounterCategory.Exists(groupName))
            {
                PerformanceCounterCategory.Delete(groupName);
            }

            var counters = new CounterCreationDataCollection();

            var totalOps = new CounterCreationData
                               {
                                   CounterName = "Messages Read",
                                   CounterHelp = "Total number of messages read",
                                   CounterType = PerformanceCounterType.NumberOfItems32
                               };
            counters.Add(totalOps);

            var opsPerSecond = new CounterCreationData
                                   {
                                       CounterName = "Messages Read / Sec",
                                       CounterHelp = "Messages read per second",
                                       CounterType = PerformanceCounterType.RateOfCountsPerSecond32
                                   };
            counters.Add(opsPerSecond);

            PerformanceCounterCategory.Create(groupName, "PVC", PerformanceCounterCategoryType.SingleInstance, counters);
        }
        /// <summary>
        /// install thge perfmon counters
        /// </summary>
        public static void InstallCounters()
        {
            if (!PerformanceCounterCategory.Exists(BabaluCounterDescriptions.CounterCategory))
            {
                //Create the collection that will hold
                // the data for the counters we are
                // creating.
                CounterCreationDataCollection counterData = new CounterCreationDataCollection();

                //Create the CreationData object.
                foreach (string counter in BabaluCounterDescriptions.BabaluCounters)
                {
                    CounterCreationData BabaluCounter = new CounterCreationData();

                    // Set the counter's type to NumberOfItems32
                    BabaluCounter.CounterType = PerformanceCounterType.NumberOfItems32;

                    //Set the counter's name
                    BabaluCounter.CounterName = counter;

                    //Add the CreationData object to our
                    //collection
                    counterData.Add(BabaluCounter);
                }

                //Create the counter in the system using the collection.
                PerformanceCounterCategory.Create(BabaluCounterDescriptions.CounterCategory, BabaluCounterDescriptions.CategoryDescription,
                                    PerformanceCounterCategoryType.SingleInstance, counterData);
            }
        }
        private bool SetupCategory()
        {
            // PerformanceCounterCategory.Delete("DCC2012");

            if (!PerformanceCounterCategory.Exists(this.categoryName))
            {
                CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData averageCount64 = new CounterCreationData();
                averageCount64.CounterType = PerformanceCounterType.NumberOfItems32;
                averageCount64.CounterName = "GetData Call Count";
                counterDataCollection.Add(averageCount64);

                CounterCreationData averageCount641 = new CounterCreationData();
                averageCount641.CounterType = PerformanceCounterType.CounterTimer;
                averageCount641.CounterName = "GetData Execution Time";
                counterDataCollection.Add(averageCount641);

                // Create the category.
                PerformanceCounterCategory.Create("DCC2012", "Desert Code Camp.",
                    PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

                return (true);
            }
            else
            {
                Console.WriteLine("Category exists - AverageCounter64SampleCategory");
                return (false);
            }
        }
示例#20
0
		static void Main(string[] args)
		{

			if (PerformanceCounterCategory.Exists("DontStayIn"))
				PerformanceCounterCategory.Delete("DontStayIn");
				
			// Create the collection container
			CounterCreationDataCollection counters = new CounterCreationDataCollection();

			// Create counter #1 and add it to the collection
			CounterCreationData dsiPages = new CounterCreationData();
			dsiPages.CounterName = "DsiPages per sec";
			dsiPages.CounterHelp = "Total number of dsi pages per second.";
			dsiPages.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
			counters.Add(dsiPages);

			// Create counter #3 and add it to the collection
			CounterCreationData genTime = new CounterCreationData();
			genTime.CounterName = "DsiPage generation time";
			genTime.CounterHelp = "Average time to generate a page.";
			genTime.CounterType = PerformanceCounterType.AverageTimer32;
			counters.Add(genTime);

			CounterCreationData genTimeBase = new CounterCreationData();
			genTimeBase.CounterName = "DsiPage generation time base";
			genTimeBase.CounterHelp = "Average time to generate a page base.";
			genTimeBase.CounterType = PerformanceCounterType.AverageBase;
			counters.Add(genTimeBase);

			// Create the category and all of the counters.
			PerformanceCounterCategory.Create("DontStayIn", "Performance counters for DontStayIn.", PerformanceCounterCategoryType.SingleInstance, counters);
			Console.WriteLine("Done!");
			Console.ReadLine();

		}
	// Constructor.
	public PerformanceCounterInstaller()
			{
				categoryHelp = String.Empty;
				categoryName = String.Empty;
				counters = new CounterCreationDataCollection();
				action = UninstallAction.Remove;
			}
        public static SyntheticCountersReporter createDefaultReporter(Logger _log, ICounterSamplingConfiguration counterSamplingConfig)
        {
            string signalFxCategory = "SignalFX";

            try
            {
                System.Diagnostics.CounterCreationDataCollection CounterDatas =
                   new System.Diagnostics.CounterCreationDataCollection();

                createCounterIfNotExist(signalFxCategory, "UsedMemory", "Total used memory", System.Diagnostics.PerformanceCounterType.NumberOfItems64, CounterDatas);

                if (CounterDatas.Count != 0)
                {
                    System.Diagnostics.PerformanceCounterCategory.Create(
                        signalFxCategory, "SignalFx synthetic counters.",
                        System.Diagnostics.PerformanceCounterCategoryType.SingleInstance, CounterDatas);
                }
            }
            catch (Exception e)
            {
                _log.Info(e.ToString());
                return null;
            }

            SyntheticCountersReporter reporter = new SyntheticCountersReporter(counterSamplingConfig);
            reporter._sfxCountersUpdateMethods.Add("UsedMemory", updateUsedMemoryCounter);
            return reporter;
        }
        /// <summary>
        /// Starts the install
        /// </summary>
        public static void InstallCounters()
        {
            Logger.Debug("Starting installation of PerformanceCounters ");

            var categoryName = "NServiceBus";
            var counterName = "Critical Time";

            if (PerformanceCounterCategory.Exists(categoryName))
            {
                Logger.Warn("Category " + categoryName + " already exist, going to delete first");
                PerformanceCounterCategory.Delete(categoryName);
            }
                

            var data = new CounterCreationDataCollection();

            var c1 = new CounterCreationData(counterName, "Age of the oldest message in the queue",
                                             PerformanceCounterType.NumberOfItems32);
            data.Add(c1);

            PerformanceCounterCategory.Create(categoryName, "NServiceBus statistics",
                                              PerformanceCounterCategoryType.MultiInstance, data);

            Logger.Debug("Installation of PerformanceCounters successful.");
        }
示例#24
0
        internal static void Create()
        {
            if (PerformanceCounterCategory.Exists(engineCategory))
            {
                PerformanceCounterCategory.Delete(engineCategory);
            }

            var counterList = new CounterCreationDataCollection();

            counterList.Add(new CounterCreationData(
                dirtyNodeEventCount,
                "Describes the number of dirty node messages on the engine's event queue.",
                PerformanceCounterType.NumberOfItems32));

            counterList.Add(new CounterCreationData(
                calculatedNodeCount,
                "Describes the number of items scheduled for calculation by an engine task.",
                PerformanceCounterType.NumberOfItems32));

            counterList.Add(new CounterCreationData(
                taskExecutionTime,
                @"Describes the time in milliseconds to process an engine task.",
                PerformanceCounterType.NumberOfItems32));

            PerformanceCounterCategory.Create(
                engineCategory,
                "Engine counters",
                PerformanceCounterCategoryType.SingleInstance,
                counterList);
        }
		private void InstallPerformanceCounters()
		{
			if (!PerformanceCounterCategory.Exists("nHydrate"))
			{
				var counters = new CounterCreationDataCollection();

				// 1. counter for counting totals: PerformanceCounterType.NumberOfItems32
				var totalAppointments = new CounterCreationData();
				totalAppointments.CounterName = "# appointments processed";
				totalAppointments.CounterHelp = "Total number of appointments processed.";
				totalAppointments.CounterType = PerformanceCounterType.NumberOfItems32;
				counters.Add(totalAppointments);

				// 2. counter for counting operations per second:
				//        PerformanceCounterType.RateOfCountsPerSecond32
				var appointmentsPerSecond = new CounterCreationData();
				appointmentsPerSecond.CounterName = "# appointments / sec";
				appointmentsPerSecond.CounterHelp = "Number of operations executed per second";
				appointmentsPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
				counters.Add(appointmentsPerSecond);

				// create new category with the counters above
				PerformanceCounterCategory.Create("nHydrate", "nHydrate Category", counters);
			}

		}
        private static void CreateOutboundCategory()
        {
            if (PerformanceCounterCategory.Exists(OutboundPerfomanceCounters.CATEGORY))
            {
                logger.DebugFormat("Deleting existing performance counter category '{0}'.", OutboundPerfomanceCounters.CATEGORY);
                PerformanceCounterCategory.Delete(OutboundPerfomanceCounters.CATEGORY);
            }

            logger.DebugFormat("Creating performance counter category '{0}'.", OutboundPerfomanceCounters.CATEGORY);

            try
            {
                var counters = new CounterCreationDataCollection(OutboundPerfomanceCounters.SupportedCounters().ToArray());
                PerformanceCounterCategory.Create(
                    OutboundPerfomanceCounters.CATEGORY,
                    "Provides statistics for Rhino-Queues messages out-bound from the current machine.",
                    PerformanceCounterCategoryType.MultiInstance,
                    counters);
            }
            catch (Exception ex)
            {
                logger.Error("Creation of outbound counters failed.", ex);
                throw;
            }
        }
示例#27
0
        void CreateCategories()
        {
            try
            {
                if (System.Diagnostics.PerformanceCounterCategory.Exists(counterCategory))
                {
                    return;
                }

                // Create a collection of type CounterCreationDataCollection.
                System.Diagnostics.CounterCreationDataCollection CounterDatas = new System.Diagnostics.CounterCreationDataCollection();
                // Create the counters and set their properties.

                System.Diagnostics.CounterCreationData cdCounter1 = new System.Diagnostics.CounterCreationData()
                {
                    CounterName = "In Call",
                    CounterHelp = "Number of simultaneous messages submitted from the BizTalk Benchmark Wizard application",
                    CounterType = System.Diagnostics.PerformanceCounterType.NumberOfItems64
                };
                System.Diagnostics.CounterCreationData cdCounter2 = new System.Diagnostics.CounterCreationData()
                {
                    CounterName = "Call Time",
                    CounterHelp = "Elasped time for call (msecs)",
                    CounterType = System.Diagnostics.PerformanceCounterType.NumberOfItems64
                };
                System.Diagnostics.CounterCreationData cdCounter3 = new System.Diagnostics.CounterCreationData()
                {
                    CounterName = "Total Calls",
                    CounterHelp = "Total number of messages submitted from the BizTalk Benchmark Wizard application",
                    CounterType = System.Diagnostics.PerformanceCounterType.NumberOfItems64
                };
                System.Diagnostics.CounterCreationData cdCounter4 = new System.Diagnostics.CounterCreationData()
                {
                    CounterName = "Calls/sec",
                    CounterHelp = "Number of messages submitted from the BizTalk Benchmark Wizard application",
                    CounterType = System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond32
                };

                // Add both counters to the collection.
                CounterDatas.Add(cdCounter1);
                CounterDatas.Add(cdCounter2);
                CounterDatas.Add(cdCounter3);
                CounterDatas.Add(cdCounter4);

                // Create the category and pass the collection to it.
                //if (System.Diagnostics.PerformanceCounterCategory.Exists(counterCategory))
                //    System.Diagnostics.PerformanceCounterCategory.Delete(counterCategory);

                PerformanceCounterCategory cat = System.Diagnostics.PerformanceCounterCategory.Create(
                    counterCategory,
                    counterCategory,
                    PerformanceCounterCategoryType.MultiInstance,
                    CounterDatas);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool CreatePerformanceCounters()
        {
            string categoryName = "WebSocketListener_Test";

            if (!PerformanceCounterCategory.Exists(categoryName))
            {
                var ccdc = new CounterCreationDataCollection();

                ccdc.Add(new CounterCreationData
                {
                    CounterType = PerformanceCounterType.RateOfCountsPerSecond64,
                    CounterName = pflabel_msgIn
                });

                ccdc.Add(new CounterCreationData
                {
                    CounterType = PerformanceCounterType.RateOfCountsPerSecond64,
                    CounterName = pflabel_msgOut
                });

                ccdc.Add(new CounterCreationData
                {
                    CounterType = PerformanceCounterType.NumberOfItems64,
                    CounterName = pflabel_connected
                });

                ccdc.Add(new CounterCreationData
                {
                    CounterType = PerformanceCounterType.AverageTimer32,
                    CounterName = pflabel_delay
                });

                ccdc.Add(new CounterCreationData
                {
                    CounterType = PerformanceCounterType.AverageBase,
                    CounterName = pflabel_delay + " base"
                });

                PerformanceCounterCategory.Create(categoryName, "", PerformanceCounterCategoryType.SingleInstance, ccdc);

                Console.WriteLine("Performance counters have been created, please re-run the app");
                return true;
            }
            else
            {
                //PerformanceCounterCategory.Delete(categoryName);
                //Console.WriteLine("Delete");
                //return true;

                MessagesIn = new PerformanceCounter(categoryName, pflabel_msgIn, false);
                MessagesOut = new PerformanceCounter(categoryName, pflabel_msgOut, false);
                Connected = new PerformanceCounter(categoryName, pflabel_connected, false);
                Delay = new PerformanceCounter(categoryName, pflabel_delay, false);
                DelayBase = new PerformanceCounter(categoryName, pflabel_delay + " base", false);
                Connected.RawValue = 0;

                return false;
            }
        }
    public static System.Diagnostics.PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData)
    {
      Contract.Ensures(0 <= categoryName.Length);
      Contract.Ensures(categoryName.Length <= 997);
      Contract.Ensures(Contract.Result<System.Diagnostics.PerformanceCounterCategory>() != null);

      return default(System.Diagnostics.PerformanceCounterCategory);
    }
 public void CreateBadCounters()
 {
     var counters = new CounterCreationDataCollection
                    {
                        new CounterCreationData("Critical Time","Age of the oldest message in the queue.",PerformanceCounterType.NumberOfItems32),
                    };
     PerformanceCounterCategory.Create("NServiceBus", "NServiceBus statistics", PerformanceCounterCategoryType.MultiInstance, counters);
 }
        public void AddCounterToCollection(CounterCreationDataCollection counterData)
        {
            CounterCreationData counterCreationData = new CounterCreationData(
                _counterName, 
                _counterHelp, 
                _pcType);

            counterData.Add(counterCreationData);
        }
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void AddRange(CounterCreationDataCollection value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     int currentCount = value.Count;
     for (int i = 0; i < currentCount; i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
        public static void installPerformanceCounter()
        {
            CounterCreationDataCollection CounterDatas = new System.Diagnostics.CounterCreationDataCollection();
            CounterCreationData           cdCounter1   = new System.Diagnostics.CounterCreationData();

            try {
                cdCounter1.CounterName = "Messages Per Second";
                cdCounter1.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
                CounterDatas.Add(cdCounter1);
                if (!((PerformanceCounterCategory.Exists("netSmtpMail"))))
                {
                    PerformanceCounterCategory.Create("netSmtpMail", "", CounterDatas);
                }
            } catch (Exception e) {
                throw (e);
            }
        }
示例#34
0
 public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData)
 {
     throw new NotImplementedException();
 }
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public CounterCreationDataCollection(CounterCreationDataCollection value)
 {
     this.AddRange(value);
 }
 private static void CreateIniFile(string categoryName, string categoryHelp, CounterCreationDataCollection creationData, string[] languageIds)
 {
     new FileIOPermission(PermissionState.Unrestricted).Assert();
     try
     {
         StreamWriter writer = new StreamWriter(IniFilePath, false, Encoding.Unicode);
         try
         {
             writer.WriteLine("");
             writer.WriteLine("[info]");
             writer.Write("drivername");
             writer.Write("=");
             writer.WriteLine(categoryName);
             writer.Write("symbolfile");
             writer.Write("=");
             writer.WriteLine(Path.GetFileName(SymbolFilePath));
             writer.WriteLine("");
             writer.WriteLine("[languages]");
             foreach (string str in languageIds)
             {
                 writer.Write(str);
                 writer.Write("=");
                 writer.Write("language");
                 writer.WriteLine(str);
             }
             writer.WriteLine("");
             writer.WriteLine("[objects]");
             foreach (string str2 in languageIds)
             {
                 writer.Write("OBJECT_");
                 writer.Write("1_");
                 writer.Write(str2);
                 writer.Write("_NAME");
                 writer.Write("=");
                 writer.WriteLine(categoryName);
             }
             writer.WriteLine("");
             writer.WriteLine("[text]");
             foreach (string str3 in languageIds)
             {
                 writer.Write("OBJECT_");
                 writer.Write("1_");
                 writer.Write(str3);
                 writer.Write("_NAME");
                 writer.Write("=");
                 writer.WriteLine(categoryName);
                 writer.Write("OBJECT_");
                 writer.Write("1_");
                 writer.Write(str3);
                 writer.Write("_HELP");
                 writer.Write("=");
                 if ((categoryHelp == null) || (categoryHelp == string.Empty))
                 {
                     writer.WriteLine(SR.GetString("HelpNotAvailable"));
                 }
                 else
                 {
                     writer.WriteLine(categoryHelp);
                 }
                 int num = 0;
                 foreach (CounterCreationData data in creationData)
                 {
                     num++;
                     writer.WriteLine("");
                     writer.Write("DEVICE_COUNTER_");
                     writer.Write(num.ToString(CultureInfo.InvariantCulture));
                     writer.Write("_");
                     writer.Write(str3);
                     writer.Write("_NAME");
                     writer.Write("=");
                     writer.WriteLine(data.CounterName);
                     writer.Write("DEVICE_COUNTER_");
                     writer.Write(num.ToString(CultureInfo.InvariantCulture));
                     writer.Write("_");
                     writer.Write(str3);
                     writer.Write("_HELP");
                     writer.Write("=");
                     writer.WriteLine(data.CounterHelp);
                 }
             }
             writer.WriteLine("");
         }
         finally
         {
             writer.Close();
         }
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
 }
        private static void CreateRegistryEntry(string categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, ref bool iniRegistered)
        {
            RegistryKey key  = null;
            RegistryKey key2 = null;
            RegistryKey key3 = null;

            new RegistryPermission(PermissionState.Unrestricted).Assert();
            try
            {
                key  = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services", true);
                key2 = key.OpenSubKey(categoryName + @"\Performance", true);
                if (key2 == null)
                {
                    key2 = key.CreateSubKey(categoryName + @"\Performance");
                }
                key2.SetValue("Open", "OpenPerformanceData");
                key2.SetValue("Collect", "CollectPerformanceData");
                key2.SetValue("Close", "ClosePerformanceData");
                key2.SetValue("Library", "netfxperf.dll");
                key2.SetValue("IsMultiInstance", (int)categoryType, RegistryValueKind.DWord);
                key2.SetValue("CategoryOptions", 3, RegistryValueKind.DWord);
                string[] strArray  = new string[creationData.Count];
                string[] strArray2 = new string[creationData.Count];
                for (int i = 0; i < creationData.Count; i++)
                {
                    strArray[i]  = creationData[i].CounterName;
                    strArray2[i] = ((int)creationData[i].CounterType).ToString(CultureInfo.InvariantCulture);
                }
                key3 = key.OpenSubKey(categoryName + @"\Linkage", true);
                if (key3 == null)
                {
                    key3 = key.CreateSubKey(categoryName + @"\Linkage");
                }
                key3.SetValue("Export", new string[] { categoryName });
                key2.SetValue("Counter Types", strArray2);
                key2.SetValue("Counter Names", strArray);
                if (key2.GetValue("First Counter") != null)
                {
                    iniRegistered = true;
                }
                else
                {
                    iniRegistered = false;
                }
            }
            finally
            {
                if (key2 != null)
                {
                    key2.Close();
                }
                if (key3 != null)
                {
                    key3.Close();
                }
                if (key != null)
                {
                    key.Close();
                }
                CodeAccessPermission.RevertAssert();
            }
        }
 internal static void RegisterCategory(string categoryName, PerformanceCounterCategoryType categoryType, string categoryHelp, CounterCreationDataCollection creationData)
 {
     try
     {
         bool iniRegistered = false;
         CreateRegistryEntry(categoryName, categoryType, creationData, ref iniRegistered);
         if (!iniRegistered)
         {
             string[] languageIds = GetLanguageIds();
             CreateIniFile(categoryName, categoryHelp, creationData, languageIds);
             CreateSymbolFile(creationData);
             RegisterFiles(IniFilePath, false);
         }
         CloseAllTables();
         CloseAllLibraries();
     }
     finally
     {
         DeleteTemporaryFiles();
     }
 }
示例#39
0
 public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, CounterCreationDataCollection counterData)
 {
     return(Create(categoryName, categoryHelp, PerformanceCounterCategoryType.Unknown, counterData));
 }
示例#40
0
        public static PerformanceCounterCategory Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData)
        {
            if (categoryType < PerformanceCounterCategoryType.Unknown || categoryType > PerformanceCounterCategoryType.MultiInstance)
            {
                throw new ArgumentOutOfRangeException(nameof(categoryType));
            }
            if (counterData == null)
            {
                throw new ArgumentNullException(nameof(counterData));
            }

            CheckValidCategory(categoryName);
            if (categoryHelp != null)
            {
                // null categoryHelp is a valid option - it gets set to "Help Not Available" later on.
                CheckValidHelp(categoryHelp);
            }
            string machineName = ".";

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer, machineName, categoryName);

            permission.Demand();

            Mutex mutex = null;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                SharedUtils.EnterMutex(PerfMutexName, ref mutex);
                if (PerformanceCounterLib.IsCustomCategory(machineName, categoryName) || PerformanceCounterLib.CategoryExists(machineName, categoryName))
                {
                    throw new InvalidOperationException(SR.Format(SR.PerformanceCategoryExists, categoryName));
                }

                CheckValidCounterLayout(counterData);
                PerformanceCounterLib.RegisterCategory(categoryName, categoryType, categoryHelp, counterData);
                return(new PerformanceCounterCategory(categoryName, machineName));
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.ReleaseMutex();
                    mutex.Close();
                }
            }
        }
示例#41
0
        internal static void CheckValidCounterLayout(CounterCreationDataCollection counterData)
        {
            // Ensure that there are no duplicate counter names being created
            Hashtable h = new Hashtable();

            for (int i = 0; i < counterData.Count; i++)
            {
                if (counterData[i].CounterName == null || counterData[i].CounterName.Length == 0)
                {
                    throw new ArgumentException(SR.Format(SR.InvalidCounterName));
                }

                int currentSampleType = (int)counterData[i].CounterType;
                if ((currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_AVERAGE_BULK) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_100NSEC_MULTI_TIMER) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_100NSEC_MULTI_TIMER_INV) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_COUNTER_MULTI_TIMER) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_COUNTER_MULTI_TIMER_INV) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_RAW_FRACTION) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_SAMPLE_FRACTION) ||
                    (currentSampleType == Interop.Kernel32.PerformanceCounterOptions.PERF_AVERAGE_TIMER))
                {
                    if (counterData.Count <= (i + 1))
                    {
                        throw new InvalidOperationException(SR.Format(SR.CounterLayout));
                    }
                    else
                    {
                        currentSampleType = (int)counterData[i + 1].CounterType;


                        if (!PerformanceCounterLib.IsBaseCounter(currentSampleType))
                        {
                            throw new InvalidOperationException(SR.Format(SR.CounterLayout));
                        }
                    }
                }
                else if (PerformanceCounterLib.IsBaseCounter(currentSampleType))
                {
                    if (i == 0)
                    {
                        throw new InvalidOperationException(SR.Format(SR.CounterLayout));
                    }
                    else
                    {
                        currentSampleType = (int)counterData[i - 1].CounterType;

                        if (
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_AVERAGE_BULK) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_100NSEC_MULTI_TIMER) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_100NSEC_MULTI_TIMER_INV) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_COUNTER_MULTI_TIMER) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_COUNTER_MULTI_TIMER_INV) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_RAW_FRACTION) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_SAMPLE_FRACTION) &&
                            (currentSampleType != Interop.Kernel32.PerformanceCounterOptions.PERF_AVERAGE_TIMER))
                        {
                            throw new InvalidOperationException(SR.Format(SR.CounterLayout));
                        }
                    }
                }

                if (h.ContainsKey(counterData[i].CounterName))
                {
                    throw new ArgumentException(SR.Format(SR.DuplicateCounterName, counterData[i].CounterName));
                }
                else
                {
                    h.Add(counterData[i].CounterName, string.Empty);

                    // Ensure that all counter help strings aren't null or empty
                    if (counterData[i].CounterHelp == null || counterData[i].CounterHelp.Length == 0)
                    {
                        counterData[i].CounterHelp = counterData[i].CounterName;
                    }
                }
            }
        }
        private static void createCounterIfNotExist(string categoryName, string counterName, string counterHelp, System.Diagnostics.PerformanceCounterType type, System.Diagnostics.CounterCreationDataCollection counterDatas)
        {
            if (!System.Diagnostics.PerformanceCounterCategory.Exists(categoryName) ||
                !System.Diagnostics.PerformanceCounterCategory.CounterExists(counterName, categoryName))
            {
                System.Diagnostics.CounterCreationData counter =
                    new System.Diagnostics.CounterCreationData();
                counter.CounterName = counterName;
                counter.CounterHelp = counterHelp;
                counter.CounterType = type;

                counterDatas.Add(counter);
            }
        }