Exemple #1
0
        /// <summary>
        ///     Returns true if the counter is registered for this category
        /// </summary>
        public bool CounterExists(string counterName)
        {
            if (counterName == null)
            {
                throw new ArgumentNullException(nameof(counterName));
            }

            if (_categoryName == null)
            {
                throw new InvalidOperationException(SR.Format(SR.CategoryNameNotSet));
            }

            return(PerformanceCounterLib.CounterExists(_categoryName, counterName));
        }
Exemple #2
0
        /// <summary>
        ///     Returns true if the instance already exists for this category.
        /// </summary>
        public bool InstanceExists(string instanceName)
        {
            if (instanceName == null)
            {
                throw new ArgumentNullException(nameof(instanceName));
            }

            if (_categoryName == null)
            {
                throw new InvalidOperationException(SR.Format(SR.CategoryNameNotSet));
            }

            using (var categorySample = PerformanceCounterLib.GetCategorySample(_categoryName))
            {
                return(categorySample._instanceNameTable.ContainsKey(instanceName));
            }
        }
Exemple #3
0
        /// <summary>
        ///     Returns true if the category is registered in the machine.
        /// </summary>
        public static bool Exists(string categoryName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException(nameof(categoryName));
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (PerformanceCounterLib.IsCustomCategory(categoryName))
            {
                return(true);
            }

            return(PerformanceCounterLib.CategoryExists(categoryName));
        }
Exemple #4
0
        /// <summary>
        ///     Returns the instance names for a given category
        /// </summary>
        /// <internalonly/>
        internal static string[] GetCounterInstances(string categoryName)
        {
            using (var categorySample = PerformanceCounterLib.GetCategorySample(categoryName))
            {
                if (categorySample._instanceNameTable.Count == 0)
                {
                    return(Array.Empty <string>());
                }

                var instanceNames = new string[categorySample._instanceNameTable.Count];
                categorySample._instanceNameTable.Keys.CopyTo(instanceNames, 0);
                if (instanceNames.Length == 1 && instanceNames[0] == PerformanceCounterLib.SingleInstanceName)
                {
                    return(Array.Empty <string>());
                }

                return(instanceNames);
            }
        }
Exemple #5
0
        /// <summary>
        ///     Returns true if the counter is registered for this category on a particular machine.
        /// </summary>
        public static bool CounterExists(string counterName, string categoryName)
        {
            if (counterName == null)
            {
                throw new ArgumentNullException(nameof(counterName));
            }

            if (categoryName == null)
            {
                throw new ArgumentNullException(nameof(categoryName));
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            return(PerformanceCounterLib.CounterExists(categoryName, counterName));
        }