/// <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_ }); }
/// <summary> /// Initializes a new instance of the <see cref=" MeanRate"/> 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="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> public MeanRate(MetricConfig config, TimeUnit unit, MetricContext context) : base(config, context) { start_time_ = context_.Tick; count_ = new Counter(config, 0, context); ticks_per_unit_ = 1.ToTicks(unit); }
/// <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_ }); }
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) }); }
/// <summary> /// Initializes a new instance of the <see cref="AbstractMetric"/> 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> /// <param name="context"> /// A <see cref="MetricContext"/> that contains the shared /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>. /// </param> protected AbstractMetric(MetricConfig config, MetricContext context) { if (config == null || context == null) { throw new ArgumentNullException(config == null ? "config" : "context"); } Config = config; context_ = context; }
/// <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; }
/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="Histogram"/> by using the /// given <see cref="IResevoir"/>. /// </summary> /// <param name="config"> /// A <see cref="MetricConfig"/> containing the configuration settings /// for the metric. /// </param> /// <param name="stats"> /// A <see cref="SnapshotConfig"/> that defines the statistics that should /// be computed. /// </param> /// <param name="resevoir"> /// A <see cref="IResevoir"/> that can be used to store the computed /// values. /// </param> /// <param name="context"> /// A <see cref="MetricContext"/> that contains the shared /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>. /// </param> public Histogram(MetricConfig config, SnapshotConfig stats, IResevoir resevoir, MetricContext context) : base(config, context) { resevoir_ = resevoir; gauges_ = new List <CallableGaugeWrapper>(); if (stats.ComputeCount) { gauges_.Add(CountGauge(config)); } if (stats.ComputeMax) { gauges_.Add(MaxGauge(config)); } if (stats.ComputeMean) { gauges_.Add(MeanGauge(config)); } if (stats.ComputeMedian) { gauges_.Add(MedianGauge(config)); } if (stats.ComputeMin) { gauges_.Add(MinGauge(config)); } if (stats.ComputeStdDev) { gauges_.Add(StdDevGauge(config)); } foreach (var percentile in stats.Percentiles) { gauges_.Add(PercentileGauge(config, percentile)); } }
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) }); }
public BucketCounter(MetricConfig config, MetricContext context) : base(config, context) { }
/// <summary> /// Initializes a new instance of the <see cref="StepCounter"/> class /// by using the given <see cref="MetricConfig"/> 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="context"> /// The <see cref="MetricContext"/> to be used by the counter. /// </param> public StepCounter(MetricConfig config, MetricContext context) : this(config, TimeUnit.Seconds, context) { }
/// <summary> /// Initializes a new instance of the <see cref="StepCounter"/> class /// by using the given <see cref="MetricConfig"/> 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="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, TimeUnit unit, MetricContext context) : this(config, 0, unit, context) { }
/// <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="context"> /// The <see cref="MetricContext"/> to be used by the counter. /// </param> public StepCounter(MetricConfig config, long initial, MetricContext context) : this(config, initial, TimeUnit.Seconds, context) { }
/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="BasicCompositeMetric"/> by /// using the given list of sub-metrics. /// </summary> /// <param name="config"> /// A <see cref="MetricConfig"/> containing the configuration settings /// for the metric. /// </param> /// <param name="metrics"> /// </param> /// <param name="context"> /// A <see cref="MetricContext"/> that contains the shared /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>. /// </param> public BasicCompositeMetric(MetricConfig config, IEnumerable<IMetric> metrics, MetricContext context) : base(config, context) { Metrics = new ReadOnlyCollection<IMetric>(metrics.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="Histogram"/> by using the /// given <see cref="IResevoir"/>. /// </summary> /// <param name="config"> /// A <see cref="MetricConfig"/> containing the configuration settings /// for the metric. /// </param> /// <param name="stats"> /// A <see cref="SnapshotConfig"/> that defines the statistics that should /// be computed. /// </param> /// <param name="resevoir"> /// A <see cref="IResevoir"/> that can be used to store the computed /// values. /// </param> /// <param name="context"> /// A <see cref="MetricContext"/> that contains the shared /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>. /// </param> public Histogram(MetricConfig config, SnapshotConfig stats, IResevoir resevoir, MetricContext context) : base(config, context) { resevoir_ = resevoir; gauges_ = new List<CallableGaugeWrapper>(); if (stats.ComputeCount) { gauges_.Add(CountGauge(config)); } if (stats.ComputeMax) { gauges_.Add(MaxGauge(config)); } if (stats.ComputeMean) { gauges_.Add(MeanGauge(config)); } if (stats.ComputeMedian) { gauges_.Add(MedianGauge(config)); } if (stats.ComputeMin) { gauges_.Add(MinGauge(config)); } if (stats.ComputeStdDev) { gauges_.Add(StdDevGauge(config)); } foreach (var percentile in stats.Percentiles) { gauges_.Add(PercentileGauge(config, percentile)); } }
/// <summary> /// Creates a new <see cref="ExponentialWeightedMovingAverage"/> that /// computed a one minute load average and expectes to be ticked /// every 5 seconds. /// </summary> /// <param name="config"> /// A <see cref="MetricConfig"/> containing the configuration settings /// for the metric. /// </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> /// <returns> /// A <see cref="ExponentialWeightedMovingAverage"/> which /// expectes to be ticked every 5 seconds. /// </returns> public static ExponentialWeightedMovingAverage ForOneMinute( MetricConfig config, TimeUnit unit, MetricContext context) { return(new ExponentialWeightedMovingAverage(config, kOneMinuteAlpha, TimeSpan.FromSeconds(kFiveSecondsInterval), unit, context)); }
static MetricContext() { ForCurrentProcess = new MetricContext(); }
/// <summary> /// Initializes a new instance of the <see cref="BasicCompositeMetric"/> by /// using the given list of sub-metrics. /// </summary> /// <param name="config"> /// A <see cref="MetricConfig"/> containing the configuration settings /// for the metric. /// </param> /// <param name="metrics"> /// </param> /// <param name="context"> /// A <see cref="MetricContext"/> that contains the shared /// <see cref="Mailbox{T}"/> and <see cref="Clock"/>. /// </param> public BasicCompositeMetric(MetricConfig config, IEnumerable <IMetric> metrics, MetricContext context) : base(config, context) { Metrics = new ReadOnlyCollection <IMetric>(metrics.ToArray()); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="Counter"/> class. /// </summary> /// <param name="config"></param> /// <param name="context"></param> public Counter(MetricConfig config, MetricContext context) : this(config, 0, context) { }
public BucketCounter(MetricConfig config, TimeUnit unit, MetricContext context) : base(config, unit, context) { }
public Builder WithContext(MetricContext context) { Context = context; return(this); }