Exemplo n.º 1
0
        /// <summary>
        /// Create counter list from string
        /// </summary>
        /// <param name="counterString">string which represents one or more counters: "\\<machineName>\<categoryName>(<instanceName>)\<counterName>"
        /// counterName and/or instanceName can have the special value "#ALL#", meaning we want to get all of them</param>
        /// <returns>list of counters</returns>
        public static IEnumerable <System.Diagnostics.PerformanceCounter> CreateCountersFromString(string counterString)
        {
            string machineName, categoryName, instanceName, counterName;

            ParseCounterString(counterString, out machineName, out categoryName, out instanceName, out counterName);

            System.Diagnostics.PerformanceCounterCategory category = new System.Diagnostics.PerformanceCounterCategory(categoryName, machineName);

            IEnumerable <System.Diagnostics.PerformanceCounter> counters = new System.Diagnostics.PerformanceCounter[] { };

            if (counterName == "#ALL#" && instanceName == "#ALL#")
            {
                foreach (string instance in category.GetInstanceNames().OrderBy(s => s))
                {
                    counters = counters.Concat(category.GetCounters(instance));
                }
            }
            else if (counterName == "#ALL#")
            {
                if (string.IsNullOrEmpty(instanceName))
                {
                    counters = category.GetCounters();
                }
                else
                {
                    counters = category.GetCounters(instanceName);
                }
            }
            else if (instanceName == "#ALL#")
            {
                foreach (string instance in category.GetInstanceNames().OrderBy(s => s))
                {
                    counters = counters.Concat(new System.Diagnostics.PerformanceCounter[] { new System.Diagnostics.PerformanceCounter(categoryName, counterName, instance, machineName) });
                }
            }
            else
            {
                counters = new System.Diagnostics.PerformanceCounter[] { new System.Diagnostics.PerformanceCounter(categoryName, counterName, instanceName, machineName) };
            }

            // Création des contrôles
            return(counters);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create counter list from string
        /// </summary>
        /// <param name="counterString">string which represents one or more counters: "\\<machineName>\<categoryName>(<instanceName>)\<counterName>"
        /// counterName and/or instanceName can have the special value "#ALL#", meaning we want to get all of them</param>
        /// <returns>list of counters</returns>
        public static IEnumerable<System.Diagnostics.PerformanceCounter> CreateCountersFromString(string counterString)
        {
            string machineName, categoryName, instanceName, counterName;
            
            ParseCounterString(counterString, out machineName, out categoryName, out instanceName, out counterName);

            System.Diagnostics.PerformanceCounterCategory category = new System.Diagnostics.PerformanceCounterCategory(categoryName, machineName);

            IEnumerable<System.Diagnostics.PerformanceCounter> counters = new System.Diagnostics.PerformanceCounter[] { };

            if (counterName == "#ALL#" && instanceName == "#ALL#")
            {
                foreach (string instance in category.GetInstanceNames().OrderBy(s => s))
                {
                    counters = counters.Concat(category.GetCounters(instance));
                }
            }
            else if (counterName == "#ALL#")
            {
                if (string.IsNullOrEmpty(instanceName))
                {
                    counters = category.GetCounters();
                }
                else
                {
                    counters = category.GetCounters(instanceName);
                }
            }
            else if (instanceName == "#ALL#")
            {
                foreach (string instance in category.GetInstanceNames().OrderBy(s => s))
                {
                    counters = counters.Concat(new System.Diagnostics.PerformanceCounter[] { new System.Diagnostics.PerformanceCounter(categoryName, counterName, instance, machineName) });
                }
            }
            else
            {
                counters = new System.Diagnostics.PerformanceCounter[] { new System.Diagnostics.PerformanceCounter(categoryName, counterName, instanceName, machineName) };
            }

            // Création des contrôles
            return counters;
        }