Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        ///     Add the <see cref="MetricsInfluxDbLineProtocolOutputFormatter" /> allowing metrics to optionally be reported to
        ///     InfluxDB using the LineProtocol.
        /// </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 AsInfluxDbLineProtocol(this IMetricsOutputFormattingBuilder metricFormattingBuilder)
        {
            if (metricFormattingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricFormattingBuilder));
            }

            var formatter = new MetricsInfluxDbLineProtocolOutputFormatter();

            return(metricFormattingBuilder.Using(formatter, false));
        }
        /// <summary>
        ///     Add the <see cref="MetricsInfluxDbLineProtocolOutputFormatter" /> allowing metrics to optionally be reported to
        ///     InfluxDB using the LineProtocol.
        /// </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 AsInfluxDbLineProtocol(
            this IMetricsOutputFormattingBuilder metricFormattingBuilder,
            Action <MetricsInfluxDbLineProtocolOptions> setupAction,
            MetricFields fields = null)
        {
            if (metricFormattingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricFormattingBuilder));
            }

            var options = new MetricsInfluxDbLineProtocolOptions();

            setupAction?.Invoke(options);

            var formatter = new MetricsInfluxDbLineProtocolOutputFormatter(options, fields);

            return(metricFormattingBuilder.Using(formatter, false));
        }