Ejemplo n.º 1
0
        internal static string NormalizeWcfPerformanceCounterName(string counterName)
        {
            //
            // See this:
            // * https://msdn.microsoft.com/en-us/library/ms731087(v=vs.110).aspx
            // * https://msdn.microsoft.com/en-us/library/ms735098.aspx
            // * http://stackoverflow.com/q/41393811/60188
            var serviceName        = counterName.SubstringBefore("@").Replace('.', '_');
            var serviceBaseAddress = counterName.SubstringAfter("@").Trim('|').Replace('.', '_');

            var normalizedCounterName = string.Format("{0}.{1}",
                                                      MetricNameBuilder.SanitizeMetricName(serviceName).ToLowerInvariant(),
                                                      MetricNameBuilder.SanitizeMetricName(serviceBaseAddress).ToLowerInvariant());

            while (normalizedCounterName.Contains("__"))
            {
                normalizedCounterName = normalizedCounterName.Replace("__", "_");
            }

            return(normalizedCounterName);
        }
Ejemplo n.º 2
0
        private IEnumerable <IMetricDefinition> CreatePerformanceCounterMetricDefinition(MetricConfigurationElement metric,
                                                                                         Func <string, string> metricNameProcessor)
        {
            return(ParsePerformanceCounters(metric.Path).Select(pc => {
                var name = metric.Name;

                if (!string.IsNullOrWhiteSpace(pc.Item1) && name.Contains("**"))
                {
                    var fragment = MetricNameBuilder.SanitizeMetricName(metricNameProcessor(pc.Item1)).ToLowerInvariant();

                    fragment = fragment.Trim('_');
                    while (fragment.Contains("__"))
                    {
                        fragment = fragment.Replace("__", "_");
                    }

                    name = name.Replace("**", fragment);
                } // if

                var metricDefinition = new PerformanceCounterMetricDefinition(name, () => pc.Item2.NextValue(), metric.AggregationStrategy);
                return metricDefinition;
            }));
        }