Esempio n. 1
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);
            }
        }
Esempio n. 2
0
    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))
        {
            CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageCount64 = new CounterCreationData();
            averageCount64.CounterType = PerformanceCounterType.AverageCount64;
            averageCount64.CounterName = "AverageCounter64Sample";
            counterDataCollection.Add(averageCount64);

            // Add the base counter.
            CounterCreationData averageCount64Base = new CounterCreationData();
            averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
            averageCount64Base.CounterName = "AverageCounter64SampleBase";
            counterDataCollection.Add(averageCount64Base);

            // Create the category.
            PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                                              "Demonstrates usage of the AverageCounter64 performance counter type.",
                                              PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - AverageCounter64SampleCategory");
            return(false);
        }
    }
    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("AverageTimer32SampleCategory"))
        {
            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageTimer32 = new CounterCreationData();
            averageTimer32.CounterType = PerformanceCounterType.AverageTimer32;
            averageTimer32.CounterName = "AverageTimer32Sample";
            CCDC.Add(averageTimer32);

            // Add the base counter.
            CounterCreationData averageTimer32Base = new CounterCreationData();
            averageTimer32Base.CounterType = PerformanceCounterType.AverageBase;
            averageTimer32Base.CounterName = "AverageTimer32SampleBase";
            CCDC.Add(averageTimer32Base);

            // Create the category.
            PerformanceCounterCategory.Create("AverageTimer32SampleCategory",
                                              "Demonstrates usage of the AverageTimer32 performance counter type",
                                              CCDC);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - " + "AverageTimer32SampleCategory");
            return(false);
        }
    }
Esempio n. 4
0
    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("SampleFractionCategory"))
        {
            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData sampleFraction = new CounterCreationData();
            sampleFraction.CounterType = PerformanceCounterType.SampleFraction;
            sampleFraction.CounterName = "SampleFractionSample";
            CCDC.Add(sampleFraction);

            // Add the base counter.
            CounterCreationData sampleFractionBase = new CounterCreationData();
            sampleFractionBase.CounterType = PerformanceCounterType.SampleBase;
            sampleFractionBase.CounterName = "SampleFractionSampleBase";
            CCDC.Add(sampleFractionBase);

            // Create the category.
            PerformanceCounterCategory.Create("SampleFractionCategory",
                                              "Demonstrates usage of the SampleFraction performance counter type.",
                                              PerformanceCounterCategoryType.SingleInstance, CCDC);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - SampleFractionCategory");
            return(false);
        }
    }
Esempio n. 5
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());
            }
        }
Esempio n. 6
0
        public static void CreatingPerformanceCounters()
        {
            //1.Verify if the category exists
            if (!PerformanceCounterCategory.Exists("myCounterCategory"))
            {
                //2. Create a counter Collection
                CounterCreationDataCollection myCounterCollection = new CounterCreationDataCollection();

                //3. Create counters and add them to the collection
                CounterCreationData myCounter01 = new CounterCreationData();
                myCounter01.CounterName = "Counter01";
                myCounter01.CounterHelp = "Total number of something done";
                myCounter01.CounterType = PerformanceCounterType.NumberOfItems32;
                myCounterCollection.Add(myCounter01);

                CounterCreationData myCounter02 = new CounterCreationData();
                myCounter02.CounterName = "Counter02";
                myCounter02.CounterHelp = "Total number of something not done";
                myCounter02.CounterType = PerformanceCounterType.NumberOfItems32;
                myCounterCollection.Add(myCounter02);


                //4. Create a new category
                PerformanceCounterCategory.Create("myCounterCategory", "Count something done and not done", myCounterCollection);
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {// TODO 1: email this to Mai
            CounterCreationDataCollection counters = new CounterCreationDataCollection();

            CounterCreationData totalOrders = new CounterCreationData();

            totalOrders.CounterName = "# Orders";
            totalOrders.CounterHelp = "Total number of orders placed";
            totalOrders.CounterType = PerformanceCounterType.NumberOfItems32;

            CounterCreationData ordersPerSecond = new CounterCreationData();

            ordersPerSecond.CounterName = "# Orders/Sec";
            ordersPerSecond.CounterHelp = "Number of orders placed per second";
            ordersPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;

            counters.Add(totalOrders);
            counters.Add(ordersPerSecond);

            // needs elevated permissions to create the counter on the windows machine
            PerformanceCounterCategory.Create("MyOrdersCategories", "A sample demonstration", PerformanceCounterCategoryType.SingleInstance, counters);

            // call order coffee
            Program p = new Program();

            p.OrderCoffee();
        }
    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists(categoryName))
        {
            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageTimer32 = new CounterCreationData();
            averageTimer32.CounterType = PerformanceCounterType.AverageTimer32;
            averageTimer32.CounterName = counterName;
            CCDC.Add(averageTimer32);

            // Add the base counter.
            CounterCreationData averageTimer32Base = new CounterCreationData();
            averageTimer32Base.CounterType = PerformanceCounterType.AverageBase;
            averageTimer32Base.CounterName = baseCounterName;
            CCDC.Add(averageTimer32Base);

            // Create the category.
            PerformanceCounterCategory.Create(categoryName,
                                              "Demonstrates usage of the AverageTimer32 performance counter type",
                                              PerformanceCounterCategoryType.SingleInstance, CCDC);

            Console.WriteLine("Category created - " + categoryName);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - " + categoryName);
            return(false);
        }
    }
Esempio n. 9
0
        private static bool SetupCategory()
        {
            if (!PerformanceCounterCategory.Exists("Memory"))
            {
                CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData memory = new CounterCreationData();
                memory.CounterType = PerformanceCounterType.NumberOfItems32;
                memory.CounterName = "Memory";
                CCDC.Add(memory);

                // Add the base counter.
                CounterCreationData averageCount64Base = new CounterCreationData();
                averageCount64Base.CounterType = PerformanceCounterType.MemoryBase;
                averageCount64Base.CounterName = "AverageCounter64SampleBase";
                CCDC.Add(averageCount64Base);

                // Create the category.
                PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                                                  "Demonstrates usage of the AverageCounter64 performance counter type.",
                                                  PerformanceCounterCategoryType.SingleInstance, CCDC);

                return(true);
            }
            else
            {
                Console.WriteLine("Category exists - AverageCounter64SampleCategory");
                return(false);
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            if (!PerformanceCounterCategory.Exists("ShoppingCounter"))
            {
                CounterCreationDataCollection counters = new CounterCreationDataCollection();
                // *1.contador para contar totais(ShoppingDone): PerformanceCounterType.NumberOfItems32 * /
                CounterCreationData totalDone = new CounterCreationData();
                totalDone.CounterName = "ShoppingDone";
                totalDone.CounterHelp = "Número total de compras concluídas";
                totalDone.CounterType = PerformanceCounterType.NumberOfItems32;
                counters.Add(totalDone);

                // 2.contador para contar totais(ShoppingNotDone): PerformanceCounterType.NumberOfItems32
                CounterCreationData totalNotDone = new CounterCreationData();
                totalNotDone.CounterName = "ShoppingNotDone";
                totalNotDone.CounterHelp = "Número total de compras não concluídas";
                totalNotDone.CounterType = PerformanceCounterType.NumberOfItems32;
                counters.Add(totalNotDone);

                // cria uma nova categoria com os contadores acima
                var texto = "Os balcões de compras ajudam a montar quantas compras são feitas e como muitos não são.";
                PerformanceCounterCategory.Create("ShoppingCounter", texto,
                                                  PerformanceCounterCategoryType.SingleInstance, counters);
                Console.WriteLine("Contador de desempenho criado.");
            }
            else
            {
                Console.WriteLine("Contador de desempenho já criado.");
            }

            Console.ReadKey();
        }
Esempio n. 11
0
        /// <summary>
        /// This routine installs the performance counters on the local machine.  Requires administrative privledges to run.
        /// </summary>
        public virtual void InstallPerformanceCounters()
        {
            try
            {
                CounterCreationDataCollection counterCreationDataCollection = new CounterCreationDataCollection();
                CounterCreationData           transactionsPerSecond         = new CounterCreationData("Transactions/Second", "Transactions per second,", PerformanceCounterType.RateOfCountsPerSecond32);
                CounterCreationData           totalTransactions             = new CounterCreationData("Total Transactions", "Total number of transactions the application has processed since it started,", PerformanceCounterType.NumberOfItems32);
                CounterCreationData           dailyTransactions             = new CounterCreationData("Daily Transactions", "Total number of transactions the application has processed today,", PerformanceCounterType.NumberOfItems32);
                CounterCreationData           runningThreads = new CounterCreationData("Running Threads", "The current number of executing threads,", PerformanceCounterType.NumberOfItems32);

                counterCreationDataCollection.Add(transactionsPerSecond);
                counterCreationDataCollection.Add(totalTransactions);
                counterCreationDataCollection.Add(dailyTransactions);
                counterCreationDataCollection.Add(runningThreads);

                if (!PerformanceCounterCategory.Exists(CounterCategory))
                {
                    PerformanceCounterCategory.Create(CounterCategory, CounterCategoryHelp,
                                                      PerformanceCounterCategoryType.SingleInstance, counterCreationDataCollection);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError(ex.ToString());
                throw;
            }
        }
        internal static bool RegisterPerformanceCounters(IEnumerable <TelemetryData> data)
        {
            int registeredCategories = 0;

            foreach (var categoryGroup in data.GroupBy(x => x.Category))
            {
                if (!PerformanceCounterCategory.Exists(categoryGroup.Key))
                {
                    var counterData = new CounterCreationDataCollection();
                    foreach (var item in data)
                    {
                        counterData.Add(new CounterCreationData(item.Name, "", item.DataTypeToCounterType()));

                        // Base PC name convention: keep in sync with code in PerformanceCounterHolderCollection
                        if (item.CounterType == TelemetryDataType.AverageCount)
                        {
                            counterData.Add(new CounterCreationData(item.Name + "Base", "", PerformanceCounterType.AverageBase));
                        }
                    }

                    PerformanceCounterCategory.Create(categoryGroup.Key, "", PerformanceCounterCategoryType.SingleInstance, counterData);

                    ++registeredCategories;
                }
            }

            return(registeredCategories > 0);
        }
        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);
            }
        }
        public void PerformanceCounterCategory_CreateCategory()
        {
            WriteLine("PerformanceCounterCategory_CreateCategory");

            var    guid = Guid.NewGuid().ToString("N");
            string name = "AverageCounter64Sample" + guid;

            Assert.False(PerformanceCounterCategory.Exists(name + "Category"));

            CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageCount64 = new CounterCreationData();

            averageCount64.CounterType = PerformanceCounterType.AverageCount64;
            averageCount64.CounterName = name;
            counterDataCollection.Add(averageCount64);

            // Add the base counter.
            CounterCreationData averageCount64Base = new CounterCreationData();

            averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
            averageCount64Base.CounterName = name + "Base";
            counterDataCollection.Add(averageCount64Base);

            // Create the category.
            PerformanceCounterCategory.Create(name + "Category",
                                              "Demonstrates usage of the AverageCounter64 performance counter type.",
                                              PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

            Assert.True(PerformanceCounterCategory.Exists(name + "Category"));

            WriteLine("PerformanceCounterCategory_CreateCategory end");
        }
Esempio n. 15
0
        public static void CreateCounters2()
        {
            if (!PerformanceCounterCategory.Exists("Kanters"))
            {
                var counters = new CounterCreationDataCollection();

                var ccdCounter1 = new CounterCreationData
                {
                    CounterName = "First",
                    CounterType = PerformanceCounterType.SampleFraction
                };
                counters.Add(ccdCounter1);
                var ccdCounter2 = new CounterCreationData
                {
                    CounterName = "Second",
                    CounterType = PerformanceCounterType.SampleBase
                };
                counters.Add(ccdCounter2);

                PerformanceCounterCategory.Create(
                    "Kanters",
                    "Desc",
                    PerformanceCounterCategoryType.MultiInstance,
                    counters);
            }
        }
Esempio n. 16
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)
            };
        }
        internal Common()
        {
            guid     = Guid.NewGuid().ToString("N");
            name     = guid + "_Counter";
            category = name + "_Category";
            counterDataCollection = new CounterCreationDataCollection();

            // Add the counter.
            counter             = new CounterCreationData();
            counter.CounterType = PerformanceCounterType.AverageCount64;
            counter.CounterName = name;
            counterDataCollection.Add(counter);

            // Add the base counter.
            counterBase             = new CounterCreationData();
            counterBase.CounterType = PerformanceCounterType.AverageBase;
            baseName = name + "Base";
            counterBase.CounterName = baseName;
            counterDataCollection.Add(counterBase);

            // Create the category.
            PerformanceCounterCategory.Create(category, "description",
                                              PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

            counterSample = new PerformanceCounter(category, name, false);

            counterSample.RawValue = 0;

            pcc = new PerformanceCounterCategory(category);
        }
        public void Install(WindowsIdentity identity)
        {
            Console.WriteLine("Starting installation of PerformanceCounters ");

            var categoryName = "NServiceBus";

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


            var data = new CounterCreationDataCollection();

            data.Add(new CounterCreationData("Critical Time", "Age of the oldest message in the queue",
                                             PerformanceCounterType.NumberOfItems32));

            data.Add(new CounterCreationData("SLA violation countdown", "Seconds until the SLA for this endpoint is breached",
                                             PerformanceCounterType.NumberOfItems32));

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

            Console.WriteLine("Installation of PerformanceCounters successful.");
        }
Esempio n. 19
0
        public static void Initialize()
        {
            CounterCreationDataCollection counters = new CounterCreationDataCollection();
            CounterCreationData           counter  = new CounterCreationData(
                "Total Files Copied", "Total number of files copied by the application.",
                PerformanceCounterType.NumberOfItems32);

            counters.Add(counter);
            counter = new CounterCreationData(
                "% Files Copied", "Percent of files copied in the current operation.",
                PerformanceCounterType.NumberOfItems32);
            counters.Add(counter);

            if (PerformanceCounterCategory.Exists("FileCopier"))
            {
                PerformanceCounterCategory.Delete("FileCopier");
            }

            PerformanceCounterCategory.Create("FileCopier",
                                              "Instrumentation of the FileCopier application.",
                                              PerformanceCounterCategoryType.SingleInstance,
                                              counters);

            _totalFilesCounter = new PerformanceCounter(
                "FileCopier", "Total Files Copied", false);
            _percentDoneCounter = new PerformanceCounter(
                "FileCopier", "% Files Copied", false);
        }
Esempio n. 20
0
        private static bool SetupCategory()
        {
            if (!PerformanceCounterCategory.Exists("CShaerpExamPerformanceCounterTest"))
            {
                CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData averageCount64 = new CounterCreationData();
                averageCount64.CounterType = PerformanceCounterType.AverageCount64;
                averageCount64.CounterName = "AverageCounter64Sample";
                counterDataCollection.Add(averageCount64);

                // Add the base counter.
                CounterCreationData averageCount64Base = new CounterCreationData();
                averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
                averageCount64Base.CounterName = "AverageCounter64SampleBase";
                counterDataCollection.Add(averageCount64Base);

                // Create the category.
                PerformanceCounterCategory.Create("CShaerpExamPerformanceCounterTest",
                                                  "Demonstrates usage of the AverageCounter64 performance counter type.",
                                                  PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

                // When monitoring performance later, you will see how both counters work together.
                // It is important to know that the supporting counter always must follow the counter which will monitor performance!

                return(true);
            }
            else
            {
                Console.WriteLine("Category exists - CShaerpExamPerformanceCounterTest");
                return(false);
            }
        }
        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);
            }
        }
Esempio n. 22
0
        private void CreatePerformanceCounter()
        {
            CounterCreationDataCollection counters = new CounterCreationDataCollection();

            CounterCreationData configVersionPerSecond = new CounterCreationData();

            configVersionPerSecond.CounterName = CONFIG_VERSION_COUNTER;
            configVersionPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
            configVersionPerSecond.CounterHelp = "configuration version response count per second";
            counters.Add(configVersionPerSecond);

            CounterCreationData resourceMgrPerSecond = new CounterCreationData();

            resourceMgrPerSecond.CounterName = RESOURCE_MGR_COUNTER;
            resourceMgrPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
            resourceMgrPerSecond.CounterHelp = "resource manager response count per second";
            counters.Add(resourceMgrPerSecond);

            CounterCreationData configMgrPerSecond = new CounterCreationData();

            configMgrPerSecond.CounterName = CONFIG_MGR_COUNTER;
            configMgrPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
            configMgrPerSecond.CounterHelp = "configuration management response count per second";
            counters.Add(configMgrPerSecond);

            PerformanceCounterCategory.Create(REMOTE_CONFIGURATION,
                                              "Remote Configuration Management Counter",
                                              PerformanceCounterCategoryType.SingleInstance, counters);
        }
Esempio n. 23
0
        public static void CreateCategory()
        {
            if (!PerformanceCounterCategory.Exists("MentoringCategory"))
            {
                var counterCollection = new CounterCreationDataCollection();

                //log in counter
                var logInCounter = new CounterCreationData();
                logInCounter.CounterType = PerformanceCounterType.NumberOfItems32;
                logInCounter.CounterName = "LogInCounter";
                counterCollection.Add(logInCounter);

                var logOutCounter = new CounterCreationData();
                logOutCounter.CounterType = PerformanceCounterType.NumberOfItems32;
                logOutCounter.CounterName = "LogOutCounter";
                counterCollection.Add(logOutCounter);

                var homePageVisitCounter = new CounterCreationData();
                homePageVisitCounter.CounterType = PerformanceCounterType.NumberOfItems32;
                homePageVisitCounter.CounterName = "HomePageVisitCounter";
                counterCollection.Add(homePageVisitCounter);

                PerformanceCounterCategory.Create("MentoringCategory", "MentoringCategory", PerformanceCounterCategoryType.SingleInstance, counterCollection);
            }
        }
Esempio n. 24
0
        public static void PerformanceCounterCategory_CreateCategory()
        {
            if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))
            {
                CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData averageCount64 = new CounterCreationData();
                averageCount64.CounterType = PerformanceCounterType.AverageCount64;
                averageCount64.CounterName = "AverageCounter64Sample";
                counterDataCollection.Add(averageCount64);

                // Add the base counter.
                CounterCreationData averageCount64Base = new CounterCreationData();
                averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
                averageCount64Base.CounterName = "AverageCounter64SampleBase";
                counterDataCollection.Add(averageCount64Base);

                // Create the category.
                PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                                                  "Demonstrates usage of the AverageCounter64 performance counter type.",
                                                  PerformanceCounterCategoryType.SingleInstance, counterDataCollection);
            }

            Assert.True(PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"));
            PerformanceCounterCategory.Delete("AverageCounter64SampleCategory");
        }
Esempio n. 25
0
        /// <summary>
        /// Instala la categoría y sus contadores asociados en la máquina
        /// </summary>
        /// <param name="category">Categoría a instalar</param>
        private static void InstallPerformanceCounterCategory(CounterCategoryData category)
        {
            CounterCreationDataCollection counterDataCol = new CounterCreationDataCollection();

            foreach (CounterData counterData in category.GetAllCounters())
            {
                CounterCreationData creationData;

                creationData = new CounterCreationData(
                    counterData.Name,
                    counterData.Description,
                    counterData.Type);
                counterDataCol.Add(creationData);

                if (counterData.HasBaseCounter)
                {
                    creationData = new CounterCreationData(
                        counterData.BaseName,
                        counterData.BaseDescription,
                        counterData.BaseType);
                    counterDataCol.Add(creationData);
                }
            }

            try
            {
                PerformanceCounterCategory.Create(category.Name, category.Description,
                                                  category.Type, counterDataCol);
            }
            catch (SecurityException uex)
            {
                throw new InstrumentationException(string.Format(
                                                       Messages.InsufficientPermissionsForCounterCategoryCreation, category.Name), uex);
            }
        }
Esempio n. 26
0
        //<Snippet4>
        public static void CreateCounters()
        {
            //<Snippet2>
            CounterCreationData data1 = new CounterCreationData("Trucks",
                                                                "Number of orders", PerformanceCounterType.NumberOfItems32);
            CounterCreationData data2 = new CounterCreationData("Rate of sales",
                                                                "Orders/second", PerformanceCounterType.RateOfCountsPerSecond32);
            CounterCreationDataCollection ccds = new CounterCreationDataCollection();

            ccds.Add(data1);
            ccds.Add(data2);
            Console.WriteLine("Creating Orders custom counter.");
            if (!PerformanceCounterCategory.Exists("Orders"))
            {
                PerformanceCounterCategory.Create("Orders",
                                                  "Processed orders",
                                                  PerformanceCounterCategoryType.MultiInstance,
                                                  ccds);
            }
            //</Snippet2>

            //<Snippet3>
            Console.WriteLine("Creating Inventory custom counter");
            if (!PerformanceCounterCategory.Exists("Inventory"))
            {
                PerformanceCounterCategory.Create("Inventory",
                                                  "Truck inventory",
                                                  PerformanceCounterCategoryType.SingleInstance,
                                                  "Trucks", "Number of trucks on hand");
            }
            //</Snippet3>
        }
Esempio n. 27
0
        // Static Constructor
        static PerformanceMonitor()
        {
            try
            {
                if (!PerformanceCounterCategory.Exists(ThreadPoolCountersCategoryName))
                {
                    CounterCreationDataCollection customPerformanceCounters = new CounterCreationDataCollection();

                    // Create custom counter objects for thread pool monitoring
                    CounterCreationData workerThreadCounter = new CounterCreationData();
                    workerThreadCounter.CounterName = "Worker Threads";
                    workerThreadCounter.CounterHelp = "Active worker threads in the thread pool";
                    workerThreadCounter.CounterType = PerformanceCounterType.NumberOfItems32;

                    CounterCreationData completionPortThreadCounter = new CounterCreationData();
                    completionPortThreadCounter.CounterName = "Completion Port Threads";
                    completionPortThreadCounter.CounterHelp = "Active completion port threads in the thread pool";
                    completionPortThreadCounter.CounterType = PerformanceCounterType.NumberOfItems32;

                    // Add custom counter objects to CounterCreationDataCollection
                    customPerformanceCounters.Add(workerThreadCounter);
                    customPerformanceCounters.Add(completionPortThreadCounter);

                    // Bind the counters to the PerformanceCounterCategory
                    PerformanceCounterCategory.Create(ThreadPoolCountersCategoryName, "Application thread pool counters", PerformanceCounterCategoryType.MultiInstance, customPerformanceCounters);
                }
            }
            catch
            {
                // Not failing if custom counters cannot be created
            }
        }
        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);
        }
Esempio n. 29
0
        void Initialize()
        {
            if (!PerformanceCounterCategory.Exists(category))
            {
                var counterDataCollection = new CounterCreationDataCollection();

                var counterTotal = new CounterCreationData(TotalMessagesProcessed, "Total processed messages by application",
                                                           PerformanceCounterType.NumberOfItems64);
                counterDataCollection.Add(counterTotal);
                var counterRate = new CounterCreationData(RateMessagesProcessed, "Average messages per second",
                                                          PerformanceCounterType.RateOfCountsPerSecond64);
                counterDataCollection.Add(counterRate);
                var counterAvg = new CounterCreationData(AverageMessagesDuration, "Average message processing time in ms",
                                                         PerformanceCounterType.AverageCount64);
                counterDataCollection.Add(counterAvg);
                var counterAvgBase = new CounterCreationData(AverageMessagesDurationBase,
                                                             "Base average message processing time in ms",
                                                             PerformanceCounterType.AverageBase);
                counterDataCollection.Add(counterAvgBase);

                PerformanceCounterCategory.Create(category, "Saritasa Tools Messages", PerformanceCounterCategoryType.SingleInstance,
                                                  counterDataCollection);
            }

            performanceCounterTotal   = new PerformanceCounter(category, TotalMessagesProcessed, false);
            performanceCounterRate    = new PerformanceCounter(category, RateMessagesProcessed, false);
            performanceCounterAvg     = new PerformanceCounter(category, AverageMessagesDuration, false);
            performanceCounterAvgBase = new PerformanceCounter(category, AverageMessagesDurationBase, false);
            initialized = true;
        }
        /// <summary>
        /// Initialize custom performance counters for this role.
        /// Note that custom performance counter creation requires elevated priveleges
        /// for the role. A role instance will not initialize successfully on
        /// Windows Azure if these calls are made without elevated priveleges.
        /// If the instance is restarted within the host, or in the development emulator,
        /// the counters will already exist.
        /// </summary>
        private static void InitializeCustomPerformanceCounters()
        {
            if (!PerformanceCounterCategory.Exists(CustomCounterCategory))
            {
                CounterCreationDataCollection counterCollection = new CounterCreationDataCollection();

                // add a counter tracking user button1 clicks
                CounterCreationData operationTotal1 = new CounterCreationData();
                operationTotal1.CounterName = CustomCounter1Name;
                operationTotal1.CounterHelp = CustomCounter1Description;
                operationTotal1.CounterType = PerformanceCounterType.NumberOfItems32;
                counterCollection.Add(operationTotal1);

                // add a counter tracking user button2 clicks
                CounterCreationData operationTotal2 = new CounterCreationData();
                operationTotal2.CounterName = CustomCounter2Name;
                operationTotal2.CounterHelp = CustomCounter2Description;
                operationTotal2.CounterType = PerformanceCounterType.NumberOfItems32;
                counterCollection.Add(operationTotal2);

                PerformanceCounterCategory.Create(
                    CustomCounterCategory,
                    CustomCounterCategoryDescription,
                    PerformanceCounterCategoryType.SingleInstance,
                    counterCollection);

                Trace.WriteLine("Custom counter category created.");
            }
            else
            {
                Trace.WriteLine("Custom counter category already exists.");
            }
        }
Esempio n. 31
0
    //public static void Main()
    //{
    //    ArrayList samplesList = new ArrayList();

    //    SetupCategory();
    //    CreateCounters();
    //    CollectSamples(samplesList);
    //}


    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("ElapsedTimeSampleCategory"))
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData ETimeData = new CounterCreationData();
            ETimeData.CounterType = PerformanceCounterType.ElapsedTime;
            ETimeData.CounterName = "ElapsedTimeSample";
            CCDC.Add(ETimeData);

            // Create the category.
            PerformanceCounterCategory.Create("ElapsedTimeSampleCategory",
                "Demonstrates usage of the ElapsedTime performance counter type.",
                CCDC);

            return (true);
        }
        else
        {
            Console.WriteLine("Category exists - ElapsedTimeSampleCategory");
            return (false);
        }
    }
    private static Dictionary<string, PerformanceCounter> CreatePerfCounters(string perfCounterCategoryName, string[] perfCounterNames, bool overWriteCounters)
    {
        CounterCreationDataCollection counters = new CounterCreationDataCollection();

        foreach (string perfCounterName in perfCounterNames)
        {
            counters.Add(new CounterCreationData(perfCounterName, "", PerformanceCounterType.NumberOfItems64));
        }

        if (overWriteCounters)
        {
            if (PerformanceCounterCategory.Exists(perfCounterCategoryName))
            {
                PerformanceCounterCategory.Delete(perfCounterCategoryName);
            }
            PerformanceCounterCategory.Create(perfCounterCategoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);
        }
        else
        {
            if (!PerformanceCounterCategory.Exists(perfCounterCategoryName))
            {
                PerformanceCounterCategory.Create(perfCounterCategoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);
            }
        }

        Dictionary<string, PerformanceCounter> perfCounterLookup = new Dictionary<string, PerformanceCounter>();

        foreach (string perfCounterName in perfCounterNames)
        {
            perfCounterLookup.Add(perfCounterName, new PerformanceCounter(perfCounterCategoryName, perfCounterName, false));
        }

        return perfCounterLookup;
    }
    public static void Main()
    {
        string categoryName = "Sample Perf Counters";
        string[] counterNames = {"Counter 1", "Counter 2"};

        CounterCreationDataCollection counters = new CounterCreationDataCollection();

        foreach (string counterName in counterNames)
        {
            counters.Add(new CounterCreationData(counterName, "", PerformanceCounterType.NumberOfItems64));
        }

        // example of recreating the counters

        if (PerformanceCounterCategory.Exists(categoryName))
        {
            PerformanceCounterCategory.Delete(categoryName);
        }
        PerformanceCounterCategory.Create(categoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);

        // example of conditionally creating the counters

        if (!PerformanceCounterCategory.Exists(categoryName))
        {
            PerformanceCounterCategory.Create(categoryName, "", PerformanceCounterCategoryType.SingleInstance, counters);
        }

        // update the counters (don't create a new instance each time you update)

        List<PerformanceCounter> perfCounters = new List<PerformanceCounter>();

        foreach (string counterName in counterNames)
        {
            perfCounters.Add(new PerformanceCounter(categoryName, counterName, false));
        }

        Random rand = new Random();

        while (true)
        {
            foreach (PerformanceCounter perfCounter in perfCounters)
            {
                perfCounter.RawValue = rand.Next(101);
            }

            Thread.Sleep(2000);
        }
    }
    static void Main(string[] args)
    {
        if (args.Length <= 1)
            {
                System.Console.WriteLine("Please enter CounterGroup and Counters");
                System.Console.WriteLine("Usage: executable <CounterGroup> <Counter1> <CounterN>");
                return;
            }

            if (args.Length == 2) {
                if (args[0].Equals("delete")) {
                    if (PerformanceCounterCategory.Exists(args[1]))
                    {
                        PerformanceCounterCategory.Delete(args[1]);
                        Console.Out.WriteLine("Deleting perfGroup: " + args[1]);
                    }
                    return;
                }
            }

            CounterCreationDataCollection col = new CounterCreationDataCollection();

            String metrics_name = args[0];

            for (int i = 1; i < args.Length; i++) {

                Console.Out.WriteLine("Adding counters: " + args[i]);
                CounterCreationData counter = new CounterCreationData();
                counter.CounterName = args[i];
                counter.CounterHelp = args[i];
                counter.CounterType = PerformanceCounterType.NumberOfItems32;
                col.Add(counter);
            }

            if (PerformanceCounterCategory.Exists(metrics_name))
            {
                PerformanceCounterCategory.Delete(metrics_name);
                Console.Out.WriteLine("Deleting perfGroup:" + metrics_name);
            }

            PerformanceCounterCategory category = PerformanceCounterCategory.Create(metrics_name,
            "Perf Category Description ", col);
            Console.Out.WriteLine("Creating perfGroup:" + metrics_name);
    }
Esempio n. 35
0
    private static bool SetupCategory()
    {
        if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))

        {

            CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageCount64 = new CounterCreationData();
            averageCount64.CounterType = PerformanceCounterType.AverageCount64;
            averageCount64.CounterName = "AverageCounter64Sample";
            counterDataCollection.Add(averageCount64);

            // Add the base counter.
            CounterCreationData averageCount64Base = new CounterCreationData();
            averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
            averageCount64Base.CounterName = "AverageCounter64SampleBase";
            counterDataCollection.Add(averageCount64Base);

            // Create the category.
            PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                "Demonstrates usage of the AverageCounter64 performance counter type.",
                PerformanceCounterCategoryType.SingleInstance, counterDataCollection);

            return (true);
        }
        else
        {
            Console.WriteLine("Category exists - AverageCounter64SampleCategory");
            return (false);
        }
    }
Esempio n. 36
0
        public void AddCounterToCollection(CounterCreationDataCollection counterData)
        {
            CounterCreationData counterCreationData = new CounterCreationData(
                _counterName,
                _counterHelp,
                _pcType);

            counterData.Add(counterCreationData);
        }