/// <summary>@ToDo: Complete documentation before stable release. {799}</summary>
        /// <param name="metricIdentifier">@ToDo: Complete documentation before stable release. {564}</param>
        /// <param name="metricConfiguration">@ToDo: Complete documentation before stable release. {324}</param>
        /// <returns>@ToDo: Complete documentation before stable release. {708}</returns>
        public Metric GetOrCreate(
            MetricIdentifier metricIdentifier,
            MetricConfiguration metricConfiguration)
        {
            Util.ValidateNotNull(metricIdentifier, nameof(metricIdentifier));

            Metric metric = this.metrics.GetOrAdd(
                metricIdentifier,
                (key) => new Metric(
                    this.metricManager,
                    metricIdentifier,
                    metricConfiguration ?? MetricConfigurations.Common.Default()));

            if (metricConfiguration != null && false == metric.configuration.Equals(metricConfiguration))
            {
                throw new ArgumentException("A Metric with the specified Namespace, Id and dimension names already exists, but it has a configuration"
                                            + " that is different from the specified configuration. You may not change configurations once a"
                                            + " metric was created for the first time. Either specify the same configuration every time, or"
                                            + " specify 'null' during every invocation except the first one. 'Null' will match against any"
                                            + " previously specified configuration when retrieving existing metrics, or fall back to"
                                            + Invariant($" the default when creating new metrics. ({nameof(metricIdentifier)} = \"{metricIdentifier.ToString()}\".)"));
            }

            return(metric);
        }
Ejemplo n.º 2
0
        public int GetValuesPerDimensionLimit(int dimensionNumber)
        {
            MetricIdentifier.ValidateDimensionNumberForGetter(dimensionNumber, MetricIdentifier.MaxDimensionsCount);

            int dimensionIndex = dimensionNumber - 1;

            return(this.valuesPerDimensionLimits[dimensionIndex]);
        }
        /// <summary>Checks if a metric with th specified identity is present in this collection.</summary>
        /// <param name="metricIdentifier">A metric identity.</param>
        /// <returns><c>true</c> if a metric with the specified exists in this collection, or <c>false</c> otherwise.</returns>
        public bool Contains(MetricIdentifier metricIdentifier)
        {
            if (metricIdentifier == null)
            {
                return(false);
            }

            return(this.metrics.ContainsKey(metricIdentifier));
        }
        /// <summary>@ToDo: Complete documentation before stable release. {569}</summary>
        /// <param name="metricIdentifier">@ToDo: Complete documentation before stable release. {108}</param>
        /// <param name="dimensionNamesAndValues">@ToDo: Complete documentation before stable release. {785}</param>
        /// <param name="config">@ToDo: Complete documentation before stable release. {275}</param>
        /// <returns>@ToDo: Complete documentation before stable release. {908}</returns>
        public MetricSeries CreateNewSeries(MetricIdentifier metricIdentifier, IEnumerable <KeyValuePair <string, string> > dimensionNamesAndValues, IMetricSeriesConfiguration config)
        {
            Util.ValidateNotNull(metricIdentifier, nameof(metricIdentifier));
            Util.ValidateNotNull(config, nameof(config));

            var dataSeries = new MetricSeries(this.aggregationManager, metricIdentifier, dimensionNamesAndValues, config);

            return(dataSeries);
        }
        /// <summary>Removes a metric with the specified identity from this collection.</summary>
        /// <param name="metricIdentifier">A metric identifier.</param>
        /// <param name="removedMetric">The metric that was removed or <c>null</c>.</param>
        /// <returns>Whether the metric was found and removed.</returns>
        public bool Remove(MetricIdentifier metricIdentifier, out Metric removedMetric)
        {
            if (metricIdentifier == null)
            {
                removedMetric = null;
                return(false);
            }

            return(this.metrics.TryRemove(metricIdentifier, out removedMetric));
        }
        /// <summary>@ToDo: Complete documentation before stable release. {064}</summary>
        /// <param name="metricNamespace">@ToDo: Complete documentation before stable release. {831}</param>
        /// <param name="metricId">@ToDo: Complete documentation before stable release. {381}</param>
        /// <param name="dimensionNamesAndValues">@ToDo: Complete documentation before stable release. {374}</param>
        /// <param name="config">@ToDo: Complete documentation before stable release. {303}</param>
        /// <returns>@ToDo: Complete documentation before stable release. {866}</returns>
        public MetricSeries CreateNewSeries(
            string metricNamespace,
            string metricId,
            IEnumerable <KeyValuePair <string, string> > dimensionNamesAndValues,
            IMetricSeriesConfiguration config)
        {
            // Create MetricIdentifier (it will also validate metricNamespace and metricId):
            List <string> dimNames = null;

            if (dimensionNamesAndValues != null)
            {
                dimNames = new List <string>();
                foreach (KeyValuePair <string, string> dimNameVal in dimensionNamesAndValues)
                {
                    dimNames.Add(dimNameVal.Key);
                }
            }

            var metricIdentifier = new MetricIdentifier(metricNamespace, metricId, dimNames);

            // Create series:
            return(this.CreateNewSeries(metricIdentifier, dimensionNamesAndValues, config));
        }
Ejemplo n.º 7
0
        internal MetricSeries(
            MetricAggregationManager aggregationManager,
            MetricIdentifier metricIdentifier,
            IEnumerable <KeyValuePair <string, string> > dimensionNamesAndValues,
            IMetricSeriesConfiguration configuration)
        {
            // Validate and store aggregationManager:
            Util.ValidateNotNull(aggregationManager, nameof(aggregationManager));
            this.aggregationManager = aggregationManager;

            // Validate and store metricIdentifier:
            Util.ValidateNotNull(metricIdentifier, nameof(metricIdentifier));
            this.MetricIdentifier = metricIdentifier;

            // Copy dimensionNamesAndValues, validate values (keys are implicitly validated as they need to match the keys in the identifier):
            var dimNameVals = new Dictionary <string, string>();

            if (dimensionNamesAndValues != null)
            {
                int dimIndex = 0;
                foreach (KeyValuePair <string, string> dimNameVal in dimensionNamesAndValues)
                {
                    if (dimNameVal.Value == null)
                    {
                        throw new ArgumentNullException(Invariant($"The value for dimension '{dimNameVal.Key}' number is null."));
                    }

                    if (String.IsNullOrWhiteSpace(dimNameVal.Value))
                    {
                        throw new ArgumentNullException(Invariant($"The value for dimension '{dimNameVal.Key}' is empty or white-space."));
                    }

                    dimNameVals[dimNameVal.Key] = dimNameVal.Value;
                    dimIndex++;
                }
            }

            // Validate that metricIdentifier and dimensionNamesAndValues contain consistent dimension names:
            if (metricIdentifier.DimensionsCount != dimNameVals.Count)
            {
                throw new ArgumentException(Invariant($"The specified {nameof(metricIdentifier)} contains {metricIdentifier.DimensionsCount} dimensions,")
                                            + Invariant($" however the specified {nameof(dimensionNamesAndValues)} contains {dimNameVals.Count} name-value pairs with unique names."));
            }

            foreach (string dimName in metricIdentifier.GetDimensionNames())
            {
                if (false == dimNameVals.ContainsKey(dimName))
                {
                    throw new ArgumentException(Invariant($"The specified {nameof(metricIdentifier)} contains a dimension named \"{dimName}\",")
                                                + Invariant($" however the specified {nameof(dimensionNamesAndValues)} does not contain an entry for that name."));
                }
            }

            // Store copied dimensionNamesAndValues:
            this.dimensionNamesAndValues = dimNameVals;

            // Validate and store configuration:
            Util.ValidateNotNull(configuration, nameof(configuration));
            this.configuration = configuration;
            this.requiresPersistentAggregator = configuration.RequiresPersistentAggregation;

            // Init other instance vars:
            this.aggregatorPersistent = null;
            this.aggregatorDefault    = null;
            this.aggregatorQuickPulse = null;
            this.aggregatorCustom     = null;
        }
        /// <summary>Gets the metric with the specified identify, if it exists.</summary>
        /// <param name="metricIdentifier">A metric identity.</param>
        /// <param name="metric">The metric (if it exists) or <c>null</c>.</param>
        /// <returns><c>true</c> if the metric was retrieved, or <c>false</c> otherwise.</returns>
        public bool TryGet(MetricIdentifier metricIdentifier, out Metric metric)
        {
            Util.ValidateNotNull(metricIdentifier, nameof(metricIdentifier));

            return(this.metrics.TryGetValue(metricIdentifier, out metric));
        }
        /// <summary>Removes a metric with the specified identity from this collection.</summary>
        /// <param name="metricIdentifier">A metric identifier.</param>
        /// <returns>Whether the metric was found and removed.</returns>
        public bool Remove(MetricIdentifier metricIdentifier)
        {
            Metric removedMetric;

            return(this.Remove(metricIdentifier, out removedMetric));
        }