internal PrometheusExporterMiddleware(PrometheusExporter exporter) { this.exporter = exporter; }
/// <summary> /// Initializes a new instance of the <see cref="PrometheusExporterMiddleware"/> class. /// </summary> /// <param name="next">The next middleware in the pipeline.</param> /// <param name="exporter">The <see cref="PrometheusExporter"/> instance.</param> public PrometheusExporterMiddleware(RequestDelegate next, PrometheusExporter exporter) { this.next = next ?? throw new ArgumentNullException(nameof(next)); this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter)); }
/// <summary> /// Initializes a new instance of the <see cref="PrometheusExporterMetricsHttpServer"/> class. /// </summary> /// <param name="exporter">The <see cref="PrometheusExporter"/> instance.</param> public PrometheusExporterMetricsHttpServer(PrometheusExporter exporter) { this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter)); this.httpListener.Prefixes.Add(exporter.Options.Url); }
/// <summary> /// Initializes a new instance of the <see cref="PrometheusExporterMetricsHttpServer"/> class. /// </summary> /// <param name="exporter">The <see cref="PrometheusExporter"/> instance.</param> public PrometheusExporterMetricsHttpServer(PrometheusExporter exporter) { this.exporter = exporter; this.httpListener.Prefixes.Add(exporter.Options.Url); }
public PrometheusCollectionManager(PrometheusExporter exporter) { this.exporter = exporter; this.scrapeResponseCacheDurationInMilliseconds = this.exporter.Options.ScrapeResponseCacheDurationMilliseconds; this.onCollectRef = this.OnCollect; }
/// <summary> /// Serialize to Prometheus Format. /// </summary> /// <param name="exporter">Prometheus Exporter.</param> /// <param name="writer">StreamWriter to write to.</param> public static void WriteMetricsCollection(this PrometheusExporter exporter, StreamWriter writer) { foreach (var metric in exporter.GetAndClearDoubleMetrics()) { var labels = metric.Labels; var builder = new PrometheusMetricBuilder() .WithName(metric.MetricName) .WithDescription(metric.MetricDescription); switch (metric.AggregationType) { case AggregationType.DoubleSum: { var doubleSum = metric.Data as SumData <double>; var doubleValue = doubleSum.Sum; builder = builder.WithType("counter"); foreach (var label in labels) { var metricValueBuilder = builder.AddValue(); metricValueBuilder = metricValueBuilder.WithValue(doubleValue); metricValueBuilder.WithLabel(label.Key, label.Value); } builder.Write(writer); break; } case AggregationType.Summary: { // Not supported yet. break; } } } foreach (var metric in exporter.GetAndClearLongMetrics()) { var labels = metric.Labels; var builder = new PrometheusMetricBuilder() .WithName(metric.MetricName) .WithDescription(metric.MetricDescription); switch (metric.AggregationType) { case AggregationType.LongSum: { var longSum = metric.Data as SumData <long>; var longValue = longSum.Sum; builder = builder.WithType("counter"); foreach (var label in labels) { var metricValueBuilder = builder.AddValue(); metricValueBuilder = metricValueBuilder.WithValue(longValue); metricValueBuilder.WithLabel(label.Key, label.Value); } builder.Write(writer); break; } case AggregationType.Summary: { // Not supported yet. break; } } } }