public PrometheusExporterMetricsService(MetricExporter exporter, MagicOnionOpenTelemetryOptions options, IConfiguration configuration, ILogger <PrometheusExporterMetricsService> logger) { this.logger = logger; this.options = options; if (exporter is PrometheusExporter prometheusExporter) { server = new PrometheusExporterMetricsHttpServerCustom(prometheusExporter, options.MetricsExporterHostingEndpoint); } }
public PrometheusExporterMetricsService(MetricExporter exporter, MagicOnionOpenTelemetryOptions options, IConfiguration configuration, ILogger <PrometheusExporterMetricsService> logger) { this.logger = logger; this.options = options; if (exporter is PrometheusExporter prometheusExporter) { metricsExporterHostingEndpoint = configuration.GetSection("MagicOnion:OpenTelemetry").GetValue("PrometheusMetricsHostingEndpoint", options.MetricsExporterEndpoint); server = new PrometheusExporterMetricsHttpServerCustom(prometheusExporter, metricsExporterHostingEndpoint); } }
/// <summary> /// Initializes a new instance of the <see cref="SteeltoeProcessor"/> class. /// </summary> /// <param name="exporter">Metric exporter instance.</param> /// <param name="exportInterval">Interval at which metrics are pushed to Exporter.</param> public SteeltoeProcessor(MetricExporter exporter, TimeSpan exportInterval) { _exporter = exporter ?? throw new ArgumentNullException(nameof(exporter)); LongMetrics = new List <ProcessedMetric <long> >(); DoubleMetrics = new List <ProcessedMetric <double> >(); _exportInterval = exportInterval; _cts = new CancellationTokenSource(); if (exportInterval < TimeSpan.MaxValue) { _worker = Task.Factory.StartNew( s => Worker((CancellationToken)s), _cts.Token).ContinueWith((task) => Console.WriteLine("error"), TaskContinuationOptions.OnlyOnFaulted); } }
private MeterFactory(MeterBuilder meterBuilder) { this.metricProcessor = meterBuilder.MetricProcessor ?? new NoOpMetricProcessor(); this.metricExporter = meterBuilder.MetricExporter ?? new NoOpMetricExporter(); // We only have PushMetricController now with only configurable thing being the push interval this.pushMetricController = new PushMetricController( this.meterRegistry, this.metricProcessor, this.metricExporter, meterBuilder.MetricPushInterval == default(TimeSpan) ? this.defaultPushInterval : meterBuilder.MetricPushInterval, new CancellationTokenSource()); this.defaultMeter = new MeterSdk(string.Empty, this.metricProcessor); }
/// <summary> /// Initializes a new instance of the <see cref="SteeltoeProcessor"/> class. /// </summary> /// <param name="exporter">Metric exporter instance.</param> /// <param name="aggregationInterval">Interval at which metrics are pushed to Exporter.</param> public SteeltoeProcessor(MetricExporter exporter, TimeSpan aggregationInterval) { this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter)); // TODO make this thread safe. this.LongMetrics = new List <Metric <long> >(); this.DoubleMetrics = new List <Metric <double> >(); this.aggregationInterval = aggregationInterval; this.cts = new CancellationTokenSource(); if (exporter == null || aggregationInterval < TimeSpan.MaxValue) { this.worker = Task.Factory.StartNew( s => this.Worker((CancellationToken)s), this.cts.Token).ContinueWith((task) => Console.WriteLine("error"), TaskContinuationOptions.OnlyOnFaulted); } }
private static void CollectMetrics(UngroupedBatcher simpleProcessor, MetricExporter exporter) { var meter = MeterFactory.Create(mb => { mb.SetMetricProcessor(simpleProcessor); mb.SetMetricExporter(exporter); mb.SetMetricPushInterval(TimeSpan.FromMilliseconds(metricPushIntervalMsec)); }).GetMeter("library1"); var testCounter = meter.CreateInt64Counter("testCounter"); var testMeasure = meter.CreateInt64Measure("testMeasure"); var labels1 = new List <KeyValuePair <string, string> >(); labels1.Add(new KeyValuePair <string, string>("dim1", "value1")); labels1.Add(new KeyValuePair <string, string>("dim2", "value1")); var labels2 = new List <KeyValuePair <string, string> >(); labels2.Add(new KeyValuePair <string, string>("dim1", "value2")); labels2.Add(new KeyValuePair <string, string>("dim2", "value2")); var defaultContext = default(SpanContext); for (int i = 0; i < 10; i++) { testCounter.Add(defaultContext, 100, meter.GetLabelSet(labels1)); testCounter.Add(defaultContext, 10, meter.GetLabelSet(labels1)); testCounter.Add(defaultContext, 200, meter.GetLabelSet(labels2)); testCounter.Add(defaultContext, 10, meter.GetLabelSet(labels2)); testMeasure.Record(defaultContext, 10, meter.GetLabelSet(labels1)); testMeasure.Record(defaultContext, 100, meter.GetLabelSet(labels1)); testMeasure.Record(defaultContext, 5, meter.GetLabelSet(labels1)); testMeasure.Record(defaultContext, 500, meter.GetLabelSet(labels1)); } }
/// <summary> /// Initializes a new instance of the <see cref="SteeltoeProcessor"/> class. /// </summary> /// <param name="exporter">Metric exporter instance.</param> public SteeltoeProcessor(MetricExporter exporter) : this(exporter, TimeSpan.MaxValue) { }
/// <summary> /// Configures Metric Exporter. /// </summary> /// <param name="metricExporter">MetricExporter instance.</param> /// <returns>The meter builder instance for chaining.</returns> public MeterBuilder SetMetricExporter(MetricExporter metricExporter) { this.MetricExporter = metricExporter; return(this); }
/// <summary> /// Sets exporter. /// </summary> /// <param name="exporter">Exporter instance.</param> /// <returns>Returns <see cref="MeterProviderBuilder"/> for chaining.</returns> public MeterProviderBuilder SetExporter(MetricExporter exporter) { this.metricExporter = exporter ?? new NoopMetricExporter(); return(this); }
internal MeterProviderBuilder() { this.metricExporter = new NoopMetricExporter(); this.metricProcessor = new NoopMetricProcessor(); this.metricPushInterval = DefaultPushInterval; }