private static IEnumerable <Metric> BucketHistogramValueToHistogram( BucketHistogramValue value, MetricTags tags, Func <string, string> labelNameFormatter) { var histogram = new Histogram { sample_count = (ulong)value.Count, sample_sum = value.Sum }; var cumulativeCount = 0ul; foreach (var keyValuePair in value.Buckets.OrderBy(x => x.Key)) { histogram.bucket.Add(new Bucket { cumulative_count = cumulativeCount += Convert.ToUInt64(keyValuePair.Value), upper_bound = keyValuePair.Key }); } var result = new List <Metric> { new Metric { histogram = histogram, label = tags.ToLabelPairs(labelNameFormatter) } }; return(result); }
private IEnumerable <BucketTimerValueSource> SetupBucketTimers() { const int count = 5; var meterValue = new MeterValue( count, 1, 2, 3, 4, TimeUnit.Seconds, new[] { new MeterValue.SetItem("item", 0.5, new MeterValue(1, 2, 3, 4, 5, TimeUnit.Seconds, new MeterValue.SetItem[0])) }); var histogramValue = new BucketHistogramValue(count, 1, new Dictionary <double, double> { { 1, 1 } }); var timerValue = new BucketTimerValue(meterValue, histogramValue, 0, TimeUnit.Nanoseconds); var timer = new BucketTimerValueSource( BucketTimerNameDefault, ConstantValue.Provider(timerValue), Unit.Requests, TimeUnit.Seconds, TimeUnit.Milliseconds, Tags); return(new[] { timer }); }
public BucketTimerValue(MeterValue rate, BucketHistogramValue histogram, long activeSessions, TimeUnit durationUnit) { Rate = rate; Histogram = histogram; ActiveSessions = activeSessions; DurationUnit = durationUnit; }
public static BucketTimerValueSource FromSerializableMetric(this BucketTimerMetric source) { var rateUnit = source.RateUnit.FromUnit(); var durationUnit = source.DurationUnit.FromUnit(); var rateValue = new MeterValue( source.Count, source.Rate.MeanRate, source.Rate.OneMinuteRate, source.Rate.FiveMinuteRate, source.Rate.FifteenMinuteRate, rateUnit); var histogramValue = new BucketHistogramValue( source.Count, source.Histogram.Sum, new ReadOnlyDictionary <double, double>(source.Histogram.Buckets)); var timerValue = new BucketTimerValue(rateValue, histogramValue, source.ActiveSessions, durationUnit); return(new BucketTimerValueSource( source.Name, ConstantValue.Provider(timerValue), source.Unit, rateUnit, durationUnit, source.Tags.FromDictionary())); }
private IEnumerable <BucketHistogramValueSource> SetupBucketHistograms() { var histogramValue = new BucketHistogramValue(1, 1, new Dictionary <double, double> { { 1, 1 } }); var histogram = new BucketHistogramValueSource(BucketHistogramNameDefault, ConstantValue.Provider(histogramValue), Unit.Items, Tags); return(new[] { histogram }); }
public static BucketHistogramValueSource FromSerializableMetric(this BucketHistogramMetric source) { var histogramValue = new BucketHistogramValue( source.Count, source.Sum, new ReadOnlyDictionary <double, double>(source.Buckets)); return(new BucketHistogramValueSource( source.Name, ConstantValue.Provider(histogramValue), source.Unit, source.Tags.FromDictionary())); }
public static void AddBucketHistogramValues( this BucketHistogramValue histogram, IDictionary <string, object> values, IDictionary <string, string> fields) { if (values == null) { return; } fields.TryAddValuesForKey(values, BucketHistogramFields.Count.ToString(), histogram.Count); fields.TryAddValuesForKey(values, BucketHistogramFields.Sum.ToString(), histogram.Sum); foreach (var bucket in histogram.Buckets) { if (double.IsPositiveInfinity(bucket.Key)) { values[$"{BucketHistogramFields.Bucket}Inf"] = bucket.Value; } else { values[$"{BucketHistogramFields.Bucket}{bucket.Key}"] = bucket.Value; } } }