public MetricInfo(string context, string metricName, MetricTags tags, TimerMetric timer, PerfCounterGauge perfCounter)
 {
     this.Context = context;
     this.MetricName = metricName;
     this.Tags = tags;
     this.Timer = timer;
     this.PerfCounter = perfCounter;
     this.Key = TagName(this.Context + this.MetricName, this.Tags);
 }
        private MetricInfo RegisterMetric(PdhCounterPathElement pathElement, IDictionary<String, MetricInfo> existingMetrics)
        {
            string contextName = CleanName(pathElement.ObjectName);
            string metricName = CleanName(pathElement.CounterName);
            string instanceName = CleanName(pathElement.InstanceName);

            MetricTags tags = default(MetricTags);
            if (instanceName != null)
            {
                tags = "instance=" + instanceName;
            }
            string keyName = MetricInfo.TagName(contextName + metricName, tags);
            MetricInfo mInfo;
            if (existingMetrics.TryGetValue(keyName, out mInfo))
            {
                existingMetrics.Remove(keyName);
                return mInfo;
            }

            PerfCounterGauge pcGauge = new PerfCounterGauge(pathElement.ObjectName, pathElement.CounterName, pathElement.InstanceName);
            TimerMetric timer = null;
            PerformanceCounterType type = pcGauge.performanceCounter.CounterType;
            switch (type)
            {
                //these types of counters are not usable
                case PerformanceCounterType.AverageBase:
                case PerformanceCounterType.CounterMultiBase:
                case PerformanceCounterType.RawBase:
                case PerformanceCounterType.SampleBase:
                    _log.Error(String.Format("Don't know how to handle metric of type {0} for {1}", type.ToString(), metricName));
                    return null;

                //timers
                case PerformanceCounterType.AverageTimer32:
                case PerformanceCounterType.ElapsedTime:
                    timer = new TimerMetric(SamplingType.FavourRecent);
                    break;
            }
            mInfo = new MetricInfo(contextName, metricName, tags, timer, pcGauge);
            if (mInfo.Timer != null)
            {
                _timers[keyName] = mInfo;
            }
            return mInfo;
        }