/// <inheritdoc /> public void Decrement(CounterOptions options, long amount, Action <MetricItem> itemSetup) { var item = new MetricItem(); itemSetup(item); _registry.Counter(options, () => Advanced.BuildCounter(options)).Decrement(item, amount); }
/// <inheritdoc /> public ICounter Counter <T>(CounterOptions options, MetricTags tags, Func <T> builder) where T : ICounterMetric { var metricName = tags.AsMetricName(options.Name); return(_counters.GetOrAdd( metricName, () => { var allTags = AllTags(MetricTags.Concat(options.Tags, tags)); Logger.Debug("Adding Counter {Name} - {@Options} {MesurementUnit} {@Tags}", metricName, options, options.MeasurementUnit.ToString(), allTags.ToDictionary()); var counter = builder(); var valueSource = new CounterValueSource( metricName, counter, options.MeasurementUnit, allTags, options.ResetOnReporting, options.ReportItemPercentages, options.ReportSetItems); return Tuple.Create((ICounter)counter, valueSource); })); }
public static void CountDecrement(CounterOptions options, long amount) { Preconditions.CheckNotNull(options); Preconditions.CheckNotNull(amount); MetricsCollector.ForEach(mroot => { mroot.Measure.Counter.Decrement(options, amount); }); }
internal static DefaultCounter Factory(string name, Action <CounterOptions> init) { var options = new CounterOptions(); init(options); return(new DefaultCounter(name, options)); }
public MetricsRegistry(IMetricsRoot metricsRoot, IConfiguration configuration) { this.metricsRoot = metricsRoot; this.findQueries = new CounterOptions { Name = configuration["app:name"] }; }
public void TestCounterIncrement() { // Arrange _measureCounterMetricsMock.Setup(m => m.Increment(It.IsAny <CounterOptions>(), It.IsAny <MetricTags>(), It.IsAny <long>())); _measureMetricsMock.Setup(m => m.Counter).Returns(_measureCounterMetricsMock.Object); ITestMetric1 testMetric1 = _metricFactory.CreateMetric <ITestMetric1>(); // Act testMetric1.RequestCount("endpoint1", 200).Increment(5); // Assert _measureCounterMetricsMock.VerifyAll(); Assert.AreEqual(1, _measureCounterMetricsMock.Invocations.Count); CounterOptions counterOptions = (CounterOptions)_measureCounterMetricsMock.Invocations[0].Arguments[0]; Assert.AreEqual("RequestCount", counterOptions.Name); MetricTags metricTags = (MetricTags)_measureCounterMetricsMock.Invocations[0].Arguments[1]; Assert.AreEqual(2, metricTags.Keys.Length); Assert.AreEqual("endpoint", metricTags.Keys[0]); Assert.AreEqual("httpStatus", metricTags.Keys[1]); Assert.AreEqual(2, metricTags.Values.Length); Assert.AreEqual("endpoint1", metricTags.Values[0]); Assert.AreEqual("200", metricTags.Values[1]); Assert.AreEqual(5L, _measureCounterMetricsMock.Invocations[0].Arguments[2]); }
internal DotNetEventListener(IEventSourceStatsCollector collector, Action <Exception> errorHandler, bool enableDebugging, IMetrics metrics) : base() { _collector = collector; _errorHandler = errorHandler; _enableDebugging = enableDebugging; _metrics = metrics; if (_enableDebugging) { _cpuConsumed = new TimerOptions() { Context = DotNetRuntimeMetricsRegistry.ContextName, MeasurementUnit = Unit.None, DurationUnit = TimeUnit.Nanoseconds, Name = "dotnet_debug_cpu_nanoseconds_total", Tags = new MetricTags("collector", collector.GetType().Name.ToSnakeCase()) }; } _eventTypeCounts = new CounterOptions() { Context = DotNetRuntimeMetricsRegistry.ContextName, MeasurementUnit = Unit.Items, ReportItemPercentages = false }; EventSourceCreated += OnEventSourceCreated; }
public DefaultMetricsReportRunner(IMetrics metrics, MetricsReporterCollection reporters) { _metrics = metrics ?? throw new ArgumentNullException(nameof(metrics)); _reporters = reporters ?? throw new ArgumentNullException(nameof(reporters)); _successCounter = new CounterOptions { Context = AppMetricsConstants.InternalMetricsContext, MeasurementUnit = Unit.Items, ResetOnReporting = true, ReportItemPercentages = false, ReportSetItems = false, Name = "report_success" }; _failedCounter = new CounterOptions { Context = AppMetricsConstants.InternalMetricsContext, MeasurementUnit = Unit.Items, ResetOnReporting = true, ReportItemPercentages = false, ReportSetItems = false, Name = "report_failed" }; }
public QueueProcessor( ConnectionFactory queueConnectionFactory, ILogger <IQueueProcessor> logger, IRiverFlowProcessor riverFlowProcessor, IMetrics metrics, IOptions <QueueConfig> queueOptions) { this.queueConnectionFactory = queueConnectionFactory; this.queueConnectionFactory.DispatchConsumersAsync = true; this.logger = logger; this.riverFlowProcessor = riverFlowProcessor; this.metrics = metrics; this.queueConfig = queueOptions.Value.Validate(); this.queueProcessTimer = new TimerOptions { Name = "Queue Processing Timer", MeasurementUnit = App.Metrics.Unit.Calls, DurationUnit = TimeUnit.Seconds, RateUnit = TimeUnit.Minutes }; this.failureCounter = new CounterOptions { Name = "Queue Processing Failures", MeasurementUnit = App.Metrics.Unit.Errors, ReportItemPercentages = true }; }
public ICounter Counter <T>(CounterOptions options, Func <T> builder) where T : ICounterMetric { EnsureContextLabel(options); var registry = _contexts.GetOrAdd(options.Context, _newContextRegistry); return(registry.Counter(options, builder)); }
public static async Task Main() { long threshold = 1; var metricsBuilder = new MetricsBuilder(); var healthBuilder = new HealthBuilder(); var metrics = metricsBuilder.Report.ToInfluxDb(AppSetting.InfluxDB.Url, AppSetting.InfluxDB.DatabaseName, TimeSpan.FromSeconds(5)) .Report.ToConsole(TimeSpan.FromSeconds(5)) .Build() ; var health = healthBuilder.Configuration .Configure(p => { p.Enabled = true; p.ReportingEnabled = true; }) .Report .ToMetrics(metrics) .HealthChecks.AddProcessPrivateMemorySizeCheck("Private Memory Size", threshold) .HealthChecks.AddProcessVirtualMemorySizeCheck("Virtual Memory Size", threshold) .HealthChecks.AddProcessPhysicalMemoryCheck("Working Set", threshold) .HealthChecks.AddPingCheck("google ping", "google.com", TimeSpan.FromSeconds(10)) .Build(); var counter = new CounterOptions { Name = "my_counter" }; metrics.Measure.Counter.Increment(counter); var scheduler = new AppMetricsTaskScheduler(TimeSpan.FromSeconds(5), async() => { await Task.WhenAll(metrics.ReportRunner.RunAllAsync()); var healthStatus = await health.HealthCheckRunner.ReadAsync(); using (var stream = new MemoryStream()) { await health.DefaultOutputHealthFormatter .WriteAsync(stream, healthStatus); var result = Encoding.UTF8.GetString(stream.ToArray()); Console.WriteLine(result); } foreach (var reporter in health.Reporters) { await reporter.ReportAsync(health.Options, healthStatus); } }); scheduler.Start(); Console.ReadKey(); }
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 Reporter(ReportFactory reportFactory, IMetrics metrics, IScheduler scheduler, ILoggerFactory loggerFactory) { if (reportFactory == null) { throw new ArgumentNullException(nameof(reportFactory)); } if (metrics == null) { throw new ArgumentNullException(nameof(metrics)); } if (scheduler == null) { throw new ArgumentNullException(nameof(scheduler)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _reportGenerator = new DefaultReportGenerator(loggerFactory); _metrics = metrics; _scheduler = scheduler; _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger <Reporter>(); _providers = reportFactory.GetProviders(); if (_providers.Count <= 0) { return; } _metricReporters = new Dictionary <Type, IMetricReporter>(_providers.Count); foreach (var provider in _providers) { _metricReporters.Add(provider.Key, provider.Value.CreateMetricReporter(provider.Key.Name, _loggerFactory)); } _successCounter = new CounterOptions { Context = Constants.InternalMetricsContext, MeasurementUnit = Unit.Items, ResetOnReporting = true, Name = "report_success" }; _failedCounter = new CounterOptions { Context = Constants.InternalMetricsContext, MeasurementUnit = Unit.Items, ResetOnReporting = true, Name = "report_failed" }; }
public Metrics(IMetricsRoot metrics) { _metrics = metrics; _counter = new CounterOptions { Name = "my_counter" }; _metrics.Measure.Counter.Increment(_counter); _metrics.Measure.Counter.Decrement(_counter); }
public MetricsCounter(string name, IMeasureCounterMetrics counterMetrics, List <string> labelNames) : base(labelNames, new List <string>()) { this.counterMetrics = counterMetrics; this.counterOptions = new CounterOptions { Name = name }; }
public MyHostedSvc() { metrics = new MetricsBuilder().Build(); metrCounter = new CounterOptions { Name = "AppMetrics_Use" }; metrics.Measure.Counter.Increment(metrCounter); snapshot = metrics.Snapshot.Get(); // filters avilable }
public void QueryExecuted() { var options = new CounterOptions { Name = "QueriesExecuted", MeasurementUnit = Unit.Calls }; _settings.Metrics.Measure.Counter.Increment(options); }
public static void Count(MetricTags tags, CounterOptions options) { Preconditions.CheckNotNull(tags); Preconditions.CheckNotNull(options); MetricsCollector.ForEach(mroot => { mroot.Measure.Counter.Increment(options, tags); }); }
public ICounter Counter <T>(CounterOptions options, Func <T> builder) where T : ICounterMetric { return(_counters.GetOrAdd(options.Name, () => { var counter = builder(); return Tuple.Create((ICounter)counter, new CounterValueSource(options.Name, counter, options.MeasurementUnit, options.Tags)); })); }
public void CommandExecuted() { var options = new CounterOptions { Name = "CommandsExecuted", MeasurementUnit = Unit.Calls }; _mtx.Measure.Counter.Increment(options); }
public void QueryFailed() { var options = new CounterOptions { Name = "QueriesFailed", MeasurementUnit = Unit.Calls }; _mtx.Measure.Counter.Increment(options); }
public void CommandFailed() { var options = new CounterOptions { Name = "CommandsFailed", MeasurementUnit = Unit.Calls }; _settings.Metrics.Measure.Counter.Increment(options); }
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(); }
private void MarkSuccess(string op) { var opts = new CounterOptions { Name = "Success", MeasurementUnit = Unit.Calls, Context = context, }; metrics.Measure.Counter.Increment(opts); }
public ICounter Counter <T>(CounterOptions options, Func <T> builder) where T : ICounterMetric { return(_counters.GetOrAdd(options.Name, () => { var counter = builder(); var valueSource = new CounterValueSource(options.Name, counter, options.MeasurementUnit, AllTags(options.Tags), options.ResetOnReporting, options.ReportItemPercentages, options.ReportSetItems); return Tuple.Create((ICounter)counter, valueSource); })); }
private void MarkError(string op) { var opts = new CounterOptions { Name = "Error", MeasurementUnit = Unit.Errors, Context = context, }; metrics.Measure.Counter.Increment(opts); }
public void Can_decrement_counter_item_by_amount() { var metricName = "test_decrement_counter_item_by_amount"; var options = new CounterOptions { Name = metricName }; _manager.Decrement(options, 3L, "item1"); _fixture.Snapshot.GetCounterValue(_context, metricName).Count.Should().Be(-3L); }
public void Can_decrement_counter() { var metricName = "test_decrement_counter"; var options = new CounterOptions { Name = metricName }; _manager.Decrement(options); _fixture.Snapshot.GetCounterValue(_context, metricName).Count.Should().Be(-1L); }
public void Can_increment_counter_item() { var metricName = "test_increment_counter_item"; var options = new CounterOptions { Name = metricName }; _manager.Increment(options, "item1"); _fixture.Snapshot.GetCounterValue(_context, metricName).Count.Should().Be(1L); }
private void MarkHttpStatus(string op, HttpStatusCode status) { var opts = new CounterOptions { Name = "HttpStatus", MeasurementUnit = Unit.Calls, Context = context, }; metrics.Measure.Counter.Increment(opts); }