/// <summary> /// Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="url">The base url where metrics are written.</param> /// <param name="flushInterval"> /// The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics /// reporting. /// </param> /// <param name="fieldsSetup">The metric fields to report as well as thier names.</param> /// <param name="optionsSetup">The setup action to configure the <see cref="MetricsGraphitePlainTextProtocolOptions"/> to use.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToGraphite( this IMetricsReportingBuilder metricReporterProviderBuilder, string url, TimeSpan flushInterval, Action <MetricFields> fieldsSetup = null, Action <MetricsGraphitePlainTextProtocolOptions> optionsSetup = 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 plainTextProtocolOptions = new MetricsGraphitePlainTextProtocolOptions(); optionsSetup?.Invoke(plainTextProtocolOptions); IMetricsOutputFormatter formatter; var defaultFields = new MetricFields(); defaultFields.DefaultGraphiteMetricFieldNames(); if (fieldsSetup == null) { formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(plainTextProtocolOptions, defaultFields); } else { fieldsSetup.Invoke(defaultFields); formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(plainTextProtocolOptions, defaultFields); } var options = new MetricsReportingGraphiteOptions { FlushInterval = flushInterval, Graphite = { BaseUri = uri }, MetricsOutputFormatter = formatter }; var httpClient = CreateClient(options, options.ClientPolicy); var reporter = new GraphiteReporter(options, httpClient); var builder = metricReporterProviderBuilder.Using(reporter); builder.OutputMetrics.AsGraphitePlainTextProtocol(plainTextProtocolOptions, defaultFields); return(builder); }
/// <summary> /// Add the <see cref="MetricsGraphitePlainTextProtocolOutputFormatter" /> allowing metrics to optionally be reported to /// Graphite using the Plain Text Protocol. /// </summary> /// <param name="metricFormattingBuilder">s /// The <see cref="IMetricsOutputFormattingBuilder" /> used to configure InfluxDB Lineprotocol formatting /// options. /// </param> /// <param name="setupAction">The InfluxDB LineProtocol formatting options to use.</param> /// <param name="fields">The metric fields to report as well as thier names.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder AsGraphitePlainTextProtocol( this IMetricsOutputFormattingBuilder metricFormattingBuilder, Action <MetricsGraphitePlainTextProtocolOptions> setupAction, MetricFields fields = null) { if (metricFormattingBuilder == null) { throw new ArgumentNullException(nameof(metricFormattingBuilder)); } if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction)); } var options = new MetricsGraphitePlainTextProtocolOptions(); setupAction.Invoke(options); if (fields == null) { fields = new MetricFields(); fields.DefaultGraphiteMetricFieldNames(); } var formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(options, fields); return(metricFormattingBuilder.Using(formatter, false)); }
/// <summary> /// Add the <see cref="MetricsGraphitePlainTextProtocolOutputFormatter" /> allowing metrics to optionally be reported to /// Graphite using the Plain Text Protocol. /// </summary> /// <param name="metricFormattingBuilder">s /// The <see cref="IMetricsOutputFormattingBuilder" /> used to configure InfluxDB Lineprotocol formatting /// options. /// </param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder AsGraphitePlainTextProtocol(this IMetricsOutputFormattingBuilder metricFormattingBuilder) { if (metricFormattingBuilder == null) { throw new ArgumentNullException(nameof(metricFormattingBuilder)); } var formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(); return(metricFormattingBuilder.Using(formatter, false)); }