/// <inheritdoc /> public void Track(ApdexOptions options, Action action) { using (_registry.Apdex(options, () => Advanced.BuildApdex(options)).NewContext()) { action(); } }
public IApdex Apdex <T>(ApdexOptions options, Func <T> builder) where T : IApdexMetric { EnsureContextLabel(options); EnsureSamplingType(options); var registry = _contexts.GetOrAdd(options.Context, _newContextRegistry); return(registry.Apdex(options, builder)); }
private static async Task Main(string[] args) { var metrics = AppMetrics.CreateDefaultBuilder().Build(); var counter = new CounterOptions { Name = "my_counter" }; metrics.Measure.Counter.Increment(counter); var gauge = new GaugeOptions { Name = "my_gauge" }; metrics.Measure.Gauge.SetValue(gauge, 1); var meter = new MeterOptions { Name = "my_meter" }; metrics.Measure.Meter.Mark(meter); var histogram = new HistogramOptions { Name = "my_histogram" }; metrics.Measure.Histogram.Update(histogram, 10); var timer = new TimerOptions { Name = "my_timer" }; using (metrics.Measure.Timer.Time(timer)) { await Task.Delay(100); } var apdex = new ApdexOptions { Name = "my_apdex", AllowWarmup = false, ApdexTSeconds = 0.1 }; using (metrics.Measure.Apdex.Track(apdex)) { await Task.Delay(200); } var snapshot = metrics.Snapshot.Get(); using (var stream = new MemoryStream()) { await metrics.DefaultOutputMetricsFormatter.WriteAsync(stream, snapshot); var result = Encoding.UTF8.GetString(stream.ToArray()); WriteLine(result); } ReadKey(); }
public IApdex Track(ApdexOptions options) { if (options.WithReservoir != null) { return(Track(options, () => this.BuildApdex(options, options.WithReservoir()))); } return(_registry.Apdex(options, () => this.BuildApdex(options))); }
public IApdex Apdex <T>(ApdexOptions options, Func <T> builder) where T : IApdexMetric { return(_apdexScores.GetOrAdd(options.Name, () => { var apdex = builder(); var valueSource = new ApdexValueSource(options.Name, apdex, AllTags(options.Tags), options.ResetOnReporting); return Tuple.Create((IApdex)apdex, valueSource); })); }
public MetricContextTestFixture() { ApdexOptions = new ApdexOptions { Name = "apdex" }; CounterOptions = new CounterOptions { Name = "counter" }; GaugeOptions = new GaugeOptions { Name = "gauge" }; HistogramOptions = new HistogramOptions { Name = "histogram" }; MeterOptions = new MeterOptions { Name = "meter" }; TimerOptions = new TimerOptions { Name = "timer" }; var tags = new GlobalMetricTags { { "key1", "value1" }, { "key2", "value2" } }; var contextualTags = new ContextualMetricTagProviders { { "key1", () => new Guid().ToString() }, { "key2", () => new Guid().ToString() } }; var samplingProvider = new DefaultSamplingReservoirProvider(() => new DefaultForwardDecayingReservoir()); Registry = new DefaultMetricContextRegistry("context_label", tags, contextualTags); ApdexBuilder = new DefaultApdexBuilder(samplingProvider); HistogramBuilder = new DefaultHistogramBuilder(samplingProvider); CounterBuilder = new DefaultCounterBuilder(); GaugeBuilder = new DefaultGaugeBuilder(); MeterBuilder = new DefaultMeterBuilder(); TimerBuilder = new DefaultTimerBuilder(samplingProvider); Clock = new StopwatchClock(); }
static MeasureApdexBenchmark() { Metrics = new ApdexOptions[NumberOfMetrics]; for (var i = 0; i < NumberOfMetrics; i++) { Metrics[i] = new ApdexOptions { Name = $"metric_{i:D4}" }; } }
public void track_action_adds_to_registry() { var metricName = "test_apdex"; var options = new ApdexOptions { Name = metricName }; _manager.Track(options, async() => { await Task.Delay(10); }); var data = _fixture.Registry.GetData(new NoOpMetricsFilter()); data.Contexts.Single().ApdexScores.FirstOrDefault(x => x.Name == metricName).Should().NotBeNull(); }
public void Context_doesnt_exist_returns_default_apdex_when_multidimensional() { var metricName = "DefaultMetricValuesProviderTests_apdex_without_context_multi"; var options = new ApdexOptions { Name = metricName, Context = "different" }; _measure.Apdex.Track(options, _tags[1], () => _clock.Advance(TimeUnit.Seconds, 3)); _provider.GetApdexValue(Context, _tags[1].AsMetricName(metricName)).Should().Be(default(ApdexValue)); }
public void Can_get_apdex_value() { var metricName = "DefaultMetricValuesProviderTests_apdex"; var options = new ApdexOptions { Name = metricName, Context = Context }; _measure.Apdex.Track(options, () => _clock.Advance(TimeUnit.Seconds, 3)); _provider.GetApdexValue(Context, metricName).Frustrating.Should().Be(1); }
public void can_add_multidimensional_to_registry() { var metricName = "apdex_test_multi"; var options = new ApdexOptions { Name = metricName }; _provider.Instance(options, _fixture.Tags[0]); _filter.WhereMetricName(name => name == _fixture.Tags[0].AsMetricName(metricName)); _fixture.Registry.GetData(_filter).Contexts.First().ApdexScores.Count().Should().Be(1); }
/// <inheritdoc /> public IApdex Apdex <T>(ApdexOptions options, MetricTags tags, Func <T> builder) where T : IApdexMetric { if (_nullMetricsRegistry.IsValueCreated) { return(_nullMetricsRegistry.Value.Apdex(options, tags, builder)); } EnsureContextLabel(options); var contextRegistry = _contexts.GetOrAdd(options.Context, _newContextRegistry); return(contextRegistry.Apdex(options, tags, builder)); }
public void can_get_apdex_value_with_tags() { var metricName = "DefaultMetricValuesProviderTests_apdex"; var options = new ApdexOptions { Name = metricName, Context = Context }; var tags = new MetricTags("key", "value"); _measure.Apdex.Track(options, tags, () => _clock.Advance(TimeUnit.Seconds, 3)); _provider.GetApdexValue(Context, tags.AsMetricName(metricName)).Frustrating.Should().Be(1); }
public void can_add_instance_to_registry() { var metricName = "apdex_test"; var options = new ApdexOptions { Name = metricName }; _provider.Instance(options); _filter.WhereMetricName(name => name == metricName); _fixture.Registry.GetData(_filter).Contexts.First().ApdexScores.Count().Should().Be(1); }
public void does_not_throw_on_metrics_of_different_type_with_same_name() { ((Action)(() => { var name = "Test"; var apdexOptions = new ApdexOptions { Name = name, MeasurementUnit = Unit.Calls, }; var counterOptions = new CounterOptions { Name = name, MeasurementUnit = Unit.Calls, }; var meterOptions = new MeterOptions { Name = name, MeasurementUnit = Unit.Calls }; var gaugeOptions = new GaugeOptions { Name = name, MeasurementUnit = Unit.Calls }; var histogramOptions = new HistogramOptions { Name = name, MeasurementUnit = Unit.Calls }; var timerOptions = new TimerOptions { Name = name, MeasurementUnit = Unit.Calls }; _fixture.Metrics.Measure.Apdex.Track(apdexOptions); _fixture.Metrics.Measure.Gauge.SetValue(gaugeOptions, () => 0.0); _fixture.Metrics.Measure.Counter.Increment(counterOptions); _fixture.Metrics.Measure.Meter.Mark(meterOptions); _fixture.Metrics.Measure.Histogram.Update(histogramOptions, 1L); _fixture.Metrics.Measure.Timer.Time(timerOptions); })).ShouldNotThrow(); }
public void can_add_add_new_instance_to_registry() { var metricName = "apdex_metric_test"; var options = new ApdexOptions { Name = metricName }; var apdexMetric = _fixture.Builder.Apdex.Build(_defaultReservoir, 0.5, true, _fixture.Clock); _provider.Instance(options, () => apdexMetric); _filter.WhereMetricName(name => name == metricName); _fixture.Registry.GetData(_filter).Contexts.First().ApdexScores.Count().Should().Be(1); }
public void Can_add_add_new_multidimensional_to_registry() { var metricName = "apdex_metric_test_multi"; var options = new ApdexOptions { Name = metricName }; var apdexMetric1 = _fixture.Builder.Apdex.Build(_defaultReservoir, 0.5, true, _fixture.Clock); _provider.Instance(options, _fixture.Tags[0], () => apdexMetric1); _filter.WhereName(name => name == _fixture.Tags[0].AsMetricName(metricName)); _fixture.Registry.GetData(_filter).Contexts.First().ApdexScores.Count().Should().Be(1); }
public void Track_action_adds_multidimensional_metrics_to_registry() { var metricName = "test_apdex_multi"; var options = new ApdexOptions { Name = metricName }; _manager.Track(options, _fixture.Tags[0], async() => { await Task.Delay(10); }); _manager.Track(options, _fixture.Tags[1], async() => { await Task.Delay(10); }); var data = _fixture.Registry.GetData(new NullMetricsFilter()); data.Contexts.Single().ApdexScores.FirstOrDefault(x => x.Name == _fixture.Tags[0].AsMetricName(metricName)).Should().NotBeNull(); data.Contexts.Single().ApdexScores.FirstOrDefault(x => x.Name == _fixture.Tags[1].AsMetricName(metricName)).Should().NotBeNull(); }
public async Task Track_adds_to_registry() { var metricName = "test_apdex_no_action"; var options = new ApdexOptions { Name = metricName }; using (_manager.Track(options)) { await Task.Delay(10); } var data = _fixture.Registry.GetData(new NullMetricsFilter()); data.Contexts.Single().ApdexScores.FirstOrDefault(x => x.Name == metricName).Should().NotBeNull(); }
public void can_use_custom_reservoir() { var reservoirMock = new Mock <IReservoir>(); reservoirMock.Setup(r => r.Update(It.IsAny <long>())); reservoirMock.Setup(r => r.GetSnapshot()).Returns(() => new UniformSnapshot(100, new long[100])); reservoirMock.Setup(r => r.Reset()); var options = new ApdexOptions { Name = "apdex_custom_reservoir", Reservoir = new Lazy <IReservoir>(() => reservoirMock.Object) }; var apdex = _provider.Instance(options); apdex.Track(100L); reservoirMock.Verify(r => r.Update(100L), Times.Once); }
public IApdex Apdex <T>(ApdexOptions options, Func <T> builder) where T : IApdexMetric { return(_apdexScores.GetOrAdd( options.Name, () => { var allTags = AllTags(options.Tags); Logger.Debug("Adding Apdex {Name} - {@Options} {MesurementUnit} {@Tags}", options.Name, options, options.MeasurementUnit.ToString(), allTags.ToDictionary()); var apdex = builder(); var valueSource = new ApdexValueSource( options.Name, apdex, allTags, options.ResetOnReporting); return Tuple.Create((IApdex)apdex, valueSource); })); }
public void can_use_custom_reservoir_when_multidimensional() { var reservoirMock = new Mock <IReservoir>(); reservoirMock.Setup(r => r.Update(It.IsAny <long>())); reservoirMock.Setup(r => r.GetSnapshot()).Returns(() => new UniformSnapshot(100, 100.0, new long[100])); reservoirMock.Setup(r => r.Reset()); var options = new ApdexOptions { Name = "apdex_custom_reservoir_multi", Reservoir = () => reservoirMock.Object }; var apdex = _provider.Instance(options, _fixture.Tags[0]); apdex.Track(100L); reservoirMock.Verify(r => r.Update(100L), Times.Once); }
public IApdex Apdex<T>(ApdexOptions options, Func<T> builder) where T : IApdexMetric { return _apdexInstance; }
/// <inheritdoc /> public IApdex Apdex <T>(ApdexOptions options, MetricTags tags, Func <T> builder) where T : IApdexMetric { return(_apdexInstance); }
public IApdex Apdex <T>(ApdexOptions options, Func <T> builder) where T : IApdexMetric { return(NullMetric.Instance); }
public static IApdexMetric BuildApdex(this IAdvancedMetrics context, ApdexOptions options) { return(new ApdexMetric(options.SamplingType, options.SampleSize, options.ExponentialDecayFactor, context.Clock, options.ApdexTSeconds)); }
#pragma warning disable SA1008, SA1009 public static IHealthCheckFactory RegisterMetricCheck( this IHealthCheckFactory factory, string name, ApdexOptions options, Func <ApdexValue, (string message, bool result)> passing,
/// <inheritdoc /> public ApdexContext Track(ApdexOptions options) { return(_registry.Apdex(options, () => Advanced.BuildApdex(options)).NewContext()); }
public IApdex Track <T>(ApdexOptions options, Func <T> builder) where T : IApdexMetric { return(_registry.Apdex(options, builder)); }
public static IApdexMetric BuildApdex(this IAdvancedMetrics context, ApdexOptions options, IReservoir reservoir) { return(new ApdexMetric(new ApdexProvider(reservoir, options.ApdexTSeconds), context.Clock)); }