/// <summary> /// Add the <see cref="InfluxDbMetricsReporter" /> allowing metrics to be reported to InfluxDB. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="url">The base url where InfluxDB is hosted.</param> /// <param name="database">The InfluxDB where metrics should be flushed.</param> /// <param name="fieldsSetup">The metric fields to report as well as thier names.</param> /// <param name="lineProtocolOptionsSetup">The setup action to configure the <see cref="MetricsInfluxDbLineProtocolOptions"/> to use.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToInfluxDb( this IMetricsReportingBuilder metricReporterProviderBuilder, string url, string database, Action <MetricFields> fieldsSetup = null, Action <MetricsInfluxDbLineProtocolOptions> lineProtocolOptionsSetup = null) { if (metricReporterProviderBuilder == null) { throw new ArgumentNullException(nameof(metricReporterProviderBuilder)); } if (url == null) { throw new ArgumentNullException(nameof(url)); } if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) { throw new InvalidOperationException($"{nameof(url)} must be a valid absolute URI"); } var lineProtocolOptions = new MetricsInfluxDbLineProtocolOptions(); lineProtocolOptionsSetup?.Invoke(lineProtocolOptions); IMetricsOutputFormatter formatter; MetricFields fields = null; if (fieldsSetup == null) { formatter = new MetricsInfluxDbLineProtocolOutputFormatter(lineProtocolOptions); } else { fields = new MetricFields(); fieldsSetup.Invoke(fields); formatter = new MetricsInfluxDbLineProtocolOutputFormatter(lineProtocolOptions, fields); } var options = new MetricsReportingInfluxDbOptions { InfluxDb = { BaseUri = uri, Database = database }, MetricsOutputFormatter = formatter }; var httpClient = CreateClient(options.InfluxDb, options.HttpPolicy); var reporter = new InfluxDbMetricsReporter(options, httpClient); var builder = metricReporterProviderBuilder.Using(reporter); builder.OutputMetrics.AsInfluxDbLineProtocol(lineProtocolOptions, fields); return(builder); }
/// <summary> /// Add the <see cref="InfluxDbMetricsReporter" /> allowing metrics to be reported to InfluxDB. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="options">The InfluxDB reporting options to use.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToInfluxDb( this IMetricsReportingBuilder metricReporterProviderBuilder, MetricsReportingInfluxDbOptions options) { if (metricReporterProviderBuilder == null) { throw new ArgumentNullException(nameof(metricReporterProviderBuilder)); } var httpClient = CreateClient(options.InfluxDb, options.HttpPolicy); var reporter = new InfluxDbMetricsReporter(options, httpClient); return(metricReporterProviderBuilder.Using(reporter)); }
/// <summary> /// Add the <see cref="InfluxDbMetricsReporter" /> allowing metrics to be reported to InfluxDB. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="url">The base url where InfluxDB is hosted.</param> /// <param name="database">The InfluxDB where metrics should be flushed.</param> /// <param name="flushInterval"> /// The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics /// reporting. /// </param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToInfluxDb( this IMetricsReportingBuilder metricReporterProviderBuilder, string url, string database, TimeSpan flushInterval) { if (metricReporterProviderBuilder == null) { throw new ArgumentNullException(nameof(metricReporterProviderBuilder)); } if (url == null) { throw new ArgumentNullException(nameof(url)); } if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) { throw new InvalidOperationException($"{nameof(url)} must be a valid absolute URI"); } var options = new MetricsReportingInfluxDbOptions { FlushInterval = flushInterval, InfluxDb = { BaseUri = uri, Database = database } }; var httpClient = CreateClient(options.InfluxDb, options.HttpPolicy); var reporter = new InfluxDbMetricsReporter(options, httpClient); var builder = metricReporterProviderBuilder.Using(reporter); builder.OutputMetrics.AsInfluxDbLineProtocol(); return(builder); }