/// <summary> /// Observes a single event with the given value. /// </summary> /// <param name="val">The Value.</param> public void Observe(double val) { histogram.Observe(val); // AppInsights might not be on and the metric could be null appInsightsMetric?.TrackValue(val); }
public void ManyBuckets_Observe() { for (var i = 0; i < _opIterations; i++) { _histogramManyBuckets.Observe(i); } }
public void Observe() { for (var i = 0; i < _opIterations; i++) { _histogramDefaultBuckets.Observe(i); } }
public static async Task <T> Measure <T>(Func <Task <T> > action, IHistogram metric, ICounter errorCounter = null) { var stopwatch = new Stopwatch(); stopwatch.Start(); T result; try { result = await action(); } catch (Exception) { errorCounter?.Inc(); throw; } finally { stopwatch.Stop(); metric.Observe(stopwatch.ElapsedTicks / (double)Stopwatch.Frequency); } return(result); }
protected override void Dispose(bool disposing) { if (disposing) { histogram.Observe(useTicks ? watch.ElapsedTicks : watch.ElapsedMilliseconds); } base.Dispose(disposing); }
public void Observe() { noLabel.Observe(2); Assert.Equal(1, noLabel.Count()); Assert.Equal(2, noLabel.Sum()); Assert.Equal(0, noLabel.BucketValue(1)); Assert.Equal(1, noLabel.BucketValue(2.5)); noLabel.WithLabels().Observe(4); Assert.Equal(2, noLabel.Count()); Assert.Equal(6, noLabel.Sum()); Assert.Equal(0, noLabel.BucketValue(1)); Assert.Equal(1, noLabel.BucketValue(2.5)); Assert.Equal(2, noLabel.BucketValue(5)); Assert.Equal(2, noLabel.BucketValue(7.5)); Assert.Equal(2, noLabel.BucketValue(10)); Assert.Equal(2, noLabel.BucketValue(double.PositiveInfinity)); }
public static void Observe(this IHistogram observer, double val, DateTimeOffset timestamp) { observer.Observe(val, timestamp.ToUnixTimeMilliseconds()); }