Exemplo n.º 1
0
        private void BDeleteSelectedClick(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                PerformanceCounterCategory category = new PerformanceCounterCategory(tbGroupName.Text);

                IEnumerable <CounterCreationData> existsCounters = category.GetCounters(string.Empty)
                                                                   .Where(x => x.CounterName != ((CounterContainer)lbExists.SelectedItem).Name)
                                                                   .Select(x => new CounterCreationData(x.CounterName, x.CounterHelp, x.CounterType));

                CounterCreationDataCollection counters = new CounterCreationDataCollection(existsCounters.ToArray());

                PerformanceCounterCategory.Delete(tbGroupName.Text);

                PerformanceCounterCategory.Create(tbGroupName.Text, tbGroupName.Text,
                                                  PerformanceCounterCategoryType.SingleInstance, counters);

                FillExistsList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = DefaultCursor;
            }
        }
Exemplo n.º 2
0
 public void SetUp()
 {
     if (PerformanceCounterCategory.Exists(categoryName))
     {
         PerformanceCounterCategory.Delete(categoryName);
     }
 }
Exemplo n.º 3
0
 public void UninstallCounters()
 {
     if (PerformanceCounterCategory.Exists(SignalRPerfCounterManager.CategoryName))
     {
         PerformanceCounterCategory.Delete(SignalRPerfCounterManager.CategoryName);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Performs installation which requires administrative permissions.
        /// </summary>
        /// <param name="installationContext">The installation context.</param>
        public void Install(InstallationContext installationContext)
        {
            // categories must be installed together, so we must find all PerfCounter targets in the configuration file
            var    countersByCategory = LoggingConfiguration.AllTargets.OfType <PerformanceCounterTarget>().BucketSort(c => c.CategoryName);
            string categoryName       = CategoryName;

            if (countersByCategory[categoryName].Any(c => c.created))
            {
                installationContext.Trace("Category '{0}' has already been installed.", categoryName);
                return;
            }

            try
            {
                PerformanceCounterCategoryType categoryType;
                CounterCreationDataCollection  ccds = GetCounterCreationDataCollection(countersByCategory[CategoryName], out categoryType);

                if (PerformanceCounterCategory.Exists(categoryName))
                {
                    installationContext.Debug("Deleting category '{0}'", categoryName);
                    PerformanceCounterCategory.Delete(categoryName);
                }

                installationContext.Debug("Creating category '{0}' with {1} counter(s) (Type: {2})", categoryName, ccds.Count, categoryType);
                foreach (CounterCreationData c in ccds)
                {
                    installationContext.Trace("  Counter: '{0}' Type: ({1}) Help: {2}", c.CounterName, c.CounterType, c.CounterHelp);
                }

                PerformanceCounterCategory.Create(categoryName, "Category created by NLog", categoryType, ccds);
            }
            catch (Exception exception)
            {
                if (exception.MustBeRethrownImmediately())
                {
                    throw;
                }
                if (installationContext.IgnoreFailures)
                {
                    installationContext.Warning("Error creating category '{0}': {1}", categoryName, exception.Message);
                }
                else
                {
                    installationContext.Error("Error creating category '{0}': {1}", categoryName, exception.Message);
                    throw;
                }

                if (exception.MustBeRethrown())
                {
                    throw;
                }
            }
            finally
            {
                foreach (var t in countersByCategory[categoryName])
                {
                    t.created = true;
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new performance category (Ey) and counter (# sabre calls / sec)
 /// </summary>
 public static void DeleteEyPerformaceCounters()
 {
     if (PerformanceCounterCategory.Exists(CategoryName))
     {
         PerformanceCounterCategory.Delete(CategoryName);
     }
 }
Exemplo n.º 6
0
        public void Init()
        {
            try
            {
                PerformanceCounterCategory.Delete("Warewolf");
            }

            catch
            {
                //Do Nothing
            }
            _mockPerformanceCounterFactory = new Mock <IRealPerformanceCounterFactory>();
            _performanceCounterFactory     = _mockPerformanceCounterFactory.Object;
            var register = new WarewolfPerformanceCounterRegister(new List <IPerformanceCounter>
            {
                new WarewolfCurrentExecutionsPerformanceCounter(_performanceCounterFactory),
                new WarewolfNumberOfErrors(_performanceCounterFactory),
                new WarewolfRequestsPerSecondPerformanceCounter(_performanceCounterFactory),
                new WarewolfAverageExecutionTimePerformanceCounter(_performanceCounterFactory),
                new WarewolfNumberOfAuthErrors(_performanceCounterFactory),
                new WarewolfServicesNotFoundCounter(_performanceCounterFactory),
            }, new List <IResourcePerformanceCounter>());

            _performanceCounterLocater = new WarewolfPerformanceCounterManager(register.Counters, new List <IResourcePerformanceCounter>(), register, new Mock <IPerformanceCounterPersistence>().Object, _performanceCounterFactory);
            CustomContainer.Register <IWarewolfPerformanceCounterLocater>(_performanceCounterLocater);
        }
 /// <summary>
 ///
 /// </summary>
 public static void RemoveCategory()
 {
     if (PerformanceCounterCategory.Exists(CATEGORY_NAME))
     {
         PerformanceCounterCategory.Delete(CATEGORY_NAME);
     }
 }
Exemplo n.º 8
0
        public static void EnsureCategory(IICPerformanceCountersAttribute categoryAttr, IEnumerable <IICPerformanceCounter> counters)
        {
            bool needCreate;

            if (!PerformanceCounterCategory.Exists(categoryAttr.CategoryName))
            {
                needCreate = true;
            }
            else
            {
                needCreate = false;
                foreach (IICPerformanceCounter counter in counters)
                {
                    if (!PerformanceCounterCategory.CounterExists(counter._rawAttr.CounterName, categoryAttr.CategoryName))
                    {
                        needCreate = true;
                        break;
                    }
                }

                if (needCreate)
                {
                    PerformanceCounterCategory.Delete(categoryAttr.CategoryName);
                }
            }

            if (needCreate)
            {
                CreateCategory(categoryAttr, counters);
            }
        }
Exemplo n.º 9
0
        public void Init()
        {
            try
            {
                try
                {
                    PerformanceCounterCategory.Delete("Warewolf");
                }

                catch
                {
                    //Do Nothing
                }

                var register = new WarewolfPerformanceCounterRegister(new List <IPerformanceCounter>
                {
                    new WarewolfCurrentExecutionsPerformanceCounter(),
                    new WarewolfNumberOfErrors(),
                    new WarewolfRequestsPerSecondPerformanceCounter(),
                    new WarewolfAverageExecutionTimePerformanceCounter(),
                    new WarewolfNumberOfAuthErrors(),
                    new WarewolfServicesNotFoundCounter()
                }, new List <IResourcePerformanceCounter>());

                CustomContainer.Register <IWarewolfPerformanceCounterLocater>(new WarewolfPerformanceCounterManager(register.Counters, new List <IResourcePerformanceCounter>(), register, new Mock <IPerformanceCounterPersistence>().Object));
            }
            catch (Exception err)
            {
                // ignored
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
            }
        }
        /// <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.");
        }
Exemplo n.º 11
0
        private static bool PerformanceCounterExistsAndHasAllCounters(string instanceName)
        {
            if (PerformanceCounterCategory.Exists(CategoryName) == false)
            {
                return(false);
            }
            foreach (var counter in CounterProperties)
            {
                if (PerformanceCounterCategory.CounterExists(counter.Name, CategoryName) == false)
                {
                    PerformanceCounterCategory.Delete(CategoryName);
                    return(false);
                }

                try
                {
                    new PerformanceCounter(CategoryName, counter.Name, instanceName, readOnly: true).Close();
                }
                catch (InvalidOperationException)
                {
                    PerformanceCounterCategory.Delete(CategoryName);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Installs the performance counters. Requires admin privileges.
        /// </summary>
        /// <param name="categoryName">The name of the category to create</param>
        /// <param name="counterDefinitions">The set of counter definitions</param>
        /// <returns>True if the counters were installed</returns>
        public static bool TrySetupCounters(string categoryName, Dictionary <int, CounterCreationData> counterDefinitions)
        {
            bool found = false;

            try
            {
                if (PerformanceCounterCategory.Exists(categoryName))
                {
                    found = true;

                    // make sure we have enough perms to update the counters
                    WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                    if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
                    {
                        return(found);
                    }

                    PerformanceCounterCategory.Delete(categoryName);
                    Console.WriteLine("\tPerformance counters {0} removed.", categoryName);
                }

                CounterCreationDataCollection collection = new CounterCreationDataCollection(counterDefinitions.OrderBy(kv => kv.Key).Select(kv => kv.Value).ToArray());
                PerformanceCounterCategory.Create(categoryName, "Microsoft Psi Runtime performance counters", PerformanceCounterCategoryType.MultiInstance, collection);
                Console.WriteLine("\tPerformance counters {0} installed.", categoryName);
                return(true);
            }
            catch (SecurityException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }

            return(found);
        }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
0
        public static PerformanceCounter CreateSimpleCounter(string counterName,
                                                             string counterHelp, PerformanceCounterType counterType, string
                                                             categoryName, string categoryHelp)
        {
            CounterCreationDataCollection counterCollection =
                new CounterCreationDataCollection();

            CounterCreationData counter =
                new CounterCreationData(counterName, counterHelp, counterType);

            counterCollection.Add(counter);

            if (PerformanceCounterCategory.Exists(categoryName))
            {
                PerformanceCounterCategory.Delete(categoryName);
            }
            PerformanceCounterCategory appCategory =
                PerformanceCounterCategory.Create(categoryName, categoryHelp,
                                                  PerformanceCounterCategoryType.SingleInstance, counterCollection);

            PerformanceCounter appCounter =
                new PerformanceCounter(categoryName, counterName, false);

            appCounter.RawValue = 0;
            return(appCounter);
        }
        public static void CreateCounterCategory(string name)
        {
            if (PerformanceCounterCategory.Exists(name))
            {
                try
                {
                    PerformanceCounterCategory.Delete(name);
                }
                catch (UnauthorizedAccessException ex)
                {
                    logger.Error($"Cannot delete existing performance counter {name}", ex);
                }
            }

            var counters = new CounterCreationDataCollection();

            var usersAtWork = new CounterCreationData($"{name} counter",
                                                      $"Count of {name} events",
                                                      PerformanceCounterType.NumberOfItems32);

            counters.Add(usersAtWork);

            try
            {
                PerformanceCounterCategory.Create(name, "Info related to LogIn", counters);
            }
            catch (UnauthorizedAccessException ex)
            {
                logger.Error($"Cannot create performance counter with name: {name}", ex);
            }
            catch (InvalidOperationException ex)
            {
                logger.Error($"Cannot create Performance Category {name} because it already exists", ex);
            }
        }
        private static void CreateCategory()
        {
            try
            {
                logger.Debug("SIPSorceryPerformanceMonitor creating " + PERFORMANCE_COUNTER_CATEGORY_NAME + " category.");

                if (PerformanceCounterCategory.Exists(PERFORMANCE_COUNTER_CATEGORY_NAME))
                {
                    PerformanceCounterCategory.Delete(PERFORMANCE_COUNTER_CATEGORY_NAME);
                }

                CounterCreationDataCollection ccdc = new CounterCreationDataCollection();

                foreach (var counter in m_counterNames)
                {
                    CounterCreationData counterData = new CounterCreationData();
                    counterData.CounterType = counter.Value;
                    counterData.CounterName = counter.Key;
                    ccdc.Add(counterData);

                    logger.Debug("SIPSorceryPerformanceMonitor added counter " + counter.Key + ".");
                }

                PerformanceCounterCategory.Create(PERFORMANCE_COUNTER_CATEGORY_NAME, "SIP Sorcery performance counters", PerformanceCounterCategoryType.SingleInstance, ccdc);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPSorceryPerformanceMonitor CreateCategory. " + excp.Message);
                throw;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Removes the performance counter data specified in the arguments
        /// </summary>
        /// <param name="data">Data to remove performance counters</param>
        /// <returns>Installation result</returns>
        public static PmcInstallationResult RemovePerformanceCounters(PmcCreationData data)
        {
            var errors     = new Dictionary <string, Exception>();
            var categories = new List <string>();

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            // --- Remove categories one-by-one
            foreach (var category in data.Categories.Values.Where(category => !category.IsPredefined))
            {
                var categoryName = AppConfigurationManager.ProviderSettings.InstancePrefix + category.Name;
                try
                {
                    // --- Delete the whole category
                    if (PerformanceCounterCategory.Exists(categoryName))
                    {
                        PerformanceCounterCategory.Delete(categoryName);
                    }
                    categories.Add(categoryName);
                }
                catch (Exception ex)
                {
                    // --- Administer errors
                    errors[categoryName] = ex;
                }
            }
            return(new PmcInstallationResult(categories, errors));
        }
Exemplo n.º 18
0
        private void InitializeGlobalPerformanceCounters()
        {
            try
            {
                CounterCreationData[] quickMonCreationData = new CounterCreationData[]
                {
                    new CounterCreationData("Collector success states/Sec", "Collector successful states per second", PerformanceCounterType.RateOfCountsPerSecond32),
                    new CounterCreationData("Collector warning states/Sec", "Collector warning states per second", PerformanceCounterType.RateOfCountsPerSecond32),
                    new CounterCreationData("Collector error states/Sec", "Collector error states per second", PerformanceCounterType.RateOfCountsPerSecond32),
                    new CounterCreationData("Collectors queried/Sec", "Number of Collectors queried per second", PerformanceCounterType.RateOfCountsPerSecond32),
                    new CounterCreationData("Collectors query time", "Collector total query time (ms)", PerformanceCounterType.NumberOfItems32),
                    new CounterCreationData("Selected Collector query time", "Selected Collector query time (ms)", PerformanceCounterType.NumberOfItems32)
                };

                if (PerformanceCounterCategory.Exists(quickMonPCCategory))
                {
                    PerformanceCounterCategory pcC = new PerformanceCounterCategory(quickMonPCCategory);
                    if (pcC.GetCounters().Count() != quickMonCreationData.Length)
                    {
                        PerformanceCounterCategory.Delete(quickMonPCCategory);
                    }
                }

                if (!PerformanceCounterCategory.Exists(quickMonPCCategory))
                {
                    PerformanceCounterCategory.Create(quickMonPCCategory, "QuickMon", PerformanceCounterCategoryType.SingleInstance, new CounterCreationDataCollection(quickMonCreationData));
                }
                try
                {
                    collectorErrorStatePerSec   = InitializePerfCounterInstance(quickMonPCCategory, "Collector error states/Sec");
                    collectorWarningStatePerSec = InitializePerfCounterInstance(quickMonPCCategory, "Collector warning states/Sec");
                    collectorInfoStatePerSec    = InitializePerfCounterInstance(quickMonPCCategory, "Collector success states/Sec");
                    collectorsQueriedPerSecond  = InitializePerfCounterInstance(quickMonPCCategory, "Collectors queried/Sec");
                    collectorsQueryTime         = InitializePerfCounterInstance(quickMonPCCategory, "Collectors query time");
                    selectedCollectorsQueryTime = InitializePerfCounterInstance(quickMonPCCategory, "Selected Collector query time");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error initializing application performance counters\r\n" + ex.Message, "Performance Counters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Requested registry access is not allowed"))
                {
                    if (IsAdmin())
                    {
                        MessageBox.Show(string.Format("Could not create performance counters! Please use a user account that has the proper rights.\r\nMore details{0}:", ex.Message), "Performance Counters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else //try launching in admin mode
                    {
                        RestartInAdminMode();
                    }
                }
                else
                {
                    MessageBox.Show("Error creating application performance counters\r\n" + ex.Message, "Performance Counters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 19
0
        private void Add()
        {
            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Adding Performance Counter Category: {0}", this.CategoryName));
            CounterCreationDataCollection colCounterCreationData = new CounterCreationDataCollection();

            colCounterCreationData.Clear();
            if (PerformanceCounterCategory.Exists(this.CategoryName))
            {
                this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Removing Performance Counter Category: {0}", this.CategoryName));
                PerformanceCounterCategory.Delete(this.CategoryName);
            }

            foreach (ITaskItem counter in this.CounterList)
            {
                string counterName = counter.GetMetadata("CounterName");
                string counterHelp = counter.GetMetadata("CounterHelp");
                PerformanceCounterType counterType = (PerformanceCounterType)Enum.Parse(typeof(PerformanceCounterType), counter.GetMetadata("CounterType"));
                this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, "Adding Performance Counter: {0}", counterName));
                CounterCreationData objCreateCounter = new CounterCreationData(counterName, counterHelp, counterType);
                colCounterCreationData.Add(objCreateCounter);
            }

            if (colCounterCreationData.Count > 0)
            {
                PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.SingleInstance;

                if (this.MultiInstance)
                {
                    categoryType = PerformanceCounterCategoryType.MultiInstance;
                }

                this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Creating Performance Counter Category: {0}", this.CategoryName));
                PerformanceCounterCategory.Create(this.CategoryName, this.CategoryHelp, categoryType, colCounterCreationData);
            }
        }
Exemplo n.º 20
0
 public static void Uninstall(string categoryName)
 {
     if (PerformanceCounterCategory.Exists(categoryName))
     {
         PerformanceCounterCategory.Delete(categoryName);
     }
 }
        void Initialize()
        {
            try
            {
                CounterCreationData[] counters = Data;

                if (!PerformanceCounterCategory.Exists(_categoryName))
                {
                    CreateCategory(counters);

                    return;
                }

                IEnumerable <CounterCreationData> missing =
                    counters.Where(counter => !PerformanceCounterCategory.CounterExists(counter.CounterName, _categoryName));
                if (missing.Any())
                {
                    PerformanceCounterCategory.Delete(_categoryName);

                    CreateCategory(counters);
                }
            }
            catch (SecurityException)
            {
                _log.WarnFormat(
                    "Unable to create performance counter category (Category: {0})" +
                    "\nTry running the program in the Administrator role to set these up." +
                    "\n**Hey, this just means you aren't admin or don't have/want perf counter support**", _categoryName);
            }
        }
Exemplo n.º 22
0
 private static void DeletePerformanceCounterCategory(PerfCounter perfCounter)
 {
     if (PerformanceCounterCategory.Exists(perfCounter.CategoryName))
     {
         PerformanceCounterCategory.Delete(perfCounter.CategoryName);
     }
 }
Exemplo n.º 23
0
 public static void UninstallPerformanceCounters()
 {
     if (PerformanceCounterCategory.Exists(PerformanceCategoryName))
     {
         PerformanceCounterCategory.Delete(PerformanceCategoryName);
     }
 }
Exemplo n.º 24
0
        void InitiatizeCategory()
        {
            try
            {
                var counters = new[]
                {
                    ConsumerThreadCount,
                    ReceiveThreadCount,
                    ReceiveRate,
                    PublishRate,
                    SendRate,
                    ReceiveCount,
                    PublishCount,
                    SentCount,
                    ConsumerDuration,
                    ConsumerDurationBase,
                    ReceiveDuration,
                    ReceiveDurationBase,
                    PublishDuration,
                    PublishDurationBase,
                };

                if (!PerformanceCounterCategory.Exists(CategoryName))
                {
                    PerformanceCounterCategory.Create(
                        CategoryName,
                        CategoryHelp,
                        PerformanceCounterCategoryType.MultiInstance,
                        new CounterCreationDataCollection(counters.Select(x => (CounterCreationData)x).ToArray()));

                    return;
                }

                int missing = counters
                              .Where(counter => !PerformanceCounterCategory.CounterExists(counter.Name, CategoryName))
                              .Count();

                if (missing > 0)
                {
                    PerformanceCounterCategory.Delete(CategoryName);

                    PerformanceCounterCategory.Create(
                        CategoryName,
                        CategoryHelp,
                        PerformanceCounterCategoryType.MultiInstance,
                        new CounterCreationDataCollection(counters.Select(x => (CounterCreationData)x).ToArray()));
                }
            }
            catch (SecurityException)
            {
                //swallow the exception because having these is NOT critical

                var msg =
                    "Unable to create performance counter category (Category: {0})" +
                    "\nTry running the program in the Administrator role to set these up." +
                    "\n**Hey, this just means you aren't admin or don't have/want perf counter support**"
                    .FormatWith(CategoryName);
                _log.Warn(msg);
            }
        }
Exemplo n.º 25
0
        protected void CreateCounters()
        {
            var categoryExists = false;

            // check if all the perf counters exist - this is the best that can be done with the current API
            if ((categoryExists = PerformanceCounterCategory.Exists(_categoryName)) &&
                _counterDefinitions.Cast <CounterCreationData>().All(ccd => PerformanceCounterCategory.CounterExists(ccd.CounterName, _categoryName)))
            {
                return;
            }

            try
            {
                if (categoryExists)
                {
                    PerformanceCounterCategory.Delete(_categoryName);
                }

                PerformanceCounterCategory.Create(_categoryName, _categoryHelp, _categoryType, _counterDefinitions);
            }
            catch (UnauthorizedAccessException e)
            {
                DerivedLogger.Error(e, "Error creating the performance counter category named '{0}'. Ensure the process is running with the necessary privileges.", _categoryName);
            }
            catch (SecurityException e)
            {
                DerivedLogger.Error(e, "Error creating the performance counter category named '{0}'. Ensure the process is running with the necessary privileges.", _categoryName);
            }
            catch (Exception e)
            {
                DerivedLogger.Error(e, "Unexpected error creating the performance counter category named '{0}': {1}", _categoryName, e.Message);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Static method to recreate Shard Management performance counter catagory with given counter list.
        /// </summary>
        internal static void CreatePerformanceCategoryAndCounters()
        {
#if NETFRAMEWORK
            // Creation of performance counters need Administrator privilege
            if (HasCreatePerformanceCategoryPermissions())
            {
                // Delete performance counter category, if exists.
                if (PerformanceCounterCategory.Exists(PerformanceCounters.ShardManagementPerformanceCounterCategory))
                {
                    PerformanceCounterCategory.Delete(PerformanceCounters.ShardManagementPerformanceCounterCategory);
                }

                CounterCreationDataCollection smmCounters = new CounterCreationDataCollection();

                foreach (PerfCounterCreationData d in PerfCounterInstance.counterList)
                {
                    smmCounters.Add(new CounterCreationData(d.CounterDisplayName, d.CounterHelpText, d.CounterType));
                }

                PerformanceCounterCategory.Create(
                    PerformanceCounters.ShardManagementPerformanceCounterCategory,
                    PerformanceCounters.ShardManagementPerformanceCounterCategoryHelp,
                    PerformanceCounterCategoryType.MultiInstance,
                    smmCounters);
            }
            else
            {
                // Trace out warning and continue
                Tracer.TraceWarning(TraceSourceConstants.ComponentNames.PerfCounter,
                                    "createCategory",
                                    "User does not have permissions to create performance counter category");
            }
#endif
        }
Exemplo n.º 27
0
        static void Main()
        {
            if (PerformanceCounterCategory.Exists("SalesDistribution"))
            {
                PerformanceCounterCategory.Delete("SalesDistribution");
            }
            CounterCreationDataCollection coll = new CounterCreationDataCollection();
            CounterCreationData           data = new CounterCreationData();

            data.CounterName = "RequestsPerSec";
            data.CounterType = PerformanceCounterType.NumberOfItems32;
            data.CounterHelp = "Requests received per second";
            coll.Add(data);

            PerformanceCounterCategory.Create("SalesDistribution", "Automated Sales Distribution System",
                                              PerformanceCounterCategoryType.SingleInstance, coll);
            PerformanceCounter counter = new PerformanceCounter("SalesDistribution", "RequestsPerSec", false);
            int x = 1;

            while (x <= 50)
            {
                Console.WriteLine("RequestsPerSec = {0}", counter.RawValue);
                counter.Increment();
                System.Threading.Thread.Sleep(250);
                x = (x + 1);
            }
            counter.Close();
            Console.Read();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Removes forwarding counters
        /// </summary>
        public static void RemoveCounters()
        {
            string message = string.Empty;

            try
            {
                message = "Removing performance counter category " + ForwardingCounters.PerformanceCategoryName;
                if (log.IsInfoEnabled)
                {
                    log.Info(message);
                }
                Console.WriteLine(message);
                PerformanceCounter.CloseSharedResources();
                PerformanceCounterCategory.Delete(ForwardingCounters.PerformanceCategoryName);
            }
            catch (Exception ex)
            {
                message = "Exception removing counters: " + ex.ToString();
                Console.WriteLine(message);
                if (log.IsInfoEnabled)
                {
                    log.Info(message);
                }
            }
        }
Exemplo n.º 29
0
        static PerformanceCounters()
        {
            try
            {
                if (PerformanceCounterCategory.Exists(category))
                {
                    PerformanceCounterCategory.Delete(category);
                }

                // order to be sure that *Base follows counter
                var props = typeof(PerformanceCounters)
                            .GetProperties()
                            .Where(p => p.PropertyType == typeof(PerformanceCounter))
                            .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);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Deletes the counters from specified machine name.
        /// </summary>
        /// <returns><c>true</c> if deleted, <c>false</c> otherwise</returns>
        public bool Delete()
        {
            if (!PerformanceType.IsValid)
            {
                Deleted = false;
                return(false);
            }
            if (Deleted)
            {
                return(true);
            }
            try
            {
                if (!PerformanceCounterCategory.Exists(CategoryName))
                {
                    return(true);
                }

                PerformanceCounterCategory.Delete(CategoryName);
                Deleted = !PerformanceCounterCategory.Exists(CategoryName);
                Created = false;
                return(Deleted);
            }
            catch
            {
                Deleted = false;
                return(false);
            }
        }