Exemplo n.º 1
0
 /// <summary>
 /// Creates a timer that will only report an incremental counter for the rate and mean.
 /// </summary>
 /// <see cref="MetricsContext.Timer"/>
 public Timer IncrementalTimer(string name, Unit unit,
                               SamplingType samplingType = SamplingType.ExponentiallyDecaying,
                               TimeUnit rateUnit         = TimeUnit.Seconds, TimeUnit durationUnit = TimeUnit.Milliseconds,
                               MetricTags tags           = default(MetricTags))
 {
     return(Timer(TaggedMetricsRegistry.INCREMENTAL_PREFIX + name, unit, samplingType, rateUnit, durationUnit, tags));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a timer that will only report iff at least one sample has been added since the last time a report was sent.
 /// </summary>
 /// <see cref="MetricsContext.Timer"/>
 public Timer ReportOnUpdateTimer(string name, Unit unit,
                                  SamplingType samplingType = SamplingType.ExponentiallyDecaying,
                                  TimeUnit rateUnit         = TimeUnit.Seconds, TimeUnit durationUnit = TimeUnit.Milliseconds,
                                  MetricTags tags           = default(MetricTags))
 {
     return(Timer(TaggedMetricsRegistry.REPORT_ON_UPDATE_PREFIX + name, unit, samplingType, rateUnit, durationUnit, tags));
 }
Exemplo n.º 3
0
        //
        // Summary:
        //     A Histogram measures the distribution of values in a stream of data: e.g., the
        //     number of results returned by a search.
        //
        // Parameters:
        //   name:
        //     Name of the metric. Must be unique across all histograms in this context.
        //
        //   unit:
        //     Description of what the is being measured ( Unit.Requests , Unit.Items etc )
        //     .
        //
        //   samplingType:
        //     Type of the sampling to use (see SamplingType for details ).
        //
        //   tags:
        //     Optional set of tags that can be associated with the metric.
        //
        // Returns:
        //     Reference to the metric
        public static Histogram Histogram(string name, Unit unit, SamplingType samplingType = SamplingType.Default,
                                          MetricTags tags = default(MetricTags))
        {
            var metricTags = GenerateTags(tags);

            return(Metric.Histogram(name, unit, samplingType, metricTags));
        }
Exemplo n.º 4
0
        private static Reservoir SamplingTypeToReservoir(SamplingType samplingType)
        {
            while (true)
            {
                switch (samplingType)
                {
                case SamplingType.Default:
                    samplingType = Metric.Config.DefaultSamplingType;
                    continue;

                case SamplingType.HighDynamicRange:
                    return(new HdrHistogramReservoir());

                case SamplingType.ExponentiallyDecaying:
                    return(new ExponentiallyDecayingReservoir());

                case SamplingType.LongTerm:
                    return(new UniformReservoir());

                case SamplingType.SlidingWindow:
                    return(new SlidingWindowReservoir());
                }
                throw new InvalidOperationException("Sampling type not implemented " + samplingType);
            }
        }
Exemplo n.º 5
0
 public static Timer Timer(string name,
                           Unit unit, SamplingType samplingType = SamplingType.FavourRecent,
                           TimeUnit rateUnit     = TimeUnit.Seconds,
                           TimeUnit durationUnit = TimeUnit.Milliseconds,
                           MetricTags tags       = default(MetricTags))
 {
     return(Metric.Timer(name, unit, samplingType, rateUnit, durationUnit, tags));
 }
 public HistogramImplementation BuildHistogram(string name, Unit unit, SamplingType samplingType)
 {
     if (samplingType == SamplingType.FavourRecent)
     {
         return new HistogramMetric(new ExponentiallyDecayingReservoir(this.clock, this.scheduler));
     }
     return new HistogramMetric(samplingType);
 }
Exemplo n.º 7
0
 public HistogramImplementation BuildHistogram(string name, Unit unit, SamplingType samplingType)
 {
     if (samplingType == SamplingType.FavourRecent)
     {
         return(new HistogramMetric(new ExponentiallyDecayingReservoir(this.clock, this.scheduler)));
     }
     return(new HistogramMetric(samplingType));
 }
Exemplo n.º 8
0
        //
        // Summary:
        //     A timer is basically a histogram of the duration of a type of event and a meter
        //     of the rate of its occurrence. Metrics.Metric.Histogram(System.String,Metrics.Unit,Metrics.SamplingType,Metrics.MetricTags)
        //     and Metrics.Metric.Meter(System.String,Metrics.Unit,Metrics.TimeUnit,Metrics.MetricTags)
        //
        // Parameters:
        //   name:
        //     Name of the metric. Must be unique across all timers in this context.
        //
        //   unit:
        //     Description of what the is being measured ( Unit.Requests , Unit.Items etc )
        //     .
        //
        //   samplingType:
        //     Type of the sampling to use (see SamplingType for details ).
        //
        //   rateUnit:
        //     Time unit for rates reporting. Defaults to Second ( occurrences / second ).
        //
        //   durationUnit:
        //     Time unit for reporting durations. Defaults to Milliseconds.
        //
        //   tags:
        //     Optional set of tags that can be associated with the metric.
        //
        // Returns:
        //     Reference to the metric
        public static Timer Timer(string name, Unit unit, SamplingType samplingType = SamplingType.Default,
                                  TimeUnit rateUnit = TimeUnit.Seconds, TimeUnit durationUnit = TimeUnit.Milliseconds,
                                  MetricTags tags   = default(MetricTags))
        {
            var metricTags = GenerateTags(tags);

            return(Metric.Timer(name, unit, samplingType, rateUnit, durationUnit, metricTags));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Configure the default sampling type to use for histograms.
 /// </summary>
 /// <param name="type">Type of sampling to use.</param>
 /// <returns>Chain-able configuration object.</returns>
 public MetricsConfig WithDefaultSamplingType(SamplingType type)
 {
     if (type == SamplingType.Default)
     {
         throw new ArgumentException("Sampling type other than default must be specified", nameof(type));
     }
     this.defaultSamplingType = type;
     return(this);
 }
Exemplo n.º 10
0
        /// <summary>Creates a new metric instance from the provided definition information, or returns any existing instance if found.</summary>
        /// <remarks>
        ///     <para>This call is designed to be safe in multithreaded environments. If two
        ///     threads attempt to register the same metric at the same time, the first will
        ///     register the metric and the second (and all subsequent calls to Register with the
        ///     same three part key) will return the same object.</para>
        ///     <para>If the Metric Definition doesn't exist, it will be created. If the Sampled
        ///     Metric doesn't exist, it will be created.</para>
        ///     <para>If a metric definition does exist with the same 3-part Key but is not a
        ///     sampled metric an exception will be thrown. This is one of the only times that an
        ///     exception can be thrown by the Loupe Agent.</para>
        /// </remarks>
        /// <example>
        ///     For examples, see the <see cref="SampledMetric">Sampled Metric</see> class
        ///     overview.
        /// </example>
        /// <param name="metricsSystem">The metrics capture system label.</param>
        /// <param name="categoryName">The name of the category with which this metric is associated.</param>
        /// <param name="counterName">The name of the metric definition within the category.</param>
        /// <param name="samplingType">The sampling type of this sampled metric counter.</param>
        /// <param name="unitCaption">A displayable caption for the units this metric samples, or null for unit-less values.</param>
        /// <param name="metricCaption">A displayable caption for this sampled metric counter.</param>
        /// <param name="description">An extended end-user description of this sampled metric counter.</param>
        /// <param name="instanceName">The unique name of this instance within the metric's collection (may be null).</param>
        public static SampledMetric Register(string metricsSystem, string categoryName, string counterName,
                                             SamplingType samplingType, string unitCaption, string metricCaption,
                                             string description, string instanceName)
        {
            SampledMetricDefinition metricDefinition = SampledMetricDefinition.Register(metricsSystem, categoryName, counterName, samplingType, unitCaption, metricCaption, description);

            // Then just forward into our call that requires the definition to be specified
            return(Register(metricDefinition, instanceName));
        }
Exemplo n.º 11
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("parameterSpace");
     writer.WriteObjectValue(ParameterSpace);
     writer.WritePropertyName("samplingType");
     writer.WriteStringValue(SamplingType.ToString());
     writer.WriteEndObject();
 }
Exemplo n.º 12
0
 private static Reservoir SamplingTypeToReservoir(SamplingType samplingType)
 {
     switch (samplingType)
     {
         case SamplingType.FavourRecent: return new ExponentiallyDecayingReservoir();
         case SamplingType.LongTerm: return new UniformReservoir();
         case SamplingType.SlidingWindow: return new SlidingWindowReservoir();
     }
     throw new InvalidOperationException("Sampling type not implemented " + samplingType.ToString());
 }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the time series values for the requested sampling type.
        /// </summary>
        /// <param name="samplingType">The sampling type requested.</param>
        /// <returns>The array of datapoints for the requested sampling type/</returns>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown if the sampling type was not included in the response.</exception>
        /// <remarks>
        /// double.NaN is the sentinel used to indicate there is no metric value.
        /// </remarks>
        public double[] GetTimeSeriesValues(SamplingType samplingType)
        {
            for (var i = 0; i < this.TimeSeriesValues.Count; ++i)
            {
                if (samplingType.Equals(this.TimeSeriesValues[i].Key))
                {
                    return(this.TimeSeriesValues[i].Value);
                }
            }

            throw new KeyNotFoundException($"Sampling type {samplingType} not found in the query result.");
        }
Exemplo n.º 14
0
        private static Reservoir SamplingTypeToReservoir(SamplingType samplingType)
        {
            switch (samplingType)
            {
            case SamplingType.FavourRecent: return(new ExponentiallyDecayingReservoir());

            case SamplingType.LongTerm: return(new UniformReservoir());

            case SamplingType.SlidingWindow: return(new SlidingWindowReservoir());
            }
            throw new System.NotImplementedException();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the datapoints for a given sampling type.
        /// </summary>
        /// <param name="samplingType">Type of the sampling.</param>
        /// <returns>
        /// an enumerable of datapoints.
        /// </returns>
        /// <exception cref="System.ArgumentException">samplingType</exception>
        public IEnumerable <Datapoint <TValue> > GetDatapoints(SamplingType samplingType)
        {
            var index = Array.IndexOf(this.Definition.SamplingTypes, samplingType);

            if (index < 0)
            {
                var message = $"'{samplingType}' is not found in [{string.Join(",", this.Definition.SamplingTypes)}])";
                throw new ArgumentException(message, nameof(samplingType));
            }

            return(this.GetDatapoints(index));
        }
Exemplo n.º 16
0
 public DefaultMetricsRegistry(
     ILoggerFactory loggerFactory,
     AppMetricsOptions options,
     IClock clock,
     EnvironmentInfoProvider environmentInfoProvider,
     Func <string, IMetricContextRegistry> newContextRegistry)
 {
     _logger = loggerFactory.CreateLogger <DefaultMetricContextRegistry>();
     _environmentInfoProvider = environmentInfoProvider;
     _clock = clock;
     _newContextRegistry  = newContextRegistry;
     _defaultContextLabel = options.DefaultContextLabel;
     _defaultSamplingType = options.DefaultSamplingType;
     _contexts.TryAdd(_defaultContextLabel, newContextRegistry(_defaultContextLabel));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Constructor to a very efficient and robust variant of the iterative closest point (ICP) algorithm.
 /// </summary>
 /// <param name="iterations">number of iterations</param>
 /// <param name="tolerence">Controls the accuracy of registration at each iteration of ICP.</param>
 /// <param name="rejectionScale">Robust outlier rejection is applied for robustness. This value actually corresponds to the standard deviation coefficient. Points with rejectionScale * sigma are ignored during registration.</param>
 /// <param name="numLevels">Number of pyramid levels to proceed. Deep pyramids increase speed but decrease accuracy. Too coarse pyramids might have computational overhead on top of the inaccurate registrtaion. This parameter should be chosen to optimize a balance. Typical values range from 4 to 10.</param>
 /// <param name="sampleType">Currently this parameter is ignored and only uniform sampling is applied. </param>
 /// <param name="numMaxCorr">Currently this parameter is ignored and only PickyICP is applied. Leave it as 1.</param>
 public ICP(
     int iterations,
     float tolerence         = 0.05f,
     float rejectionScale    = 2.5f,
     int numLevels           = 6,
     SamplingType sampleType = SamplingType.Uniform,
     int numMaxCorr          = 1)
 {
     _ptr = PpfMatch3dInvoke.cveICPCreate(
         iterations,
         tolerence,
         rejectionScale,
         numLevels,
         sampleType,
         numMaxCorr);
 }
        /// <summary>
        /// Determines whether the metric value is of type long.
        /// </summary>
        /// <param name="samplingType">Type of the sampling.</param>
        /// <param name="seriesResolutionInMinutes">The series resolution in minutes.</param>
        /// <param name="aggregationType">Type of the aggregation.</param>
        /// <returns>
        /// True if the metric value is of type long; false otherwise.
        /// </returns>
        public static bool IsMetricValueTypeLong(SamplingType samplingType, int seriesResolutionInMinutes, AggregationType aggregationType)
        {
            // AggregationType.None is the default, which is to compute the average.
            if (aggregationType == AggregationType.None && seriesResolutionInMinutes > SerializationConstants.DefaultSeriesResolutionInMinutes)
            {
                return(false);
            }

            for (int i = 0; i < SamplingTypesWithValueTypeOfLong.Length; ++i)
            {
                if (SamplingTypesWithValueTypeOfLong[i].Equals(samplingType))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 19
0
        private void AddNewEntityIfNecessary(Sampling sampling, SamplingType samplingType)
        {
            bool isSamplingTypeNeedToBeAdd = sampling.SamplingType_Id < 1;

            if (isSamplingTypeNeedToBeAdd)
            {
                SamplingType newSamplingType = new SamplingType()
                {
                    Name   = samplingType.Name,
                    NameFr = samplingType.Name
                };

                db.SamplingTypes.Add(newSamplingType);
                db.SaveChanges();

                sampling.SamplingType_Id = newSamplingType.Id;
            }
        }
        public PartialViewResult Save(SamplingType model)
        {
            if (model.Id > 0)
            {
                var samplingtype = db.SamplingTypes.Where(i => i.Id == model.Id).FirstOrDefault();
                samplingtype.Name     = model.Name;
                samplingtype.NameFr   = model.NameFr;
                samplingtype.IsActive = model.IsActive;
                db.SaveChanges(User.Identity.Name);
            }
            else
            {
                db.SamplingTypes.Add(model);
                db.SaveChanges(User.Identity.Name);
            }

            var result = db.SamplingTypes.ToList();

            return(PartialView("_List", result));
        }
Exemplo n.º 21
0
        private void AddNewEntityIfNecessary(Sampling sampling)
        {
            bool newSamplingTypeMustBeAdded = sampling.SamplingType_Id < 1 &&
                                              sampling.SamplingType.Name != String.Empty;

            if (newSamplingTypeMustBeAdded)
            {
                SamplingType newSamplingType = new SamplingType()
                {
                    IsActive = true,
                    Name     = sampling.SamplingType.Name,
                    NameFr   = sampling.SamplingType.Name
                };

                db.SamplingTypes.Add(newSamplingType);
                db.SaveChanges();

                sampling.SamplingType    = newSamplingType;
                sampling.SamplingType_Id = newSamplingType.Id;
            }
        }
Exemplo n.º 22
0
        public static IReservoir Build(SamplingType samplingType, int sampleSize, double alpha)
        {
            while (true)
            {
                switch (samplingType)
                {
                case SamplingType.HighDynamicRange:
                    return(new HdrHistogramReservoir());

                case SamplingType.ExponentiallyDecaying:
                    return(new ExponentiallyDecayingReservoir(sampleSize, alpha));

                case SamplingType.LongTerm:
                    return(new UniformReservoir(sampleSize));

                case SamplingType.SlidingWindow:
                    return(new SlidingWindowReservoir(sampleSize));

                default:
                    throw new ArgumentOutOfRangeException(nameof(samplingType), samplingType, "Sampling type not implemented " + samplingType);
                }
            }
        }
Exemplo n.º 23
0
 public HistogramImplementation BuildHistogram(string name, Unit unit, SamplingType samplingType)
 {
     return(new HistogramMetric(new UniformReservoir()));
 }
Exemplo n.º 24
0
 public Timer Timer(string name, Unit unit, SamplingType samplingType, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
 {
     return(this.registry.Timer(name, () => this.metricsBuilder.BuildTimer(name, unit, rateUnit, durationUnit, samplingType), unit, rateUnit, durationUnit, tags));
 }
Exemplo n.º 25
0
 public Histogram Histogram(string name, Unit unit, SamplingType samplingType, MetricTags tags)
 {
     return(this.Histogram(name, unit, () => this.metricsBuilder.BuildHistogram(name, unit, samplingType), tags));
 }
Exemplo n.º 26
0
 /// <summary>
 /// A Histogram measures the distribution of values in a stream of data: e.g., the number of results returned by a search.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all histograms in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Histogram Histogram(string name, Unit unit, SamplingType samplingType = SamplingType.FavourRecent, MetricTags tags = default(MetricTags))
 {
     return(globalContext.Histogram(name, unit, samplingType, tags));
 }
Exemplo n.º 27
0
 public HistogramImplementation BuildHistogram(string name, Unit unit, SamplingType samplingType)
 {
     return new HistogramMetric(samplingType);
 }
Exemplo n.º 28
0
 /// <summary>
 /// A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence.
 /// <seealso cref="Histogram"/> and <seealso cref="Meter"/>
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all timers in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="durationUnit">Time unit for reporting durations. Defaults to Milliseconds. </param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Timer Timer(string name, Unit unit, SamplingType samplingType = SamplingType.FavourRecent,
     TimeUnit rateUnit = TimeUnit.Seconds, TimeUnit durationUnit = TimeUnit.Milliseconds, MetricTags tags = default(MetricTags))
 {
     return globalContext.Timer(name, unit, samplingType, rateUnit, durationUnit, tags);
 }
 public Histogram Histogram(string name, Unit unit, SamplingType samplingType, MetricTags tags) { throw new ReadOnlyMetricsContextException(); }
Exemplo n.º 30
0
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, SamplingType samplingType)
 {
     return new TimerMetric(samplingType);
 }
Exemplo n.º 31
0
 public HistogramMetric(SamplingType samplingType)
     : this(SamplingTypeToReservoir(samplingType))
 {
 }
Exemplo n.º 32
0
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, SamplingType samplingType)
 {
     return new TimerMetric(new HistogramMetric(new ExponentiallyDecayingReservoir(this.clock, this.scheduler)), new MeterMetric(this.clock, this.scheduler), this.clock);
 }
Exemplo n.º 33
0
 /// <summary>
 /// A Histogram measures the distribution of values in a stream of data: e.g., the number of results returned by a search.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all histograms in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Histogram Histogram(string name, Unit unit, SamplingType samplingType = SamplingType.FavourRecent, MetricTags tags = default(MetricTags))
 {
     return globalContext.Histogram(name, unit, samplingType, tags);
 }
Exemplo n.º 34
0
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, SamplingType samplingType)
 {
     return(new TimerMetric(new HistogramMetric(new UniformReservoir()), new MeterMetric(this.clock, this.scheduler), this.clock));
 }
 public Timer Timer(string name, Unit unit, SamplingType samplingType, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags) { throw new ReadOnlyMetricsContextException(); }
Exemplo n.º 36
0
 public HistogramImplementation BuildHistogram(string name, Unit unit, SamplingType samplingType)
 {
     return(new HistogramMetric(samplingType));
 }
Exemplo n.º 37
0
 public PropertyDefinition(PropertyAggregationType propertyAggregationType, SamplingType samplingType)
 {
     this.PropertyAggregationType = propertyAggregationType;
     this.SamplingType            = samplingType;
     this.PropertyName            = GetPropertyName(this.PropertyAggregationType, this.SamplingType.Name);
 }
Exemplo n.º 38
0
 public TimerImplementation BuildTimer(string name, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, SamplingType samplingType)
 {
     return(new TimerMetric(samplingType));
 }