Beispiel #1
0
        StatsTimer(Builder builder) : base(builder.Config, builder.Context)
        {
            unit_ = builder.TimeUnit;

            // remove the count from the histogram, because we need to add a
            // tag for the time unit and this tag will make no sense for count
            // values.
            var snapshot_config =
                new SnapshotConfig.Builder(builder.SnapshotConfig)
                .WithCount(false)
                .Build();

            MetricConfig unit_config = builder
                                       .Config
                                       .WithAdditionalTag("unit", unit_.Name());

            MetricContext context = builder.Context;

            histogram_ = new Histogram(unit_config, snapshot_config, builder.Resevoir,
                                       context);

            Tag tag = MetricType.Counter.AsTag();

            count_ = new Counter(unit_config.WithAdditionalTag(tag), context);

            metrics_ = new ReadOnlyCollection <IMetric>(
                new IMetric[] {
                count_, new CompositMetricTransformer(histogram_, ConvertToUnit)
            });
        }
        public static void Constructor_InitializesEstimationPeriod(
            [Frozen] TimeUnit estimationPeriod,
            OrderItem orderItem)
        {
            var model = new GetOrderItemModel(orderItem);

            model.EstimationPeriod.Should().Be(estimationPeriod.Name());
        }
        public static void Constructor_InitializesTimeUnit(
            [Frozen] TimeUnit timeUnit,
            OrderItem orderItem)
        {
            var model = new GetOrderItemModel(orderItem);

            model.TimeUnit.Should().NotBeNull();
            model.TimeUnit.Description.Should().Be(timeUnit.Description());
            model.TimeUnit.Name.Should().Be(timeUnit.Name());
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StepCounter"/> class
 /// by using the given <see cref="MetricConfig"/>, initial value and
 /// <see cref="MetricContext"/>.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> object containing the configuration
 /// that should be used by the <see cref="StepCounter"/> object.
 /// </param>
 /// <param name="initial">
 /// The initial value of the counter.
 /// </param>
 /// <param name="unit">
 /// The unit to be used to report the computed rate.
 /// </param>
 /// <param name="context">
 /// The <see cref="MetricContext"/> to be used by the counter.
 /// </param>
 public StepCounter(MetricConfig config, long initial, TimeUnit unit,
                    MetricContext context)
     : base(
         config
         .WithAdditionalTag(MetricType.Normalized.AsTag())
         .WithAdditionalTag("unit", unit.Name()), context)
 {
     prev_count_ = initial;
     curr_count_ = initial;
     prev_tick_  = curr_tick_ = context.Tick;
     unit_       = unit;
 }
Beispiel #5
0
        public Timer(MetricConfig config, TimeUnit unit, MetricContext context)
            : base(config, context)
        {
            unit_ = unit;

            MetricConfig cfg = config.WithAdditionalTag("unit", unit.Name());

            count_      = new Counter(cfg.WithAdditionalTag(kStatistic, kCount), context);
            max_        = new StepMaxGauge(cfg.WithAdditionalTag(kStatistic, kMax));
            min_        = new StepMinGauge(cfg.WithAdditionalTag(kStatistic, kMin));
            total_time_ =
                new Counter(cfg.WithAdditionalTag(kStatistic, kTotal), context);

            metrics_ = new ReadOnlyCollection <IMetric>(
                new IMetric[] {
                count_,
                new MeasureTransformer(max_, ConvertToUnit),
                new MeasureTransformer(min_, ConvertToUnit),
                new MeasureTransformer(total_time_, ConvertToUnit)
            });
        }
Beispiel #6
0
        public static void EachTimeUnit_HasExpectedDisplayName(TimeUnit timeUnit, string expectedDisplayName)
        {
            var actualDisplayName = timeUnit.Name();

            actualDisplayName.Should().Be(expectedDisplayName);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StepCounter"/> class
 /// by using the given <see cref="MetricConfig"/>, initial value and
 /// <see cref="MetricContext"/>.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> object containing the configuration
 /// that should be used by the <see cref="StepCounter"/> object.
 /// </param>
 /// <param name="initial">
 /// The initial value of the counter.
 /// </param>
 /// <param name="unit">
 /// The unit to be used to report the computed rate.
 /// </param>
 /// <param name="context">
 /// The <see cref="MetricContext"/> to be used by the counter.
 /// </param>
 public StepCounter(MetricConfig config, long initial, TimeUnit unit,
   MetricContext context)
   : base(
     config
       .WithAdditionalTag(MetricType.Normalized.AsTag())
       .WithAdditionalTag("unit", unit.Name()), context) {
   prev_count_ = initial;
   curr_count_ = initial;
   prev_tick_ = curr_tick_ = context.Tick;
   unit_ = unit;
 }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Timer"/> class by using
        /// the given configuration.
        /// </summary>
        /// <param name="builder">
        /// </param>
        public BucketTimer(Builder builder) : base(builder.Config, builder.Context)
        {
            unit_         = builder.TimeUnit;
            measure_unit_ = builder.MeasureUnit;

            MetricContext context = builder.Context;

            MetricConfig config =
                builder
                .Config
                .WithAdditionalTag("unit", measure_unit_.Name());

            count_ = new BucketCounter(config.WithAdditionalTag(kStatistic, kCount),
                                       context);
            max_ = new StepMaxGauge(config.WithAdditionalTag(kStatistic, kMax));
            min_ = new StepMinGauge(config.WithAdditionalTag(kStatistic, kMin));

            // We should not convert the value of the total time, since
            // it is already a time the rate reported will be the
            // percentage of time that was spent within the defined reporting
            // interval.
            MetricConfig time_config =
                config
                .WithAdditionalTag(kStatistic, kTotal)
                .WithAdditionalTag("unit", "nounit");

            total_time_ = new BucketCounter(time_config, TimeUnit.Ticks, context);

            overflow_count_ =
                new BucketCounter(
                    config
                    .WithAdditionalTag(kStatistic, kCount)
                    .WithAdditionalTag(kBucket, "bucket=overflow"),
                    context);

            buckets_ = builder.Buckets;

            // Compute the size of the maximum bucket name and create a padding
            // format to allow lexicographically sort of buckets.
            int    num_digits = buckets_[buckets_.Length - 1].ToString().Length;
            string padding    = "".PadLeft(num_digits, '0');

            string label = unit_.Abbreviation();

            bucket_count_ = new BucketCounter[buckets_.Length];
            for (int i = 0; i < buckets_.Length; i++)
            {
                bucket_count_[i] = new BucketCounter(
                    config
                    .WithAdditionalTag(kStatistic, kCount)
                    .WithAdditionalTag(kBucket,
                                       "bucket={0}{1}".Fmt(buckets_[i].ToString(padding), label)),
                    context);
            }

            Func <double, double> convert =
                measure => ConvertToUnit(measure, measure_unit_);

            var metrics = new List <IMetric> {
                total_time_,
                new StepMeasureTransformer(min_, convert),
                new StepMeasureTransformer(max_, convert),
                overflow_count_,
                count_
            };

            metrics.AddRange(bucket_count_);

            metrics_ = new ReadOnlyCollection <IMetric>(metrics);
        }