Esempio n. 1
0
        private IEnumerable <IMetricDefinition> CreateMetricDefinitions(MetricConfigurationElement metric, string type)
        {
            switch (type)
            {
            case "performance-counter":
                return(CreatePerformanceCounterMetricDefinition(metric, NormalizePerformanceCounterName));

            case "iis-performance-counter":
                //
                // IIS performance counters are prefixed with "PID_", which
                // we need to get rid of
                return(CreatePerformanceCounterMetricDefinition(metric, NormalizeIisPerformanceCounterName));

            case "wcf-performance-counter":
                //
                // WCF performance counters are prefixed with "ServiceName@" and contain
                // pipe-delimited crap like Service@http:||foo:8080|bar
                return(CreatePerformanceCounterMetricDefinition(metric, NormalizeWcfPerformanceCounterName));

            case "number-of-files":
                return(CreateNumberOfFilesDefinition(metric));

            default:
                throw new ArgumentOutOfRangeException("type");
            }
        }
Esempio n. 2
0
        private IEnumerable <IMetricDefinition> CreateNumberOfFilesDefinition(MetricConfigurationElement metric)
        {
            var path = metric.Path;

            if (!Directory.Exists(path))
            {
                yield break;
            }

            yield return(new MetricDefinition(
                             metric.Name,
                             () => {
                var numberOfFiles = new DirectoryInfo(path).EnumerateFiles("*.*", SearchOption.TopDirectoryOnly).Count();
                return numberOfFiles;
            }, metric.AggregationStrategy));
        }
Esempio n. 3
0
        public IMetricSource CreateMetricSource(MetricConfigurationElement metric)
        {
            if (metric.Type == "rabbit-mq")
            {
                var metricSource = new RabbitMqMetricSource(metric);
                return(metricSource);
            } // if

            if (metric.Type == "memcached")
            {
                var metricSource = new MemcachedMetricSource(metric);
                return(metricSource);
            } // if

            var metricDefinitions = metricDefinitionFactory.CreateMetricDefinitions(metric);

            if (metric.RefreshEvery.HasValue)
            {
                return(new RefreshableMetricSource(metricDefinitions, metric.RefreshEvery.Value, () => metricDefinitionFactory.CreateMetricDefinitions(metric)));
            }

            return(new MetricSource(metricDefinitions));
        }
Esempio n. 4
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;
            }));
        }
Esempio n. 5
0
        public IEnumerable <IMetricDefinition> CreateMetricDefinitions(MetricConfigurationElement metric)
        {
            var type = metric.Type.ToLowerInvariant();

            return(CreateMetricDefinitions(metric, type));
        }