コード例 #1
0
ファイル: Meter.cs プロジェクト: brumschlag/nohros-must
        /// <summary>
        /// Initializes a new instance of the <see cref=" Meter"/> class by using
        /// the specified meter name, rate unit and clock.
        /// </summary>
        /// <param name="config">
        /// A <see cref="MetricConfig"/> containing the configuration settings
        /// for the metric.
        /// </param>
        /// <param name="rate_unit">
        /// The time unit of the meter's rate.
        /// </param>
        /// <param name="context">
        /// A <see cref="MetricContext"/> that contains the shared
        /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>.
        /// </param>
        internal Meter(MetricConfig config, TimeUnit rate_unit,
                       MetricContext context) : base(config, context)
        {
            const string kStatistic = "statistic";

            mean_rate_ = new MeanRate(
                config.WithAdditionalTag(new Tag(kStatistic, "mean_rate")), rate_unit,
                context);

            ewma_1_rate_ = ExponentialWeightedMovingAverage
                           .ForOneMinute(
                config.WithAdditionalTag(new Tag(kStatistic, "ewma_m1_rate")),
                rate_unit, context);

            ewma_5_rate_ = ExponentialWeightedMovingAverage
                           .ForFiveMinutes(
                config.WithAdditionalTag(new Tag(kStatistic, "ewma_m5_rate")),
                rate_unit, context);

            ewma_15_rate_ = ExponentialWeightedMovingAverage
                            .ForFifteenMinutes(
                config.WithAdditionalTag(new Tag(kStatistic, "ewma_m15_rate")),
                rate_unit, context);

            metrics_ = new ReadOnlyCollection <IMetric>(
                new IMetric[] {
                mean_rate_, ewma_1_rate_, ewma_5_rate_, ewma_15_rate_
            });
        }
コード例 #2
0
ファイル: Meter.cs プロジェクト: joethinh/nohros-must
    /// <summary>
    /// Initializes a new instance of the <see cref=" Meter"/> class by using
    /// the specified meter name, rate unit and clock.
    /// </summary>
    /// <param name="config">
    /// A <see cref="MetricConfig"/> containing the configuration settings
    /// for the metric.
    /// </param>
    /// <param name="rate_unit">
    /// The time unit of the meter's rate.
    /// </param>
    /// <param name="context">
    /// A <see cref="MetricContext"/> that contains the shared
    /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>.
    /// </param>
    internal Meter(MetricConfig config, TimeUnit rate_unit,
      MetricContext context) : base(config, context) {
      const string kStatistic = "statistic";

      mean_rate_ = new MeanRate(
        config.WithAdditionalTag(new Tag(kStatistic, "mean_rate")), rate_unit,
        context);

      ewma_1_rate_ = ExponentialWeightedMovingAverage
        .ForOneMinute(
          config.WithAdditionalTag(new Tag(kStatistic, "ewma_m1_rate")),
          rate_unit, context);

      ewma_5_rate_ = ExponentialWeightedMovingAverage
        .ForFiveMinutes(
          config.WithAdditionalTag(new Tag(kStatistic, "ewma_m5_rate")),
          rate_unit, context);

      ewma_15_rate_ = ExponentialWeightedMovingAverage
        .ForFifteenMinutes(
          config.WithAdditionalTag(new Tag(kStatistic, "ewma_m15_rate")),
          rate_unit, context);

      metrics_ = new ReadOnlyCollection<IMetric>(
        new IMetric[] {
          mean_rate_, ewma_1_rate_, ewma_5_rate_, ewma_15_rate_
        });
    }
コード例 #3
0
 CallableGaugeWrapper CountGauge(MetricConfig config)
 {
     return
         (new CallableGaugeWrapper(
              config.WithAdditionalTag("statistic", "count"),
              snapshot => snapshot.Size));
 }
コード例 #4
0
 CallableGaugeWrapper StdDevGauge(MetricConfig config)
 {
     return
         (new CallableGaugeWrapper(
              config.WithAdditionalTag("statistic", "stddev"),
              snapshot => snapshot.StdDev));
 }
コード例 #5
0
 CallableGaugeWrapper MaxGauge(MetricConfig config)
 {
     return
         (new CallableGaugeWrapper(
              config.WithAdditionalTag("statistic", "max"),
              snapshot => snapshot.Max));
 }
コード例 #6
0
ファイル: StatsTimer.cs プロジェクト: brumschlag/nohros-must
        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)
            });
        }
コード例 #7
0
 CallableGaugeWrapper PercentileGauge(MetricConfig config, double percentile)
 {
     // We need to divide the percentile to 100 because the percentiles from
     // the SnapshotConfig is in range 0 to 100 and the Snapshot.Quantile
     // methof computes percentiles in range 0.0 to 1.0.
     return
         (new CallableGaugeWrapper(
              config.WithAdditionalTag("statistic",
                                       "percentile_" + (percentile).ToString("#0.####")),
              snapshot => snapshot.Quantile(percentile / 100)));
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="ExponentialWeightedMovingAverage"/> class by using the
 /// specified smoothing constant, expected tick interval and time unit of
 /// the tick interval.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> containing the configuration settings
 /// for the metric.
 /// </param>
 /// <param name="alpha">
 /// The smoothing constant.
 /// </param>
 /// <param name="interval">
 /// The expected tick interval.
 /// </param>
 /// <param name="unit">
 /// The time unit that should be used to compute the rate.
 /// </param>
 /// <param name="context">
 /// A <see cref="MetricContext"/> that contains the shared
 /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>.
 /// </param>
 public ExponentialWeightedMovingAverage(MetricConfig config, double alpha,
                                         TimeSpan interval, TimeUnit unit, MetricContext context)
     : base(config.WithAdditionalTag(MetricType.EWMA.AsTag()), context)
 {
     interval_       = interval.Ticks;
     alpha_          = alpha;
     ticks_per_unit_ = 1.ToTicks(unit);
     uncounted_      = 0;
     rate_           = 0.0;
     last_tick_      = context_.Tick;
     initialized_    = false;
 }
コード例 #9
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)
            });
        }
コード例 #10
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;
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Counter"/> class that
 /// uses the specified executor to perform the counter updates (
 /// increment/decrement).
 /// </summary>
 public Counter(MetricConfig config, long initial, MetricContext context)
     : base(config.WithAdditionalTag(MetricType.Counter.AsTag()), context)
 {
     count_ = initial;
 }
コード例 #12
0
ファイル: Counter.cs プロジェクト: joethinh/nohros-must
 /// <summary>
 /// Initializes a new instance of the <see cref="Counter"/> class that
 /// uses the specified executor to perform the counter updates (
 /// increment/decrement).
 /// </summary>
 public Counter(MetricConfig config, long initial, MetricContext context)
   : base(config.WithAdditionalTag(MetricType.Counter.AsTag()), context) {
   count_ = initial;
 }
コード例 #13
0
ファイル: MaxGauge.cs プロジェクト: brumschlag/nohros-must
 /// <summary>
 /// Initializes a new instance of the <see cref="MaxGauge"/> class
 /// by using the given <paramref name="config"/> object.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> containing the configuration settings
 /// for the metric.
 /// </param>
 public MaxGauge(MetricConfig config)
     : base(config.WithAdditionalTag(MetricType.Gauge.AsTag()))
 {
 }
コード例 #14
0
ファイル: MinGauge.cs プロジェクト: joethinh/nohros-must
 /// <summary>
 /// Initializes a new instance of the <see cref="MinGauge"/> class
 /// by using the given <paramref name="config"/> object.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> containing the configuration settings
 /// for the metric.
 /// </param>
 public MinGauge(MetricConfig config)
   : base(config.WithAdditionalTag(MetricType.Gauge.AsTag())) {
   value_ = long.MaxValue;
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="ExponentialWeightedMovingAverage"/> class by using the
 /// specified smoothing constant, expected tick interval and time unit of
 /// the tick interval.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> containing the configuration settings
 /// for the metric.
 /// </param>
 /// <param name="alpha">
 /// The smoothing constant.
 /// </param>
 /// <param name="interval">
 /// The expected tick interval.
 /// </param>
 /// <param name="unit">
 /// The time unit that should be used to compute the rate.
 /// </param>
 /// <param name="context">
 /// A <see cref="MetricContext"/> that contains the shared
 /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>.
 /// </param>
 public ExponentialWeightedMovingAverage(MetricConfig config, double alpha,
   TimeSpan interval, TimeUnit unit, MetricContext context)
   : base(config.WithAdditionalTag(MetricType.EWMA.AsTag()), context) {
   interval_ = interval.Ticks;
   alpha_ = alpha;
   ticks_per_unit_ = 1.ToTicks(unit);
   uncounted_ = 0;
   rate_ = 0.0;
   last_tick_ = context_.Tick;
   initialized_ = false;
 }
コード例 #16
0
ファイル: MaxGauge.cs プロジェクト: joethinh/nohros-must
 /// <summary>
 /// Initializes a new instance of the <see cref="MaxGauge"/> class
 /// by using the given <paramref name="config"/> object.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> containing the configuration settings
 /// for the metric.
 /// </param>
 public MaxGauge(MetricConfig config)
   : base(config.WithAdditionalTag(MetricType.Gauge.AsTag())) {
 }
コード例 #17
0
ファイル: Histogram.cs プロジェクト: joethinh/nohros-must
 CallableGaugeWrapper MaxGauge(MetricConfig config) {
   return
     new CallableGaugeWrapper(
       config.WithAdditionalTag("statistic", "max"),
       snapshot => snapshot.Max);
 }
コード例 #18
0
ファイル: StepCounter.cs プロジェクト: joethinh/nohros-must
 /// <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;
 }
コード例 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MinGauge"/> class
 /// by using the given <paramref name="config"/> object.
 /// </summary>
 /// <param name="config">
 /// A <see cref="MetricConfig"/> containing the configuration settings
 /// for the metric.
 /// </param>
 public MinGauge(MetricConfig config)
     : base(config.WithAdditionalTag(MetricType.Gauge.AsTag()))
 {
     value_ = long.MaxValue;
 }
コード例 #20
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);
        }
コード例 #21
0
ファイル: Histogram.cs プロジェクト: joethinh/nohros-must
 CallableGaugeWrapper PercentileGauge(MetricConfig config, double percentile) {
   // We need to divide the percentile to 100 because the percentiles from
   // the SnapshotConfig is in range 0 to 100 and the Snapshot.Quantile
   // methof computes percentiles in range 0.0 to 1.0.
   return
     new CallableGaugeWrapper(
       config.WithAdditionalTag("statistic",
         "percentile_" + (percentile).ToString("#0.####")),
       snapshot => snapshot.Quantile(percentile/100));
 }
コード例 #22
0
ファイル: Histogram.cs プロジェクト: joethinh/nohros-must
 CallableGaugeWrapper StdDevGauge(MetricConfig config) {
   return
     new CallableGaugeWrapper(
       config.WithAdditionalTag("statistic", "stddev"),
       snapshot => snapshot.StdDev);
 }
コード例 #23
0
ファイル: Histogram.cs プロジェクト: joethinh/nohros-must
 CallableGaugeWrapper CountGauge(MetricConfig config) {
   return
     new CallableGaugeWrapper(
       config.WithAdditionalTag("statistic", "count"),
       snapshot => snapshot.Size);
 }