Ejemplo n.º 1
0
        private PerformanceCounterCollection CreatePerfCounters(string instance)
        {
            PerformanceCounterCollection counters = new PerformanceCounterCollection();

            foreach (PerfCounterConfig config in counterConfigs)
            {
                var perfCounter = CounterFromConfig(instance, config);
                if (perfCounter != null)
                {
                    counters.AddCounter(perfCounter);
                }
            }
            return(counters);
        }
Ejemplo n.º 2
0
        public PerformanceCounter GetCounter(string counterName, string instance)
        {
            PerformanceCounterCollection perfCat = defaultInstanceCounters;

            if (instance != null)
            {
                lock (dtInstanceCounters)
                {
                    if (!dtInstanceCounters.TryGetValue(instance, out perfCat))
                    {
                        perfCat = CreatePerfCounters(instance);
                        dtInstanceCounters.Add(instance, perfCat);
                        //Dictionary<string, PerformanceCounterCollection> cats = new Dictionary<string, PerformanceCounterCollection>(dtInstanceCounters);
                        //cats[instance] = perfCat;
                        //dtInstanceCounters = cats;
                    }
                }
            }
            return(perfCat.GetCounter(counterName));
        }